customclass
5 years ago
lib
7 years ago
upload-cleaner
5 years ago
class-wpvivid-additional-db-method.php
6 years ago
class-wpvivid-backup-database.php
5 years ago
class-wpvivid-backup-site.php
7 years ago
class-wpvivid-backup-uploader.php
5 years ago
class-wpvivid-backup.php
5 years ago
class-wpvivid-backuplist.php
5 years ago
class-wpvivid-backuptoremote.php
6 years ago
class-wpvivid-compress-default.php
6 years ago
class-wpvivid-crypt.php
5 years ago
class-wpvivid-db-method.php
6 years ago
class-wpvivid-downloader.php
5 years ago
class-wpvivid-error-log.php
5 years ago
class-wpvivid-export-import.php
5 years ago
class-wpvivid-exporter.php
5 years ago
class-wpvivid-function-realize.php
5 years ago
class-wpvivid-i18n.php
5 years ago
class-wpvivid-importer.php
5 years ago
class-wpvivid-interface-mainwp.php
5 years ago
class-wpvivid-log.php
7 years ago
class-wpvivid-mail-report.php
5 years ago
class-wpvivid-migrate.php
5 years ago
class-wpvivid-mysqldump-method.php
5 years ago
class-wpvivid-mysqldump.php
5 years ago
class-wpvivid-public-interface.php
5 years ago
class-wpvivid-remote-collection.php
5 years ago
class-wpvivid-restore-data.php
6 years ago
class-wpvivid-restore-database.php
5 years ago
class-wpvivid-restore-db-extra.php
6 years ago
class-wpvivid-restore-db-method.php
6 years ago
class-wpvivid-restore-db-pdo-mysql-method.php
6 years ago
class-wpvivid-restore-db-wpdb-method.php
6 years ago
class-wpvivid-restore-site.php
5 years ago
class-wpvivid-restore-template.php
7 years ago
class-wpvivid-restore.php
5 years ago
class-wpvivid-schedule.php
5 years ago
class-wpvivid-setting.php
5 years ago
class-wpvivid-tab-page-container.php
5 years ago
class-wpvivid-taskmanager.php
5 years ago
class-wpvivid-tools.php
5 years ago
class-wpvivid-upload.php
6 years ago
class-wpvivid-zipclass.php
5 years ago
class-wpvivid.php
5 years ago
index.php
7 years ago
class-wpvivid-public-interface.php
460 lines
| 1 | <?php |
| 2 | |
| 3 | class WPvivid_Public_Interface |
| 4 | { |
| 5 | public function __construct() |
| 6 | { |
| 7 | |
| 8 | } |
| 9 | |
| 10 | public function mainwp_data($data){ |
| 11 | $action = sanitize_text_field($data['mwp_action']); |
| 12 | if (has_filter($action)) { |
| 13 | $ret = apply_filters($action, $data); |
| 14 | } else { |
| 15 | $ret['result'] = WPVIVID_FAILED; |
| 16 | $ret['error'] = 'Unknown function'; |
| 17 | } |
| 18 | return $ret; |
| 19 | } |
| 20 | |
| 21 | public function prepare_backup($backup_options){ |
| 22 | global $wpvivid_plugin; |
| 23 | if(isset($backup_options)&&!empty($backup_options)){ |
| 24 | if (is_null($backup_options)) { |
| 25 | $ret['error']='Invalid parameter param:'.$backup_options; |
| 26 | return $ret; |
| 27 | } |
| 28 | $backup_options = apply_filters('wpvivid_custom_backup_options', $backup_options); |
| 29 | |
| 30 | if(!isset($backup_options['type'])) |
| 31 | { |
| 32 | $backup_options['type']='Manual'; |
| 33 | $backup_options['action']='backup'; |
| 34 | } |
| 35 | $ret = $wpvivid_plugin->check_backup_option($backup_options, $backup_options['type']); |
| 36 | if($ret['result']!='success') { |
| 37 | return $ret; |
| 38 | } |
| 39 | $ret=$wpvivid_plugin->pre_backup($backup_options); |
| 40 | if($ret['result']=='success') { |
| 41 | //Check the website data to be backed up |
| 42 | $ret['check']=$wpvivid_plugin->check_backup($ret['task_id'],$backup_options); |
| 43 | if(isset($ret['check']['result']) && $ret['check']['result'] == 'failed') { |
| 44 | $ret['error']=$ret['check']['error']; |
| 45 | return $ret; |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | else{ |
| 50 | $ret['error']='Error occurred while parsing the request data. Please try to run backup again.'; |
| 51 | return $ret; |
| 52 | } |
| 53 | return $ret; |
| 54 | } |
| 55 | |
| 56 | public function backup_now($task_id){ |
| 57 | global $wpvivid_plugin; |
| 58 | if (!isset($task_id)||empty($task_id)||!is_string($task_id)) |
| 59 | { |
| 60 | $ret['error']=__('Error occurred while parsing the request data. Please try to run backup again.', 'wpvivid-backuprestore'); |
| 61 | return $ret; |
| 62 | } |
| 63 | $task_id=sanitize_key($task_id); |
| 64 | $ret['result']='success'; |
| 65 | $txt = '<mainwp>' . base64_encode( serialize( $ret ) ) . '</mainwp>'; |
| 66 | // Close browser connection so that it can resume AJAX polling |
| 67 | header( 'Content-Length: ' . ( ( ! empty( $txt ) ) ? strlen( $txt ) : '0' ) ); |
| 68 | header( 'Connection: close' ); |
| 69 | header( 'Content-Encoding: none' ); |
| 70 | if ( session_id() ) { |
| 71 | session_write_close(); |
| 72 | } |
| 73 | echo $txt; |
| 74 | // These two added - 19-Feb-15 - started being required on local dev machine, for unknown reason (probably some plugin that started an output buffer). |
| 75 | if ( ob_get_level() ) { |
| 76 | ob_end_flush(); |
| 77 | } |
| 78 | flush(); |
| 79 | |
| 80 | $wpvivid_plugin->flush($task_id); |
| 81 | //Start backup site |
| 82 | $wpvivid_plugin->backup($task_id); |
| 83 | $ret['result']='success'; |
| 84 | } |
| 85 | |
| 86 | public function get_status(){ |
| 87 | $ret['result']='success'; |
| 88 | $list_tasks=array(); |
| 89 | $tasks=WPvivid_Setting::get_tasks(); |
| 90 | foreach ($tasks as $task) |
| 91 | { |
| 92 | $backup = new WPvivid_Backup_Task($task['id']); |
| 93 | $list_tasks[$task['id']]=$backup->get_backup_task_info($task['id']); |
| 94 | if($list_tasks[$task['id']]['task_info']['need_update_last_task']===true){ |
| 95 | $task_msg = WPvivid_taskmanager::get_task($task['id']); |
| 96 | WPvivid_Setting::update_option('wpvivid_last_msg',$task_msg); |
| 97 | } |
| 98 | } |
| 99 | $ret['wpvivid']['task']=$list_tasks; |
| 100 | $backuplist=WPvivid_Backuplist::get_backuplist(); |
| 101 | $schedule=WPvivid_Schedule::get_schedule(); |
| 102 | $ret['wpvivid']['backup_list']=$backuplist; |
| 103 | $ret['wpvivid']['schedule']=$schedule; |
| 104 | $ret['wpvivid']['schedule']['last_message']=WPvivid_Setting::get_last_backup_message('wpvivid_last_msg'); |
| 105 | WPvivid_taskmanager::delete_marked_task(); |
| 106 | return $ret; |
| 107 | } |
| 108 | |
| 109 | public function get_backup_schedule(){ |
| 110 | $schedule=WPvivid_Schedule::get_schedule(); |
| 111 | $ret['result']='success'; |
| 112 | $ret['wpvivid']['schedule']=$schedule; |
| 113 | $ret['wpvivid']['schedule']['last_message']=WPvivid_Setting::get_last_backup_message('wpvivid_last_msg'); |
| 114 | return $ret; |
| 115 | } |
| 116 | |
| 117 | public function get_backup_list(){ |
| 118 | $backuplist=WPvivid_Backuplist::get_backuplist(); |
| 119 | $ret['result']='success'; |
| 120 | $ret['wpvivid']['backup_list']=$backuplist; |
| 121 | return $ret; |
| 122 | } |
| 123 | |
| 124 | public function get_default_remote(){ |
| 125 | global $wpvivid_plugin; |
| 126 | $ret['result']='success'; |
| 127 | $ret['remote_storage_type']=$wpvivid_plugin->function_realize->_get_default_remote_storage(); |
| 128 | return $ret; |
| 129 | } |
| 130 | |
| 131 | public function delete_backup($backup_id, $force_del){ |
| 132 | global $wpvivid_plugin; |
| 133 | if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) { |
| 134 | $ret['error']='Invalid parameter param: backup_id.'; |
| 135 | return $ret; |
| 136 | } |
| 137 | if(!isset($force_del)){ |
| 138 | $ret['error']='Invalid parameter param: force.'; |
| 139 | return $ret; |
| 140 | } |
| 141 | if($force_del==0||$force_del==1) { |
| 142 | } |
| 143 | else { |
| 144 | $force_del=0; |
| 145 | } |
| 146 | $backup_id=sanitize_key($backup_id); |
| 147 | $ret=$wpvivid_plugin->delete_backup_by_id($backup_id, $force_del); |
| 148 | $backuplist=WPvivid_Backuplist::get_backuplist(); |
| 149 | $ret['wpvivid']['backup_list']=$backuplist; |
| 150 | return $ret; |
| 151 | } |
| 152 | |
| 153 | public function delete_backup_array($backup_id_array){ |
| 154 | global $wpvivid_plugin; |
| 155 | if(!isset($backup_id_array)||empty($backup_id_array)||!is_array($backup_id_array)) { |
| 156 | $ret['error']='Invalid parameter param: backup_id'; |
| 157 | return $ret; |
| 158 | } |
| 159 | $ret=array(); |
| 160 | foreach($backup_id_array as $backup_id) |
| 161 | { |
| 162 | $backup_id=sanitize_key($backup_id); |
| 163 | $ret=$wpvivid_plugin->delete_backup_by_id($backup_id); |
| 164 | } |
| 165 | $backuplist=WPvivid_Backuplist::get_backuplist(); |
| 166 | $ret['wpvivid']['backup_list']=$backuplist; |
| 167 | return $ret; |
| 168 | } |
| 169 | |
| 170 | public function set_security_lock($backup_id, $lock){ |
| 171 | if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)){ |
| 172 | $ret['error']='Backup id not found'; |
| 173 | return $ret; |
| 174 | } |
| 175 | if(!isset($lock)){ |
| 176 | $ret['error']='Invalid parameter param: lock'; |
| 177 | return $ret; |
| 178 | } |
| 179 | $backup_id=sanitize_key($backup_id); |
| 180 | if($lock==0||$lock==1) { |
| 181 | } |
| 182 | else { |
| 183 | $lock=0; |
| 184 | } |
| 185 | WPvivid_Backuplist::set_security_lock($backup_id,$lock); |
| 186 | $backuplist=WPvivid_Backuplist::get_backuplist(); |
| 187 | $ret['wpvivid']['backup_list']=$backuplist; |
| 188 | return $ret; |
| 189 | } |
| 190 | |
| 191 | public function view_log($backup_id){ |
| 192 | global $wpvivid_plugin; |
| 193 | if (!isset($backup_id)||empty($backup_id)||!is_string($backup_id)){ |
| 194 | $ret['error']='Backup id not found'; |
| 195 | return $ret; |
| 196 | } |
| 197 | $backup_id=sanitize_key($backup_id); |
| 198 | $ret=$wpvivid_plugin->function_realize->_get_log_file('backuplist', $backup_id); |
| 199 | if($ret['result'] == 'success') { |
| 200 | $file = fopen($ret['log_file'], 'r'); |
| 201 | if (!$file) { |
| 202 | $ret['result'] = 'failed'; |
| 203 | $ret['error'] = __('Unable to open the log file.', 'wpvivid-backuprestore'); |
| 204 | return $ret; |
| 205 | } |
| 206 | $buffer = ''; |
| 207 | while (!feof($file)) { |
| 208 | $buffer .= fread($file, 1024); |
| 209 | } |
| 210 | fclose($file); |
| 211 | $ret['data'] = $buffer; |
| 212 | } |
| 213 | else{ |
| 214 | $ret['error']='Unknown error'; |
| 215 | } |
| 216 | return $ret; |
| 217 | } |
| 218 | |
| 219 | public function read_last_backup_log($log_file_name){ |
| 220 | global $wpvivid_plugin; |
| 221 | if(!isset($log_file_name)||empty($log_file_name)||!is_string($log_file_name)) |
| 222 | { |
| 223 | $ret['result']='failed'; |
| 224 | $ret['error']=__('Reading the log failed. Please try again.', 'wpvivid-backuprestore'); |
| 225 | return $ret; |
| 226 | } |
| 227 | $log_file_name=sanitize_text_field($log_file_name); |
| 228 | $ret=$wpvivid_plugin->function_realize->_get_log_file('lastlog', $log_file_name); |
| 229 | if($ret['result'] == 'success') { |
| 230 | $file = fopen($ret['log_file'], 'r'); |
| 231 | if (!$file) { |
| 232 | $ret['result'] = 'failed'; |
| 233 | $ret['error'] = __('Unable to open the log file.', 'wpvivid-backuprestore'); |
| 234 | return $ret; |
| 235 | } |
| 236 | $buffer = ''; |
| 237 | while (!feof($file)) { |
| 238 | $buffer .= fread($file, 1024); |
| 239 | } |
| 240 | fclose($file); |
| 241 | $ret['result'] = 'success'; |
| 242 | $ret['data'] = $buffer; |
| 243 | } |
| 244 | else{ |
| 245 | $ret['error']='Unknown error'; |
| 246 | } |
| 247 | return $ret; |
| 248 | } |
| 249 | |
| 250 | public function view_backup_task_log($backup_task_id){ |
| 251 | global $wpvivid_plugin; |
| 252 | if (!isset($backup_task_id)||empty($backup_task_id)||!is_string($backup_task_id)){ |
| 253 | $ret['error']='Reading the log failed. Please try again.'; |
| 254 | return $ret; |
| 255 | } |
| 256 | $backup_task_id = sanitize_key($backup_task_id); |
| 257 | $ret=$wpvivid_plugin->function_realize->_get_log_file('tasklog', $backup_task_id); |
| 258 | if($ret['result'] == 'success') { |
| 259 | $file = fopen($ret['log_file'], 'r'); |
| 260 | if (!$file) { |
| 261 | $ret['result'] = 'failed'; |
| 262 | $ret['error'] = __('Unable to open the log file.', 'wpvivid-backuprestore'); |
| 263 | return $ret; |
| 264 | } |
| 265 | $buffer = ''; |
| 266 | while (!feof($file)) { |
| 267 | $buffer .= fread($file, 1024); |
| 268 | } |
| 269 | fclose($file); |
| 270 | $ret['result'] = 'success'; |
| 271 | $ret['data'] = $buffer; |
| 272 | } |
| 273 | else{ |
| 274 | $ret['error']='Unknown error'; |
| 275 | } |
| 276 | return $ret; |
| 277 | } |
| 278 | |
| 279 | public function backup_cancel($task_id = ''){ |
| 280 | global $wpvivid_plugin; |
| 281 | $ret=$wpvivid_plugin->function_realize->_backup_cancel(); |
| 282 | return $ret; |
| 283 | } |
| 284 | |
| 285 | public function init_download_page($backup_id){ |
| 286 | global $wpvivid_plugin; |
| 287 | if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) { |
| 288 | $ret['error']='Invalid parameter param:'.$backup_id; |
| 289 | return $ret; |
| 290 | } |
| 291 | else { |
| 292 | $backup_id=sanitize_key($backup_id); |
| 293 | return $wpvivid_plugin->init_download($backup_id); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | public function prepare_download_backup($backup_id, $file_name){ |
| 298 | if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) |
| 299 | { |
| 300 | $ret['error']='Invalid parameter param:'.$backup_id; |
| 301 | return $ret; |
| 302 | } |
| 303 | if(!isset($file_name)||empty($file_name)||!is_string($file_name)) |
| 304 | { |
| 305 | $ret['error']='Invalid parameter param:'.$file_name; |
| 306 | return $ret; |
| 307 | } |
| 308 | $download_info=array(); |
| 309 | $download_info['backup_id']=sanitize_key($backup_id); |
| 310 | $download_info['file_name'] = $file_name; |
| 311 | |
| 312 | @set_time_limit(600); |
| 313 | if (session_id()) |
| 314 | session_write_close(); |
| 315 | try |
| 316 | { |
| 317 | $downloader=new WPvivid_downloader(); |
| 318 | $downloader->ready_download($download_info); |
| 319 | } |
| 320 | catch (Exception $e) |
| 321 | { |
| 322 | $message = 'A exception ('.get_class($e).') occurred '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')'; |
| 323 | error_log($message); |
| 324 | return array('error'=>$message); |
| 325 | } |
| 326 | catch (Error $e) |
| 327 | { |
| 328 | $message = 'A error ('.get_class($e).') has occurred: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')'; |
| 329 | error_log($message); |
| 330 | return array('error'=>$message); |
| 331 | } |
| 332 | |
| 333 | $ret['result']='success'; |
| 334 | return $ret; |
| 335 | } |
| 336 | |
| 337 | public function get_download_task($backup_id){ |
| 338 | if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) { |
| 339 | $ret['error']='Invalid parameter param:'.$backup_id; |
| 340 | return $ret; |
| 341 | } |
| 342 | else { |
| 343 | $backup = WPvivid_Backuplist::get_backup_by_id($backup_id); |
| 344 | if ($backup === false) { |
| 345 | $ret['result'] = WPVIVID_FAILED; |
| 346 | $ret['error'] = 'backup id not found'; |
| 347 | return $ret; |
| 348 | } |
| 349 | $backup_item = new WPvivid_Backup_Item($backup); |
| 350 | $ret = $backup_item->update_download_page($backup_id); |
| 351 | return $ret; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | public function download_backup($backup_id, $file_name){ |
| 356 | global $wpvivid_plugin; |
| 357 | if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) { |
| 358 | $ret['error']='Invalid parameter param: backup_id'; |
| 359 | return $ret; |
| 360 | } |
| 361 | if(!isset($file_name)||empty($file_name)||!is_string($file_name)) { |
| 362 | $ret['error']='Invalid parameter param: file_name'; |
| 363 | return $ret; |
| 364 | } |
| 365 | $backup_id=sanitize_key($backup_id); |
| 366 | $cache=WPvivid_taskmanager::get_download_cache($backup_id); |
| 367 | if($cache===false) { |
| 368 | $wpvivid_plugin->init_download($backup_id); |
| 369 | $cache=WPvivid_taskmanager::get_download_cache($backup_id); |
| 370 | } |
| 371 | $path=false; |
| 372 | if(array_key_exists($file_name,$cache['files'])) { |
| 373 | if($cache['files'][$file_name]['status']=='completed') { |
| 374 | $path=$cache['files'][$file_name]['download_path']; |
| 375 | $download_url = $cache['files'][$file_name]['download_url']; |
| 376 | } |
| 377 | } |
| 378 | if($path!==false) { |
| 379 | if (file_exists($path)) { |
| 380 | $ret['download_url'] = $download_url; |
| 381 | $ret['size'] = filesize($path); |
| 382 | } |
| 383 | } |
| 384 | return $ret; |
| 385 | } |
| 386 | |
| 387 | public function set_general_setting($setting){ |
| 388 | $ret=array(); |
| 389 | try { |
| 390 | if(isset($setting)&&!empty($setting)) { |
| 391 | $json_setting = $setting; |
| 392 | $json_setting = stripslashes($json_setting); |
| 393 | $setting = json_decode($json_setting, true); |
| 394 | if (is_null($setting)) { |
| 395 | $ret['error']='bad parameter'; |
| 396 | return $ret; |
| 397 | } |
| 398 | WPvivid_Setting::update_setting($setting); |
| 399 | } |
| 400 | |
| 401 | $ret['result']='success'; |
| 402 | } |
| 403 | catch (Exception $error) { |
| 404 | $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';'; |
| 405 | error_log($message); |
| 406 | return array('error'=>$message); |
| 407 | } |
| 408 | return $ret; |
| 409 | } |
| 410 | |
| 411 | public function set_schedule($schedule){ |
| 412 | $ret=array(); |
| 413 | try { |
| 414 | if(isset($schedule)&&!empty($schedule)) { |
| 415 | $json = $schedule; |
| 416 | $json = stripslashes($json); |
| 417 | $schedule = json_decode($json, true); |
| 418 | if (is_null($schedule)) { |
| 419 | $ret['error']='bad parameter'; |
| 420 | return $ret; |
| 421 | } |
| 422 | $ret=WPvivid_Schedule::set_schedule_ex($schedule); |
| 423 | if($ret['result']!='success') { |
| 424 | return $ret; |
| 425 | } |
| 426 | } |
| 427 | $ret['result']='success'; |
| 428 | } |
| 429 | catch (Exception $error) { |
| 430 | $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';'; |
| 431 | error_log($message); |
| 432 | return array('error'=>$message); |
| 433 | } |
| 434 | return $ret; |
| 435 | } |
| 436 | |
| 437 | public function set_remote($remote){ |
| 438 | global $wpvivid_plugin; |
| 439 | $ret=array(); |
| 440 | try { |
| 441 | if(isset($remote)&&!empty($remote)) { |
| 442 | $json = $remote; |
| 443 | $json = stripslashes($json); |
| 444 | $remote = json_decode($json, true); |
| 445 | if (is_null($remote)) { |
| 446 | $ret['error']='bad parameter'; |
| 447 | return $ret; |
| 448 | } |
| 449 | $wpvivid_plugin->function_realize->_set_remote($remote); |
| 450 | } |
| 451 | $ret['result']='success'; |
| 452 | } |
| 453 | catch (Exception $error) { |
| 454 | $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';'; |
| 455 | error_log($message); |
| 456 | return array('error'=>$message); |
| 457 | } |
| 458 | return $ret; |
| 459 | } |
| 460 | } |