|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* The admin-specific functionality of the plugin. |
|
5
|
|
|
* |
|
6
|
|
|
* @link http://www.thinkovi.com |
|
7
|
|
|
* @since 1.0.0 |
|
8
|
|
|
* |
|
9
|
|
|
* @package Xcloner |
|
10
|
|
|
* @subpackage Xcloner/admin |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* The admin-specific functionality of the plugin. |
|
15
|
|
|
* |
|
16
|
|
|
* Defines the plugin name, version, and two examples hooks for how to |
|
17
|
|
|
* enqueue the admin-specific stylesheet and JavaScript. |
|
18
|
|
|
* |
|
19
|
|
|
* @package Xcloner |
|
20
|
|
|
* @subpackage Xcloner/admin |
|
21
|
|
|
* @author Liuta Ovidiu <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class Xcloner_Admin { |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The ID of this plugin. |
|
27
|
|
|
* |
|
28
|
|
|
* @since 1.0.0 |
|
29
|
|
|
* @access private |
|
30
|
|
|
* @var string $plugin_name The ID of this plugin. |
|
31
|
|
|
*/ |
|
32
|
|
|
private $plugin_name; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The version of this plugin. |
|
36
|
|
|
* |
|
37
|
|
|
* @since 1.0.0 |
|
38
|
|
|
* @access private |
|
39
|
|
|
* @var string $version The current version of this plugin. |
|
40
|
|
|
*/ |
|
41
|
|
|
private $version; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var Xcloner |
|
45
|
|
|
*/ |
|
46
|
|
|
private $xcloner_container; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Initialize the class and set its properties. |
|
50
|
|
|
* |
|
51
|
|
|
* Xcloner_Admin constructor. |
|
52
|
|
|
* @param Xcloner $xcloner_container |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct(Xcloner $xcloner_container) { |
|
55
|
|
|
|
|
56
|
|
|
$this->plugin_name = $xcloner_container->get_plugin_name(); |
|
57
|
|
|
$this->version = $xcloner_container->get_version(); |
|
58
|
|
|
$this->xcloner_container = $xcloner_container; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return Xcloner |
|
63
|
|
|
*/ |
|
64
|
|
|
public function get_xcloner_container() { |
|
65
|
|
|
return $this->xcloner_container; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Register the stylesheets for the admin area. |
|
70
|
|
|
* |
|
71
|
|
|
* @since 1.0.0 |
|
72
|
|
|
*/ |
|
73
|
|
|
public function enqueue_styles($hook) { |
|
74
|
|
|
|
|
75
|
|
|
if (!stristr($hook, "page_".$this->plugin_name) || (isset($_GET['option']) and $_GET['option'] == "com_cloner")) { |
|
76
|
|
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* This function is provided for demonstration purposes only. |
|
81
|
|
|
* |
|
82
|
|
|
* An instance of this class should be passed to the run() function |
|
83
|
|
|
* defined in Xcloner_Loader as all of the hooks are defined |
|
84
|
|
|
* in that particular class. |
|
85
|
|
|
* |
|
86
|
|
|
* The Xcloner_Loader will then create the relationship |
|
87
|
|
|
* between the defined hooks and the functions defined in this |
|
88
|
|
|
* class. |
|
89
|
|
|
*/ |
|
90
|
|
|
|
|
91
|
|
|
wp_enqueue_style($this->plugin_name."_materialize", plugin_dir_url(__FILE__).'css/materialize.min.css', array(), $this->version, 'all'); |
|
92
|
|
|
wp_enqueue_style($this->plugin_name."_materialize.clockpicker", plugin_dir_url(__FILE__).'css/materialize.clockpicker.css', array(), $this->version, 'all'); |
|
93
|
|
|
wp_enqueue_style($this->plugin_name."_materialize.icons", '//fonts.googleapis.com/icon?family=Material+Icons', array(), $this->version, 'all'); |
|
94
|
|
|
wp_enqueue_style($this->plugin_name."_jquery.datatables", plugin_dir_url(__FILE__).'css/jquery.dataTables.min.css', array(), $this->version, 'all'); |
|
95
|
|
|
wp_enqueue_style($this->plugin_name."_jquery.datatables.responsive", plugin_dir_url(__FILE__).'css/responsive.dataTables.css', array(), $this->version, 'all'); |
|
96
|
|
|
wp_enqueue_style($this->plugin_name."_jstree", dirname(plugin_dir_url(__FILE__)).'/vendor/vakata/jstree/dist/themes/default/style.min.css', array(), '3.3', 'all'); |
|
97
|
|
|
wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/xcloner-admin.css', array(), $this->version, 'all'); |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Register the JavaScript for the admin area. |
|
103
|
|
|
* |
|
104
|
|
|
* @since 1.0.0 |
|
105
|
|
|
*/ |
|
106
|
|
|
public function enqueue_scripts($hook) { |
|
107
|
|
|
|
|
108
|
|
|
if (!stristr($hook, "page_".$this->plugin_name)) { |
|
109
|
|
|
return; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* This function is provided for demonstration purposes only. |
|
114
|
|
|
* |
|
115
|
|
|
* An instance of this class should be passed to the run() function |
|
116
|
|
|
* defined in Xcloner_Loader as all of the hooks are defined |
|
117
|
|
|
* in that particular class. |
|
118
|
|
|
* |
|
119
|
|
|
* The Xcloner_Loader will then create the relationship |
|
120
|
|
|
* between the defined hooks and the functions defined in this |
|
121
|
|
|
* class. |
|
122
|
|
|
*/ |
|
123
|
|
|
|
|
124
|
|
|
add_thickbox(); |
|
125
|
|
|
wp_enqueue_script('plugin-install'); |
|
126
|
|
|
wp_enqueue_script('updates'); |
|
127
|
|
|
wp_enqueue_script($this->plugin_name."_materialize", plugin_dir_url(__FILE__).'js/materialize.min.js', array('jquery'), $this->version, false); |
|
128
|
|
|
wp_enqueue_script($this->plugin_name."_materialize.clockpicker", plugin_dir_url(__FILE__).'js/materialize.clockpicker.js', array('jquery'), $this->version, false); |
|
129
|
|
|
wp_enqueue_script($this->plugin_name."_jquery.datatables", plugin_dir_url(__FILE__).'js/jquery.dataTables.min.js', array('jquery'), $this->version, false); |
|
130
|
|
|
wp_enqueue_script($this->plugin_name."_jquery.datatables.respnsive", plugin_dir_url(__FILE__).'js/dataTables.responsive.js', array('jquery'), $this->version, false); |
|
131
|
|
|
wp_enqueue_script($this->plugin_name."_vakata", dirname(plugin_dir_url(__FILE__)).'/vendor/vakata/jstree/dist/jstree.min.js', array('jquery'), '3.3', false); |
|
132
|
|
|
wp_enqueue_script($this->plugin_name."_xcloner-backup-class", plugin_dir_url(__FILE__).'js/xcloner-backup-class.js', array('jquery'), $this->version, false); |
|
133
|
|
|
wp_enqueue_script($this->plugin_name."_xcloner-scheduler-class", plugin_dir_url(__FILE__).'js/xcloner-scheduler-class.js', array('jquery'), $this->version, false); |
|
134
|
|
|
wp_enqueue_script($this->plugin_name."_xcloner-restore-class", plugin_dir_url(__FILE__).'js/xcloner-restore-class.js', array('jquery'), $this->version, false); |
|
135
|
|
|
wp_enqueue_script($this->plugin_name."_xcloner-manage-backups-class", plugin_dir_url(__FILE__).'js/xcloner-manage-backups-class.js', array('jquery'), $this->version, false); |
|
136
|
|
|
wp_enqueue_script($this->plugin_name."_xcloner-remote-storage-class", plugin_dir_url(__FILE__).'js/xcloner-remote-storage-class.js', array('jquery'), $this->version, false); |
|
137
|
|
|
wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/xcloner-admin.js', array('jquery'), $this->version, false); |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function xcloner_init_page() { |
|
143
|
|
|
require_once("partials/xcloner_init_page.php"); |
|
144
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Returns the XCloner Storage Page |
|
149
|
|
|
*/ |
|
150
|
|
|
public function xcloner_remote_storage_page() { |
|
151
|
|
|
$xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization(); |
|
152
|
|
|
$remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
if (isset($_POST['action'])) { |
|
156
|
|
|
$_POST['action'] = $xcloner_sanitization->sanitize_input_as_string($_POST['action']); |
|
157
|
|
|
$remote_storage->save($_POST['action']); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
if (isset($_POST['authentification_code']) && $_POST['authentification_code'] != "") { |
|
161
|
|
|
$_POST['authentification_code'] = $xcloner_sanitization->sanitize_input_as_string($_POST['authentification_code']); |
|
162
|
|
|
|
|
163
|
|
|
$remote_storage->set_access_token($_POST['authentification_code']); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
if (isset($_POST['connection_check']) && $_POST['connection_check']) { |
|
167
|
|
|
$remote_storage->check($_POST['action']); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
require_once("partials/xcloner_remote_storage_page.php"); |
|
171
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function xcloner_scheduled_backups_page() { |
|
175
|
|
|
$requirements = $this->xcloner_container->get_xcloner_requirements(); |
|
176
|
|
|
|
|
177
|
|
|
if (!$requirements->check_backup_ready_status()) { |
|
178
|
|
|
require_once("partials/xcloner_init_page.php"); |
|
179
|
|
|
|
|
180
|
|
|
return false; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
require_once("partials/xcloner_scheduled_backups_page.php"); |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function xcloner_manage_backups_page() { |
|
188
|
|
|
require_once("partials/xcloner_manage_backups_page.php"); |
|
189
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
public function xcloner_debugger_page() { |
|
193
|
|
|
require_once("partials/xcloner_console_page.php"); |
|
194
|
|
|
|
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function xcloner_restore_page() { |
|
198
|
|
|
require_once("partials/xcloner_restore_page.php"); |
|
199
|
|
|
|
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public function xcloner_generate_backups_page() { |
|
203
|
|
|
$requirements = $this->xcloner_container->get_xcloner_requirements(); |
|
204
|
|
|
|
|
205
|
|
|
if (!$requirements->check_backup_ready_status()) { |
|
206
|
|
|
require_once("partials/xcloner_init_page.php"); |
|
207
|
|
|
|
|
208
|
|
|
return false; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
require_once("partials/xcloner_generate_backups_page.php"); |
|
212
|
|
|
|
|
213
|
|
|
return; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
public function xcloner_settings_page() { |
|
217
|
|
|
// check user capabilities |
|
218
|
|
|
if (!current_user_can('manage_options')) { |
|
219
|
|
|
return; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
// add error/update messages |
|
223
|
|
|
|
|
224
|
|
|
// check if the user have submitted the settings |
|
225
|
|
|
// wordpress will add the "settings-updated" $_GET parameter to the url |
|
226
|
|
|
if (isset($_GET['settings-updated'])) { |
|
227
|
|
|
// add settings saved message with the class of "updated" |
|
228
|
|
|
add_settings_error('wporg_messages', 'wporg_message', __('Settings Saved', 'wporg'), 'updated'); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
// show error/update messages |
|
232
|
|
|
settings_errors('wporg_messages'); |
|
233
|
|
|
?> |
|
234
|
|
|
|
|
235
|
|
|
<?php |
|
236
|
|
|
$xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization(); |
|
237
|
|
|
|
|
238
|
|
|
if (isset($_GET['tab'])) { |
|
239
|
|
|
$active_tab = $xcloner_sanitization->sanitize_input_as_string($_GET['tab']); |
|
240
|
|
|
} // end if |
|
241
|
|
|
else { |
|
242
|
|
|
$active_tab = "general_options"; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
?> |
|
246
|
|
|
<h1><?= esc_html(get_admin_page_title()); ?></h1> |
|
247
|
|
|
|
|
248
|
|
|
<ul class="nav-tab-wrapper row"> |
|
249
|
|
|
<li><a href="?page=xcloner_settings_page&tab=general_options" |
|
250
|
|
|
class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'general_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('General Options', 'xcloner-backup-and-restore') ?></a> |
|
251
|
|
|
</li> |
|
252
|
|
|
<li><a href="?page=xcloner_settings_page&tab=mysql_options" |
|
253
|
|
|
class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'mysql_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('Mysql Options', 'xcloner-backup-and-restore') ?></a> |
|
254
|
|
|
</li> |
|
255
|
|
|
<li><a href="?page=xcloner_settings_page&tab=system_options" |
|
256
|
|
|
class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'system_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('System Options', 'xcloner-backup-and-restore') ?></a> |
|
257
|
|
|
</li> |
|
258
|
|
|
<li><a href="?page=xcloner_settings_page&tab=cleanup_options" |
|
259
|
|
|
class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'cleanup_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('Cleanup Options', 'xcloner-backup-and-restore') ?></a> |
|
260
|
|
|
</li> |
|
261
|
|
|
</ul> |
|
262
|
|
|
|
|
263
|
|
|
<div class="wrap"> |
|
264
|
|
|
|
|
265
|
|
|
<form action="options.php" method="post"> |
|
266
|
|
|
<?php |
|
267
|
|
|
|
|
268
|
|
|
if ($active_tab == 'general_options') { |
|
269
|
|
|
|
|
270
|
|
|
settings_fields('xcloner_general_settings_group'); |
|
271
|
|
|
do_settings_sections('xcloner_settings_page'); |
|
272
|
|
|
|
|
273
|
|
|
} elseif ($active_tab == 'mysql_options') { |
|
274
|
|
|
|
|
275
|
|
|
settings_fields('xcloner_mysql_settings_group'); |
|
276
|
|
|
do_settings_sections('xcloner_mysql_settings_page'); |
|
277
|
|
|
} elseif ($active_tab == 'system_options') { |
|
278
|
|
|
|
|
279
|
|
|
settings_fields('xcloner_system_settings_group'); |
|
280
|
|
|
do_settings_sections('xcloner_system_settings_page'); |
|
281
|
|
|
} elseif ($active_tab == 'cleanup_options') { |
|
282
|
|
|
|
|
283
|
|
|
settings_fields('xcloner_cleanup_settings_group'); |
|
284
|
|
|
do_settings_sections('xcloner_cleanup_settings_page'); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
// output save settings button |
|
288
|
|
|
submit_button('Save Settings'); |
|
289
|
|
|
?> |
|
290
|
|
|
</form> |
|
291
|
|
|
|
|
292
|
|
|
</div> |
|
293
|
|
|
<?php |
|
294
|
|
|
|
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
} |
|
298
|
|
|
|