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