is_plugin_installed = true; if ( version_compare( phpversion(), '5.3', '>=' ) ) { add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); } } } public function init() { if ( version_compare( phpversion(), '5.3', '<' ) ) { return; } if (!$this->is_plugin_installed) { return; } add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); if ( get_option( 'mainwp_backupwordpress_hide_plugin' ) === 'hide' ) { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); } } function hide_update_notice( $slugs ) { $slugs[] = 'backupwordpress/backupwordpress.php'; return $slugs; } function remove_update_nag( $value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } if (! MainWP_Helper::is_screen_with_update()) { return $value; } if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) { unset( $value->response['backupwordpress/backupwordpress.php'] ); } return $value; } public function action() { $information = array(); if ( ! self::isActivated() ) { $information['error'] = 'NO_BACKUPWORDPRESS'; MainWP_Helper::write( $information ); } if ( isset( $_POST['mwp_action'] ) ) { switch ( $_POST['mwp_action'] ) { case 'set_showhide': $information = $this->set_showhide(); break; case 'delete_schedule': $information = $this->delete_schedule(); break; case 'cancel_schedule': $information = $this->hmbkp_request_cancel_backup(); break; case 'get_backup_status': $information = $this->get_backup_status(); break; case 'reload_backupslist': $information = $this->reload_backups(); break; case 'delete_backup': $information = $this->hmbkp_request_delete_backup(); break; case 'run_schedule': $information = $this->run_schedule(); break; case 'save_all_schedules': $information = $this->save_all_schedules(); break; case 'update_schedule': $information = $this->update_schedule(); break; case 'get_excluded': $information = $this->get_excluded(); break; case 'directory_browse': $information = $this->directory_browse(); break; case 'exclude_add_rule': $information = $this->hmbkp_add_exclude_rule(); break; case 'exclude_remove_rule': $information = $this->hmbkp_remove_exclude_rule(); break; case 'general_exclude_add_rule': $information = $this->general_exclude_add_rule(); break; } } MainWP_Helper::write( $information ); } function check_schedule() { $schedule_id = ( isset( $_POST['schedule_id'] ) && ! empty( $_POST['schedule_id'] ) ) ? $_POST['schedule_id'] : ''; if ( empty( $schedule_id ) ) { $information = array( 'error' => 'Empty schedule id' ); MainWP_Helper::write( $information ); } else { $schedule_id = sanitize_text_field( urldecode( $schedule_id ) ); HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); if ( ! HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) { $information = array( 'result' => 'NOTFOUND' ); MainWP_Helper::write( $information ); } } return $schedule_id; } // ok public function syncOthersData( $information, $data = array() ) { if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) { try { $information['syncBackUpWordPress'] = $this->get_sync_data(); } catch(Exception $e) { } } return $information; } // ok private function get_sync_data() { MainWP_Helper::check_classes_exists('HM\BackUpWordPress\Schedules'); MainWP_Helper::check_methods('HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) ); HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); $backups_time = array(); if (is_array($schedules) && count($schedules)) { $check = current($schedules); MainWP_Helper::check_methods($check, array( 'get_backups' ) ); foreach ( $schedules as $sche ) { $existing_backup = $sche->get_backups(); if ( ! empty( $existing_backup ) ) { $backups_time = array_merge( $backups_time, array_keys( $existing_backup ) ); } } } $lasttime_backup = 0; if ( ! empty( $backups_time ) ) { $lasttime_backup = max( $backups_time ); } $return = array( 'lasttime_backup' => $lasttime_backup ); return $return; } function do_site_stats() { if (has_action('mainwp_child_reports_log')) { do_action( 'mainwp_child_reports_log', 'backupwordpress'); } else { $this->do_reports_log('backupwordpress'); } } // ok public function do_reports_log( $ext = '') { if ( $ext !== 'backupwordpress' ) { return; } if (!$this->is_plugin_installed) { return; } try { MainWP_Helper::check_classes_exists('HM\BackUpWordPress\Schedules'); MainWP_Helper::check_methods('HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' )); // Refresh the schedules from the database to make sure we have the latest changes HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); if (is_array($schedules) && count($schedules) > 0) { $check = current($schedules); MainWP_Helper::check_methods($check, array( 'get_backups', 'get_type' )); foreach($schedules as $schedule) { foreach ( $schedule->get_backups() as $file ) { $backup_type = $schedule->get_type(); $message = 'BackupWordpres backup ' . $backup_type . ' finished'; $destination = 'N/A'; if ( file_exists( $file ) ) { $date = @filemtime( $file ); if ( !empty( $date ) ) { do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $date ); MainWP_Helper::update_lasttime_backup('backupwordpress', $date); // to support backup before update feature } } } } } } catch(Exception $e) { } } function set_showhide() { $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : ''; MainWP_Helper::update_option( 'mainwp_backupwordpress_hide_plugin', $hide ); $information['result'] = 'SUCCESS'; return $information; } function delete_schedule() { $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); if ( $schedule ) { $schedule->cancel( true ); $information['result'] = 'SUCCESS'; } else { $information['result'] = 'NOTFOUND'; } return $information; } function hmbkp_request_cancel_backup() { $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); // Delete the running backup if (method_exists($schedule, 'get_running_backup_filename' )) { if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) { unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ); } if ( $schedule->get_schedule_running_path() && file_exists( $schedule->get_schedule_running_path() ) ) { unlink( $schedule->get_schedule_running_path() ); } } else { $status = $schedule->get_status(); // Delete the running backup if ( $status->get_backup_filename() && file_exists( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ) ) { unlink( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ); } if ( file_exists( $status->get_status_filepath() ) ) { unlink( $status->get_status_filepath() ); } } HM\BackUpWordPress\Path::get_instance()->cleanup(); if ($status === null) { $information['scheduleStatus'] = $schedule->get_status(); } else { $information['scheduleStatus'] = $status->get_status(); } $information['result'] = 'SUCCESS'; return $information; } function get_backup_status() { $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); if (method_exists($schedule, 'get_running_backup_filename' )) { $information['scheduleStatus'] = $schedule->get_status(); } else { $status = $schedule->get_status(); $information['scheduleStatus'] = $status->get_status(); } $information['result'] = 'SUCCESS'; return $information; } function run_schedule() { $schedule_id = $this->check_schedule(); if (function_exists('hmbkp_run_schedule_async')) { hmbkp_run_schedule_async($schedule_id); } elseif (function_exists('\HM\BackUpWordPress\run_schedule_async')) { HM\BackUpWordPress\Path::get_instance()->cleanup(); // Fixes an issue on servers which only allow a single session per client session_write_close(); $task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id ); $task->schedule(); } else { return array( 'error' => __('Error while trying to trigger the schedule', 'mainwp-child') ); } return array( 'result' => 'SUCCESS' ); } function reload_backups() { $scheduleIds = isset( $_POST['schedule_ids'] ) ? $_POST['schedule_ids'] : array(); HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); $all_schedules_ids = array(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); foreach ( $schedules as $sch ) { $all_schedules_ids[] = $sch->get_id(); } if ( empty( $all_schedules_ids ) ) { return array( 'error' => 'Schedules could not be found.' ); } foreach ( $all_schedules_ids as $schedule_id ) { if ( ! HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) { continue; } $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); $started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time(); $out = array( 'b' => $this->get_backupslist_html( $schedule ), 'count' => count( $schedule->get_backups() ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), 'started_ago' => human_time_diff( $started_ago ), ); if (method_exists($schedule, 'get_running_backup_filename' )) { $out['scheduleStatus'] = $schedule->get_status(); } else { $status = $schedule->get_status(); $out['scheduleStatus'] = $status->get_status(); } $information['backups'][ $schedule_id ] = $out; } $send_back_schedules = array(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); foreach ( $schedules as $schedule ) { $sch_id = $schedule->get_id(); if ( ! in_array( $sch_id, $scheduleIds ) ) { $current_option = get_option( 'hmbkp_schedule_' . $sch_id ); if ( is_array( $current_option ) ) { unset( $current_option['excludes'] ); // not send this value $started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time(); $send_back_schedules[ $sch_id ] = array( 'options' => $current_option, 'b' => $this->get_backupslist_html( $schedule ), 'count' => count( $schedule->get_backups() ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), 'scheduleStatus' => $schedule->get_status(), 'started_ago' => human_time_diff( $started_ago ), ); if (method_exists($schedule, 'get_running_backup_filename' )) { $send_back_schedules['scheduleStatus'] = $schedule->get_status(); } else { $status = $schedule->get_status(); $send_back_schedules['scheduleStatus'] = $status->get_status(); } } } } if (function_exists('HM\BackUpWordPress\Backup::get_home_path')) { $backups_path = str_replace( HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() ); } else { $backups_path = str_replace( HM\BackUpWordPress\Path::get_home_path(), '', HM\BackUpWordPress\Path::get_path() ); } $information['backups_path'] = $backups_path; $information['send_back_schedules'] = $send_back_schedules; $information['result'] = 'SUCCESS'; return $information; } function hmbkp_request_delete_backup() { if ( ! isset( $_POST['hmbkp_backuparchive'] ) || empty( $_POST['hmbkp_backuparchive'] ) ) { return array( 'error' => __( 'Invalid data. Please check and try again.', 'mainwp-child' ) ); } $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); $deleted = $schedule->delete_backup(base64_decode( urldecode($_POST['hmbkp_backuparchive'] ))); if ( is_wp_error( $deleted ) ) { return array( 'error' => $deleted->get_error_message() ); } $ret = array( 'result' => 'SUCCESS', 'b' => $this->get_backupslist_html( $schedule ), 'count' => count( $schedule->get_backups() ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), ); if (method_exists($schedule, 'get_running_backup_filename' )) { $ret['scheduleStatus'] = $schedule->get_status(); } else { $status = $schedule->get_status(); $ret['scheduleStatus'] = $status->get_status(); } return $ret; } function get_backupslist_html( $schedule ) { ob_start(); ?>
%s
)', esc_attr( $schedule->get_formatted_site_size() ) );
}
} else {
$site_size = new HM\BackUpWordPress\Site_Size( $schedule->get_type(), $schedule->get_excludes() );
if ( ( 'database' === $schedule->get_type() ) || $site_size->is_site_size_cached() ) {
return sprintf( '(%s
)', esc_attr( $site_size->get_formatted_site_size() ) );
}
}
return sprintf( '(' . __( 'calculating the size of your backup…', 'mainwp-backupwordpress-extension' ) . '
)' );
}
function hmbkp_get_backup_row( $file, HM\BackUpWordPress\Scheduled_Backup $schedule ) {
$encoded_file = urlencode( base64_encode( $file ) );
$offset = get_option( 'gmt_offset' ) * 3600;
?>
VCS folders and other backup plugin folders.', 'backupwordpress' ); ?>
/
/
|
filesize( $root );
} else {
$size = $schedule->filesize( $root, true );
}
if ( false !== $size ) {
$size = size_format( $size );
if ( ! $size ) {
$size = '0 B';
}
?>
| ||||
---|---|---|---|---|---|
isFile() ) { ?> isDir() ) { ?> |
getBasename() ); ?>
isFile() ) { ?>
getBasename() ); ?>
isDir() ) { ?>
getBasename() ); ?>
getBasename() ); ?>
isFile() ) { ?>
getBasename() ); ?>
isDir() ) {
//echo add_query_arg( 'hmbkp_directory_browse', urlencode( $file->getPathname() ) );
?>
getBasename() ); ?>
|
isDir() && $is_size_calculated ) : ?>
filesize( $file );
} else {
$size = $schedule->filesize( $file );
}
if ( false !== $size ) {
$size = size_format( $size );
if ( ! $size ) {
$size = '0 B';
}
?>
isDir() ) { ?>
--
|
getPerms() ), - 4 ) ); ?> | isLink() ) : ?> isDir() ) : esc_html_e( 'Folder', 'backupwordpress' ); else : esc_html_e( 'File', 'backupwordpress' ); endif; ?> | getPathname(); // Excluded directories need to be trailingslashed if ( $file->isDir() ) { $exclude_path = trailingslashit( wp_normalize_path( $file->getPathname() ) ); } ?> |