1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* XCloner - Backup and Restore backup plugin for Wordpress |
4
|
|
|
* |
5
|
|
|
* class-xcloner.php |
6
|
|
|
* @author Liuta Ovidiu <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This program is free software; you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU General Public License as published by |
10
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License |
19
|
|
|
* along with this program; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
21
|
|
|
* MA 02110-1301, USA. |
22
|
|
|
* |
23
|
|
|
* @link https://github.com/ovidiul/XCloner-Wordpress |
24
|
|
|
* |
25
|
|
|
* @modified 7/31/18 3:29 PM |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The core plugin class. |
31
|
|
|
* |
32
|
|
|
* This is used to define internationalization, admin-specific hooks, and |
33
|
|
|
* public-facing site hooks. |
34
|
|
|
* |
35
|
|
|
* Also maintains the unique identifier of this plugin as well as the current |
36
|
|
|
* version of the plugin. |
37
|
|
|
* |
38
|
|
|
* @since 1.0.0 |
39
|
|
|
* @package Xcloner |
40
|
|
|
* @subpackage Xcloner/includes |
41
|
|
|
* @author Liuta Ovidiu <[email protected]> |
42
|
|
|
* @link http://www.thinkovi.com |
43
|
|
|
*/ |
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 __call($property, $args) { |
172
|
|
|
|
173
|
|
|
$property = str_replace("get_", "", $property); |
174
|
|
|
|
175
|
|
|
if(property_exists($this, $property)){ |
176
|
|
|
return $this->$property; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function check_dependencies() { |
181
|
|
|
|
182
|
|
|
$backup_storage_path = realpath(__DIR__.DS."..".DS."..".DS."..").DS."backups".DS; |
183
|
|
|
|
184
|
|
|
define("XCLONER_STORAGE_PATH", realpath($backup_storage_path)); |
185
|
|
|
|
186
|
|
|
if (!is_dir($backup_storage_path)) |
187
|
|
|
{ |
188
|
|
|
if (!@mkdir($backup_storage_path)) |
189
|
|
|
{ |
190
|
|
|
$status = "error"; |
191
|
|
|
$message = sprintf(__("Unable to create the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
192
|
|
|
$this->trigger_message($message, $status, $backup_storage_path); |
193
|
|
|
return; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
if (!is_writable($backup_storage_path)) |
197
|
|
|
{ |
198
|
|
|
$status = "error"; |
199
|
|
|
$message = sprintf(__("Unable to write to the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
200
|
|
|
$this->trigger_message($message, $status, $backup_storage_path); |
201
|
|
|
|
202
|
|
|
return; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function trigger_message($message, $status = "error", $message_param1 = "", $message_param2 = "", $message_param3 = "") |
208
|
|
|
{ |
209
|
|
|
$message = sprintf(__($message), $message_param1, $message_param2, $message_param3); |
210
|
|
|
add_action('xcloner_admin_notices', array($this, "trigger_message_notice"), 10, 2); |
211
|
|
|
do_action('xcloner_admin_notices', $message, $status); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function trigger_message_notice($message, $status = "success") |
215
|
|
|
{ |
216
|
|
|
?> |
217
|
|
|
<div class="notice notice-<?php echo $status?> is-dismissible"> |
218
|
|
|
<p><?php _e($message, 'xcloner-backup-and-restore'); ?></p> |
219
|
|
|
</div> |
220
|
|
|
<?php |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Load the required dependencies for this plugin. |
225
|
|
|
* |
226
|
|
|
* Include the following files that make up the plugin: |
227
|
|
|
* |
228
|
|
|
* - Xcloner_Loader. Orchestrates the hooks of the plugin. |
229
|
|
|
* - Xcloner_i18n. Defines internationalization functionality. |
230
|
|
|
* - Xcloner_Admin. Defines all hooks for the admin area. |
231
|
|
|
* - Xcloner_Public. Defines all hooks for the public side of the site. |
232
|
|
|
* |
233
|
|
|
* Create an instance of the loader which will be used to register the hooks |
234
|
|
|
* with WordPress. |
235
|
|
|
* |
236
|
|
|
* @since 1.0.0 |
237
|
|
|
* @access private |
238
|
|
|
*/ |
239
|
|
|
private function load_dependencies() { |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* The class responsible for orchestrating the actions and filters of the |
243
|
|
|
* core plugin. |
244
|
|
|
*/ |
245
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-loader.php'; |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* The class responsible for defining internationalization functionality |
249
|
|
|
* of the plugin. |
250
|
|
|
*/ |
251
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-i18n.php'; |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* The class responsible for defining all actions that occur in the admin area. |
255
|
|
|
*/ |
256
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'admin/class-xcloner-admin.php'; |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* The class responsible for debugging XCloner. |
260
|
|
|
*/ |
261
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-logger.php'; |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* The class responsible for defining the admin settings area. |
265
|
|
|
*/ |
266
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-settings.php'; |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* The class responsible for defining the Remote Storage settings area. |
270
|
|
|
*/ |
271
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-remote-storage.php'; |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* The class responsible for implementing the database backup methods. |
275
|
|
|
*/ |
276
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-database.php'; |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* The class responsible for sanitization of users input. |
280
|
|
|
*/ |
281
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-sanitization.php'; |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* The class responsible for XCloner system requirements validation. |
285
|
|
|
*/ |
286
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-requirements.php'; |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* The class responsible for XCloner backup archive creation. |
290
|
|
|
*/ |
291
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-archive.php'; |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* The class responsible for XCloner API requests. |
295
|
|
|
*/ |
296
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-api.php'; |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* The class responsible for the XCloner File System methods. |
300
|
|
|
*/ |
301
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-system.php'; |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* The class responsible for the XCloner File Transfer methods. |
305
|
|
|
*/ |
306
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-transfer.php'; |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* The class responsible for the XCloner Scheduler methods. |
310
|
|
|
*/ |
311
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-scheduler.php'; |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* The class responsible for the XCloner Encryption methods. |
315
|
|
|
*/ |
316
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-encryption.php'; |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* The class responsible for defining all actions that occur in the public-facing |
320
|
|
|
* side of the site. |
321
|
|
|
*/ |
322
|
|
|
require_once plugin_dir_path(dirname(__FILE__)).'public/class-xcloner-public.php'; |
323
|
|
|
|
324
|
|
|
$this->loader = new Xcloner_Loader($this); |
325
|
|
|
|
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Define the locale for this plugin for internationalization. |
330
|
|
|
* |
331
|
|
|
* Uses the Xcloner_i18n class in order to set the domain and to register the hook |
332
|
|
|
* with WordPress. |
333
|
|
|
* |
334
|
|
|
* @since 1.0.0 |
335
|
|
|
* @access private |
336
|
|
|
*/ |
337
|
|
|
private function set_locale() { |
338
|
|
|
|
339
|
|
|
$plugin_i18n = new Xcloner_i18n(); |
340
|
|
|
|
341
|
|
|
$this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
342
|
|
|
|
343
|
|
|
//wp_localize_script( 'ajax-script', 'my_ajax_object', |
344
|
|
|
// array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
345
|
|
|
|
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Register all of the hooks related to the admin area functionality |
350
|
|
|
* of the plugin. |
351
|
|
|
* |
352
|
|
|
* @since 1.0.0 |
353
|
|
|
* @access private |
354
|
|
|
*/ |
355
|
|
|
private function define_admin_hooks() { |
356
|
|
|
|
357
|
|
|
$plugin_admin = new Xcloner_Admin($this); |
358
|
|
|
$this->plugin_admin = $plugin_admin; |
359
|
|
|
|
360
|
|
|
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
361
|
|
|
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
362
|
|
|
|
363
|
|
|
add_action('backup_archive_finished', array($this, 'do_action_after_backup_finished'), 10, 2); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* Register the Admin Sidebar menu |
368
|
|
|
* |
369
|
|
|
* @access private |
370
|
|
|
* |
371
|
|
|
*/ |
372
|
|
|
private function define_admin_menu() { |
373
|
|
|
|
374
|
|
|
add_action('admin_menu', array($this->loader, 'xcloner_backup_add_admin_menu')); |
375
|
|
|
|
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
private function define_plugin_settings() { |
379
|
|
|
/** |
380
|
|
|
* register wporg_settings_init to the admin_init action hook |
381
|
|
|
*/ |
382
|
|
|
|
383
|
|
|
$this->xcloner_settings = new XCloner_Settings($this); |
384
|
|
|
|
385
|
|
|
if (defined('DOING_CRON') || isset($_POST['hash'])) { |
386
|
|
|
|
387
|
|
|
if (defined('DOING_CRON') || $_POST['hash'] == "generate_hash") { |
388
|
|
|
$this->xcloner_settings->generate_new_hash(); |
389
|
|
|
} else { |
390
|
|
|
$this->xcloner_settings->set_hash($_POST['hash']); |
391
|
|
|
} |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
if (defined('DOING_CRON') || !isset($_POST['hash'])) |
395
|
|
|
{ |
396
|
|
|
add_action('shutdown', function() { |
397
|
|
|
$this->xcloner_filesystem = new Xcloner_File_System($this); |
398
|
|
|
$this->xcloner_filesystem->remove_tmp_filesystem(); |
399
|
|
|
}); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
$this->xcloner_sanitization = new Xcloner_Sanitization(); |
403
|
|
|
$this->xcloner_requirements = new Xcloner_Requirements($this); |
404
|
|
|
|
405
|
|
|
add_action('admin_init', array($this->xcloner_settings, 'settings_init')); |
406
|
|
|
|
407
|
|
|
//adding links to the Manage Plugins Wordpress page for XCloner |
408
|
|
|
add_filter('plugin_action_links', array($this, 'add_plugin_action_links'), 10, 2); |
409
|
|
|
|
410
|
|
|
|
411
|
|
|
|
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/* |
415
|
|
|
* type = core|plugin|theme|translation |
416
|
|
|
*/ |
417
|
|
|
public function pre_auto_update($type, $item, $context) |
418
|
|
|
{ |
419
|
|
|
if (!$type) |
420
|
|
|
{ |
421
|
|
|
return false; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
$exclude_files = array(); |
425
|
|
|
$regex = ""; |
426
|
|
|
$data = ""; |
427
|
|
|
|
428
|
|
|
$this->get_xcloner_logger()->info(sprintf("Doing automatic backup before %s upgrade, pre_auto_update hook.", $type)); |
|
|
|
|
429
|
|
|
|
430
|
|
|
$content_dir = str_replace(ABSPATH, "", WP_CONTENT_DIR); |
431
|
|
|
$plugins_dir = str_replace(ABSPATH, "", WP_PLUGIN_DIR); |
432
|
|
|
$langs_dir = $content_dir.DS."languages"; |
433
|
|
|
$themes_dir = $content_dir.DS."themes"; |
434
|
|
|
|
435
|
|
|
switch ($type) { |
436
|
|
|
case 'core': |
437
|
|
|
$exclude_files = array( |
438
|
|
|
"^(?!(wp-admin|wp-includes|(?!.*\/.*.php)))(.*)$", |
439
|
|
|
); |
440
|
|
|
break; |
441
|
|
|
case 'plugin': |
442
|
|
|
|
443
|
|
|
$dir_array = explode(DS, $plugins_dir); |
444
|
|
|
|
445
|
|
|
foreach ($dir_array as $dir) |
446
|
|
|
{ |
447
|
|
|
$data .= "\/".$dir; |
448
|
|
|
$regex .= $data."$|"; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
$regex .= "\/".implode("\/", $dir_array); |
452
|
|
|
|
453
|
|
|
$exclude_files = array( |
454
|
|
|
"^(?!(".$regex."))(.*)$", |
455
|
|
|
); |
456
|
|
|
break; |
457
|
|
|
case 'theme': |
458
|
|
|
|
459
|
|
|
$dir_array = explode(DS, $themes_dir); |
460
|
|
|
|
461
|
|
|
foreach ($dir_array as $dir) |
462
|
|
|
{ |
463
|
|
|
$data .= "\/".$dir; |
464
|
|
|
$regex .= $data."$|"; |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
$regex .= "\/".implode("\/", $dir_array); |
468
|
|
|
|
469
|
|
|
$exclude_files = array( |
470
|
|
|
"^(?!(".$regex."))(.*)$", |
471
|
|
|
); |
472
|
|
|
break; |
473
|
|
|
case 'translation': |
474
|
|
|
|
475
|
|
|
$dir_array = explode(DS, $langs_dir); |
476
|
|
|
|
477
|
|
|
foreach ($dir_array as $dir) |
478
|
|
|
{ |
479
|
|
|
$data .= "\/".$dir; |
480
|
|
|
$regex .= $data."$|"; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
$regex .= "\/".implode("\/", $dir_array); |
484
|
|
|
|
485
|
|
|
$exclude_files = array( |
486
|
|
|
"^(?!(".$regex."))(.*)$", |
487
|
|
|
); |
488
|
|
|
break; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
$schedule = array(); |
492
|
|
|
|
493
|
|
|
$schedule['id'] = 0; |
494
|
|
|
$schedule['name'] = "pre_auto_update"; |
495
|
|
|
$schedule['recurrence'] = "single"; |
496
|
|
|
$schedule['excluded_files'] = json_encode($exclude_files); |
497
|
|
|
$schedule['table_params'] = json_encode(array("#" => array($this->get_xcloner_settings()->get_db_database()))); |
|
|
|
|
498
|
|
|
|
499
|
|
|
$schedule['backup_params'] = new stdClass(); |
500
|
|
|
$schedule['backup_params']->email_notification = get_option('admin_email'); |
501
|
|
|
$schedule['backup_params']->backup_name = "backup_pre_auto_update_".$type."_[domain]-[time]-sql"; |
502
|
|
|
|
503
|
|
|
try { |
504
|
|
|
$this->xcloner_scheduler->xcloner_scheduler_callback(0, $schedule); |
505
|
|
|
}catch (Exception $e) { |
506
|
|
|
$this->get_xcloner_logger()->error($e->getMessage()); |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* Register all of the hooks related to the public-facing functionality |
513
|
|
|
* of the plugin. |
514
|
|
|
* |
515
|
|
|
* @since 1.0.0 |
516
|
|
|
* @access private |
517
|
|
|
*/ |
518
|
|
|
private function define_public_hooks() { |
519
|
|
|
|
520
|
|
|
$plugin_public = new Xcloner_Public($this); |
521
|
|
|
|
522
|
|
|
$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); |
523
|
|
|
$this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); |
524
|
|
|
|
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
public function exception_handler() { |
528
|
|
|
|
529
|
|
|
$logger = new XCloner_Logger($this, "php_system"); |
530
|
|
|
$error = error_get_last(); |
531
|
|
|
|
532
|
|
|
if ($error['type'] and $logger) |
533
|
|
|
{ |
534
|
|
|
$logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true)); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
public function friendly_error_type($type) { |
540
|
|
|
static $levels = null; |
541
|
|
|
if ($levels === null) { |
542
|
|
|
$levels = []; |
543
|
|
|
foreach (get_defined_constants() as $key=>$value) { |
544
|
|
|
if (strpos($key, 'E_') !== 0) {continue; } |
545
|
|
|
$levels[$value] = $key; //substr($key,2); |
546
|
|
|
} |
547
|
|
|
} |
548
|
|
|
return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
private function define_ajax_hooks() |
552
|
|
|
{ |
553
|
|
|
//adding the pre-update hook |
554
|
|
|
|
555
|
|
|
if (is_admin() || defined('DOING_CRON')) |
556
|
|
|
{ |
557
|
|
|
$this->xcloner_logger = new XCloner_Logger($this, "xcloner_api"); |
558
|
|
|
$this->xcloner_filesystem = new Xcloner_File_System($this); |
559
|
|
|
|
560
|
|
|
//$this->xcloner_filesystem->set_diff_timestamp_start (strtotime("-15 days")); |
561
|
|
|
|
562
|
|
|
$this->archive_system = new Xcloner_Archive($this); |
563
|
|
|
$this->xcloner_database = new Xcloner_Database($this); |
564
|
|
|
$this->xcloner_scheduler = new Xcloner_Scheduler($this); |
565
|
|
|
$this->xcloner_remote_storage = new Xcloner_Remote_Storage($this); |
566
|
|
|
$this->xcloner_file_transfer = new Xcloner_File_Transfer($this); |
567
|
|
|
$this->xcloner_encryption = new Xcloner_Encryption($this); |
568
|
|
|
|
569
|
|
|
$xcloner_api = new Xcloner_Api($this); |
570
|
|
|
|
571
|
|
|
add_action('wp_ajax_get_database_tables_action', array($xcloner_api, 'get_database_tables_action')); |
572
|
|
|
add_action('wp_ajax_get_file_system_action', array($xcloner_api, 'get_file_system_action')); |
573
|
|
|
add_action('wp_ajax_scan_filesystem', array($xcloner_api, 'scan_filesystem')); |
574
|
|
|
add_action('wp_ajax_backup_database', array($xcloner_api, 'backup_database')); |
575
|
|
|
add_action('wp_ajax_backup_files', array($xcloner_api, 'backup_files')); |
576
|
|
|
add_action('wp_ajax_save_schedule', array($xcloner_api, 'save_schedule')); |
577
|
|
|
add_action('wp_ajax_get_schedule_by_id', array($xcloner_api, 'get_schedule_by_id')); |
578
|
|
|
add_action('wp_ajax_get_scheduler_list', array($xcloner_api, 'get_scheduler_list')); |
579
|
|
|
add_action('wp_ajax_delete_schedule_by_id', array($xcloner_api, 'delete_schedule_by_id')); |
580
|
|
|
add_action('wp_ajax_delete_backup_by_name', array($xcloner_api, 'delete_backup_by_name')); |
581
|
|
|
add_action('wp_ajax_download_backup_by_name', array($xcloner_api, 'download_backup_by_name')); |
582
|
|
|
add_action('wp_ajax_remote_storage_save_status', array($xcloner_api, 'remote_storage_save_status')); |
583
|
|
|
add_action('wp_ajax_upload_backup_to_remote', array($xcloner_api, 'upload_backup_to_remote')); |
584
|
|
|
add_action('wp_ajax_list_backup_files', array($xcloner_api, 'list_backup_files')); |
585
|
|
|
add_action('wp_ajax_restore_upload_backup', array($xcloner_api, 'restore_upload_backup')); |
586
|
|
|
add_action('wp_ajax_download_restore_script', array($xcloner_api, 'download_restore_script')); |
587
|
|
|
add_action('wp_ajax_copy_backup_remote_to_local', array($xcloner_api, 'copy_backup_remote_to_local')); |
588
|
|
|
add_action('wp_ajax_restore_backup', array($xcloner_api, 'restore_backup')); |
589
|
|
|
add_action('wp_ajax_backup_encryption', array($xcloner_api, 'backup_encryption')); |
590
|
|
|
add_action('wp_ajax_backup_decryption', array($xcloner_api, 'backup_decryption')); |
591
|
|
|
add_action('wp_ajax_get_manage_backups_list', array($xcloner_api, 'get_manage_backups_list')); |
592
|
|
|
add_action('admin_notices', array($this, 'xcloner_error_admin_notices')); |
593
|
|
|
|
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
//Do a pre-update backup of targeted files |
597
|
|
|
if ($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
598
|
|
|
{ |
599
|
|
|
add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3); |
600
|
|
|
} |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
public function add_plugin_action_links($links, $file) { |
604
|
|
|
if ($file == plugin_basename(dirname(dirname(__FILE__)).'/xcloner.php')) |
605
|
|
|
{ |
606
|
|
|
$links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>'; |
607
|
|
|
$links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>'; |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
return $links; |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
public function xcloner_error_admin_notices() { |
614
|
|
|
settings_errors('xcloner_error_message'); |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
public function define_cron_hooks() |
618
|
|
|
{ |
619
|
|
|
//registering new schedule intervals |
620
|
|
|
add_filter('cron_schedules', array($this, 'add_new_intervals')); |
621
|
|
|
|
622
|
|
|
|
623
|
|
|
$xcloner_scheduler = $this->get_xcloner_scheduler(); |
|
|
|
|
624
|
|
|
$xcloner_scheduler->update_wp_cron_hooks(); |
625
|
|
|
|
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* @param $schedules |
630
|
|
|
* @return mixed |
631
|
|
|
*/ |
632
|
|
|
public function add_new_intervals($schedules) |
633
|
|
|
{ |
634
|
|
|
//weekly scheduler interval |
635
|
|
|
$schedules['weekly'] = array( |
636
|
|
|
'interval' => 604800, |
637
|
|
|
'display' => __('Once Weekly', 'xcloner-backup-and-restore') |
638
|
|
|
); |
639
|
|
|
|
640
|
|
|
//monthly scheduler interval |
641
|
|
|
$schedules['monthly'] = array( |
642
|
|
|
'interval' => 2635200, |
643
|
|
|
'display' => __('Once Monthly', 'xcloner-backup-and-restore') |
644
|
|
|
); |
645
|
|
|
|
646
|
|
|
//monthly scheduler interval |
647
|
|
|
$schedules['twicedaily'] = array( |
648
|
|
|
'interval' => 43200, |
649
|
|
|
'display' => __('Twice Daily', 'xcloner-backup-and-restore') |
650
|
|
|
); |
651
|
|
|
|
652
|
|
|
return $schedules; |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* Run the loader to execute all of the hooks with WordPress. |
658
|
|
|
* |
659
|
|
|
* @since 1.0.0 |
660
|
|
|
*/ |
661
|
|
|
public function run() { |
662
|
|
|
$this->loader->run(); |
663
|
|
|
} |
664
|
|
|
|
665
|
|
|
/** |
666
|
|
|
* The name of the plugin used to uniquely identify it within the context of |
667
|
|
|
* WordPress and to define internationalization functionality. |
668
|
|
|
* |
669
|
|
|
* @since 1.0.0 |
670
|
|
|
* @return string The name of the plugin. |
671
|
|
|
*/ |
672
|
|
|
public function get_plugin_name() { |
673
|
|
|
return $this->plugin_name; |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
/** |
677
|
|
|
* The reference to the class that orchestrates the hooks with the plugin. |
678
|
|
|
* |
679
|
|
|
* @since 1.0.0 |
680
|
|
|
* @return Xcloner_Loader Orchestrates the hooks of the plugin. |
681
|
|
|
*/ |
682
|
|
|
public function get_loader() { |
683
|
|
|
return $this->loader; |
684
|
|
|
} |
685
|
|
|
|
686
|
|
|
/** |
687
|
|
|
* Retrieve the version number of the plugin. |
688
|
|
|
* |
689
|
|
|
* @since 1.0.0 |
690
|
|
|
* @return string The version number of the plugin. |
691
|
|
|
*/ |
692
|
|
|
public function get_version() { |
693
|
|
|
return $this->version; |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
public function xcloner_display() |
697
|
|
|
{ |
698
|
|
|
// check user capabilities |
699
|
|
|
if (!current_user_can('manage_options')) { |
700
|
|
|
return; |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
$page = sanitize_key($_GET['page']); |
704
|
|
|
|
705
|
|
|
if ($page) |
706
|
|
|
{ |
707
|
|
|
$this->display($page); |
708
|
|
|
} |
709
|
|
|
|
710
|
|
|
} |
711
|
|
|
|
712
|
|
|
public function display($page) |
713
|
|
|
{ |
714
|
|
|
$plugin_admin = new Xcloner_Admin($this); |
715
|
|
|
$this->plugin_admin = $plugin_admin; |
716
|
|
|
|
717
|
|
|
call_user_func_array(array($this->plugin_admin, $page), array()); |
718
|
|
|
} |
719
|
|
|
} |
720
|
|
|
|