'backups', 'singular' => 'backup', 'ajax' => true, ) ); $this->destinations = BackWPup::get_registered_destinations(); } public function ajax_user_can() { return current_user_can( 'backwpup_backups' ); } public function prepare_items() { $per_page = $this->get_items_per_page( 'backwpupbackups_per_page' ); if ( empty( $per_page ) || $per_page < 1 ) { $per_page = 20; } $jobdest = ''; if ( isset( $_GET['jobdets-button-top'] ) ) { $jobdest = sanitize_text_field( $_GET['jobdest-top'] ); } if ( isset( $_GET['jobdets-button-bottom'] ) ) { $jobdest = sanitize_text_field( $_GET['jobdest-bottom'] ); } if ( empty( $jobdest ) ) { $jobdests = $this->get_destinations_list(); if ( empty( $jobdests ) ) { $jobdests = array( '_' ); } $jobdest = $jobdests[0]; $_GET['jobdest-top'] = $jobdests[0]; $_GET['jobdets-button-top'] = 'empty'; } list( $this->jobid, $this->dest ) = explode( '_', $jobdest ); if ( ! empty( $this->destinations[ $this->dest ]['class'] ) ) { /** @var BackWPup_Destinations $dest_object */ $dest_object = BackWPup::get_destination( $this->dest ); $this->items = $dest_object->file_get_list( $jobdest ); } if ( ! $this->items ) { $this->items = ''; return; } // Sorting. $order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_STRING ) ?: 'desc'; $orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_STRING ) ?: 'time'; $tmp = array(); if ( $orderby === 'time' ) { if ( $order === 'asc' ) { foreach ( $this->items as &$ma ) { $tmp[] = &$ma["time"]; } array_multisort( $tmp, SORT_ASC, $this->items ); } else { foreach ( $this->items as &$ma ) { $tmp[] = &$ma["time"]; } array_multisort( $tmp, SORT_DESC, $this->items ); } } elseif ( $orderby === 'file' ) { if ( $order === 'asc' ) { foreach ( $this->items as &$ma ) { $tmp[] = &$ma["filename"]; } array_multisort( $tmp, SORT_ASC, $this->items ); } else { foreach ( $this->items as &$ma ) { $tmp[] = &$ma["filename"]; } array_multisort( $tmp, SORT_DESC, $this->items ); } } elseif ( $orderby === 'folder' ) { if ( $order === 'asc' ) { foreach ( $this->items as &$ma ) { $tmp[] = &$ma["folder"]; } array_multisort( $tmp, SORT_ASC, $this->items ); } else { foreach ( $this->items as &$ma ) { $tmp[] = &$ma["folder"]; } array_multisort( $tmp, SORT_DESC, $this->items ); } } elseif ( $orderby === 'size' ) { if ( $order === 'asc' ) { foreach ( $this->items as &$ma ) { $tmp[] = &$ma["filesize"]; } array_multisort( $tmp, SORT_ASC, $this->items ); } else { foreach ( $this->items as &$ma ) { $tmp[] = &$ma["filesize"]; } array_multisort( $tmp, SORT_DESC, $this->items ); } } $this->set_pagination_args( array( 'total_items' => count( $this->items ), 'per_page' => $per_page, 'jobdest' => $jobdest, 'orderby' => $orderby, 'order' => $order, ) ); // Only display items on page. $start = intval( ( $this->get_pagenum() - 1 ) * $per_page ); $end = $start + $per_page; if ( $end > count( $this->items ) ) { $end = count( $this->items ); } $i = - 1; $paged_items = array(); foreach ( $this->items as $item ) { $i ++; if ( $i < $start ) { continue; } if ( $i >= $end ) { break; } $paged_items[] = $item; } $this->items = $paged_items; } public function no_items() { _e( 'No files could be found. (List will be generated during next backup.)', 'backwpup' ); } public function get_bulk_actions() { if ( ! $this->has_items() ) { return array(); } $actions = array(); $actions['delete'] = __( 'Delete', 'backwpup' ); return $actions; } public function extra_tablenav( $which ) { $destinations_list = $this->get_destinations_list(); if ( count( $destinations_list ) < 1 ) { return; } if ( count( $destinations_list ) === 1 ) { echo ''; return; } ?>
'query-submit-' . $which ) ); ?>
'; $posts_columns['time'] = __( 'Time', 'backwpup' ); $posts_columns['file'] = __( 'File', 'backwpup' ); $posts_columns['folder'] = __( 'Folder', 'backwpup' ); $posts_columns['size'] = __( 'Size', 'backwpup' ); return $posts_columns; } public function get_sortable_columns() { return array( 'file' => array( 'file', false ), 'folder' => 'folder', 'size' => 'size', 'time' => array( 'time', false ), ); } public function column_cb( $item ) { return ''; } public function get_destinations_list() { $jobdest = array(); $jobids = BackWPup_Option::get_job_ids(); foreach ( $jobids as $jobid ) { if ( BackWPup_Option::get( $jobid, 'backuptype' ) === 'sync' ) { continue; } $dests = BackWPup_Option::get( $jobid, 'destinations' ); foreach ( $dests as $dest ) { if ( ! $this->destinations[ $dest ]['class'] ) { continue; } $dest_class = BackWPup::get_destination( $dest ); $can_do_dest = $dest_class->file_get_list( $jobid . '_' . $dest ); if ( ! empty( $can_do_dest ) ) { $jobdest[] = $jobid . '_' . $dest; } } } return $jobdest; } public function column_file( $item ) { $actions = array(); $r = '' . esc_attr( $item['filename'] ) . '
'; if ( ! empty( $item['info'] ) ) { $r .= esc_attr( $item['info'] ) . '
'; } if ( current_user_can( 'backwpup_backups_delete' ) ) { $actions['delete'] = $this->delete_item_action( $item ); } if ( ! empty( $item['downloadurl'] ) && current_user_can( 'backwpup_backups_download' ) ) { try { $actions['download'] = $this->download_item_action( $item ); } catch ( BackWPup_Factory_Exception $e ) { $actions['download'] = sprintf( '%2$s', wp_nonce_url( $item['downloadurl'], 'backwpup_action_nonce' ), __( 'Download', 'backwpup' ) ); } } // Add restore url to link list if ( current_user_can( 'backwpup_restore' ) && ! empty( $item['restoreurl'] ) ) { $item['restoreurl'] = add_query_arg( array( 'step' => 1, 'trigger_download' => 1, ), $item['restoreurl'] ); $actions['restore'] = sprintf( '%2$s', wp_nonce_url( $item['restoreurl'], 'restore-backup_' . $this->jobid ), __( 'Restore', 'backwpup' ) ); } $r .= $this->row_actions( $actions ); return $r; } public function column_folder( $item ) { return esc_attr( $item['folder'] ); } public function column_size( $item ) { if ( ! empty( $item['filesize'] ) && $item['filesize'] != - 1 ) { return size_format( $item['filesize'], 2 ); } else { return __( '?', 'backwpup' ); } } public function column_time( $item ) { return sprintf( __( '%1$s at %2$s', 'backwpup' ), date_i18n( get_option( 'date_format' ), $item['time'], true ), date_i18n( get_option( 'time_format' ), $item['time'], true ) ); } public static function load() { //Create Table self::$listtable = new BackWPup_Page_Backups; switch ( self::$listtable->current_action() ) { case 'delete': //Delete Backup archives check_admin_referer( 'bulk-backups' ); if ( ! current_user_can( 'backwpup_backups_delete' ) ) { wp_die( __( 'Sorry, you don\'t have permissions to do that.', 'backwpup' ) ); } $jobdest = ''; if ( isset( $_GET['jobdest'] ) ) { $jobdest = sanitize_text_field( $_GET['jobdest'] ); } if ( isset( $_GET['jobdest-top'] ) ) { $jobdest = sanitize_text_field( $_GET['jobdest-top'] ); } $_GET['jobdest-top'] = $jobdest; $_GET['jobdets-button-top'] = 'submit'; if ( $jobdest === '' ) { return; } list( $jobid, $dest ) = explode( '_', $jobdest ); /** @var BackWPup_Destinations $dest_class */ $dest_class = BackWPup::get_destination( $dest ); $files = $dest_class->file_get_list( $jobdest ); foreach ( $_GET['backupfiles'] as $backupfile ) { foreach ( $files as $file ) { if ( is_array( $file ) && $file['file'] == $backupfile ) { $dest_class->file_delete( $jobdest, $backupfile ); } } } $files = $dest_class->file_get_list( $jobdest ); if ( empty ( $files ) ) { $_GET['jobdest-top'] = ''; } break; default: if ( isset( $_GET['jobid'] ) ) { $jobid = absint( $_GET['jobid'] ); if ( ! current_user_can( 'backwpup_backups_download' ) ) { wp_die( __( 'Sorry, you don\'t have permissions to do that.', 'backwpup' ) ); } check_admin_referer( 'backwpup_action_nonce' ); $filename = untrailingslashit( BackWPup::get_plugin_data( 'temp' ) ) . '/' . basename( isset( $_GET['local_file'] ) ? $_GET['local_file'] : $_GET['file'] ); if ( file_exists( $filename ) ) { $downloader = new BackWPup_Download_File( $filename, function ( \BackWPup_Download_File_Interface $obj ) use ( $filename ) { $obj->clean_ob() ->headers(); readfile( $filename ); // Delete the temporary file. unlink( $filename ); die(); }, 'backwpup_backups_download' ); $downloader->download(); } else { // If the file doesn't exist, fallback to old way of downloading // This is for destinations without a downloader class $dest = strtoupper( str_replace( 'download', '', self::$listtable->current_action() ) ); if ( ! empty( $dest ) && strstr( self::$listtable->current_action(), 'download' ) ) { /** @var BackWPup_Destinations $dest_class */ $dest_class = BackWPup::get_destination( $dest ); try { $dest_class->file_download( $jobid, trim( sanitize_text_field( $_GET['file'] ) ) ); } catch ( BackWPup_Destination_Download_Exception $e ) { header( 'HTTP/1.0 404 Not Found' ); wp_die( esc_html__( 'Ops! Unfortunately the file doesn\'t exists. May be was deleted?' ), esc_html__( '404 - File Not Found.' ), array( 'back_link' => esc_html__( '« Go back', 'backwpup' ), ) ); } } } } break; } //Save per page if ( isset( $_POST['screen-options-apply'] ) && isset( $_POST['wp_screen_options']['option'] ) && isset( $_POST['wp_screen_options']['value'] ) && $_POST['wp_screen_options']['option'] == 'backwpupbackups_per_page' ) { check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); global $current_user; if ( $_POST['wp_screen_options']['value'] > 0 && $_POST['wp_screen_options']['value'] < 1000 ) { update_user_option( $current_user->ID, 'backwpupbackups_per_page', (int) $_POST['wp_screen_options']['value'] ); wp_redirect( remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() ) ); exit; } } add_screen_option( 'per_page', array( 'label' => __( 'Backup Files', 'backwpup' ), 'default' => 20, 'option' => 'backwpupbackups_per_page', ) ); self::$listtable->prepare_items(); } public static function admin_print_styles() { ?>

display(); ?>
jobid . '_' . $this->dest, $this->get_pagenum(), esc_attr( $item['file'] ) ); $url = wp_nonce_url( network_admin_url( 'admin.php' ) . $query, 'bulk-backups' ); $js = sprintf( 'if ( confirm(\'%s\') ) { return true; } return false;', esc_js( __( 'You are about to delete this backup archive. \'Cancel\' to stop, \'OK\' to delete.', "backwpup" ) ) ); return sprintf( '%3$s', $url, $js, __( 'Delete', 'backwpup' ) ); } private function download_item_action( $item ) { $local_file = untrailingslashit( BackWPup::get_plugin_data( 'TEMP' ) ) . "/{$item['filename']}"; return sprintf( '%7$s', intval( $this->jobid ), esc_attr( $this->dest ), esc_attr( $item['file'] ), esc_attr( $local_file ), wp_create_nonce( 'backwpup_action_nonce' ), wp_nonce_url( $item['downloadurl'], 'backwpup_action_nonce' ), __( 'Download', 'backwpup' ) ); } }