This repository was archived by the owner on Mar 1, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathsimple-backup-list-table.php
More file actions
235 lines (158 loc) · 7.19 KB
/
Copy pathsimple-backup-list-table.php
File metadata and controls
235 lines (158 loc) · 7.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
if(!class_exists('WP_List_Table')){
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
class Backup_List_Table extends WP_List_Table{
private $opt;
function __construct(){
$parent_args = array(
'singular' => 'backup', //singular name of the listed records
'plural' => 'backups', //plural name of the listed records
'ajax' => true //does this table support ajax?
);
$this->opt = get_option('simple-backup-settings');
parent::__construct($parent_args);
}
function column_filename($item) {
$actions = array(
//'Download' => sprintf('<a href="%s">Download</a>',$item['link']),
'Download' => sprintf('<a href="'.admin_url().'tools.php?page=%s&download_backup_file=%s">Download</a>',"backup_manager",$item['filename']),
'Delete' => sprintf('<a href="'.admin_url().'tools.php?page=%s&delete_backup_file=%s">Delete</a>',"backup_manager",$item['filename'])
);
if(isset($this->opt['backup_settings']['enable_ftp_backup_system']) && "true" == $this->opt['backup_settings']['enable_ftp_backup_system']){
$actions['Copy to FTP'] = sprintf('<a href="'.admin_url().'tools.php?page=%s&ftp_put_backup_file=%s">Copy to FTP</a>',"backup_manager",$item['filename']);
}
//$link = sprintf('<strong><a href="%s">%s</a></strong>',$item['link'], $item['filename']);
$link = sprintf('<strong><a href="'.admin_url().'tools.php?page=%1$s&download_backup_file=%2$s">%2$s</a></strong>',"backup_manager",$item['filename']);
return sprintf('%1$s %2$s', $link, $this->row_actions($actions) );
}
function get_columns(){
global $status;
$columns = array(
'filename' => __('File Name', 'simple-backup'),
'size' => __('File Size', 'simple-backup'),
'date' => __('File Date', 'simple-backup'),
);
return $columns;
}
function get_sortable_columns(){
$sortable_columns = array(
'filename' => array('filename',false),
'size' => array('size',false),
'date' => array('date',true)
);
return $sortable_columns;
}
function extra_tablenav($which){
if ( 'top' == $which ){
$link = "<div class='alignleft actions' >";
//$link .= "<form method='post' style='display:inline;'>";
//$link .= "<input type='hidden' name='simple-backup' value='simple-backup'>";
//$link .= "<input type='submit' value='Create WordPress Backup' class='button-primary'>";
//$link .= "</form > ";
$link .= "<form method='post' action='".admin_url()."options-general.php?page=simple-backup-settings' style='display:inline;'>";
$link .= "<input type='submit' value='Change Backup Settings' class='button-secondary'>";
$link .= "</form>";
$link .= "</div>";
echo $link;
}
if ( 'bottom' == $which ){
$link = "<div class='alignleft actions'>";
$link .= "<form method='post' style='display:inline;'>";
$link .= "<input type='hidden' name='simple-backup' value='simple-backup'>";
$link .= "<input type='submit' value='Create WordPress Backup' class='button-primary'>";
$link .= "</form> ";
$link .= "<form method='post' action='".admin_url()."options-general.php?page=simple-backup-settings' style='display:inline;'>";
$link .= "<input type='submit' value='Change Settings' class='button-secondary'>";
$link .= "</form>";
$link .= "</div>";
//echo $link;
}
}
function column_default($item, $column_name){
$item = apply_filters('simple-backup-output-data', $item);
//unset existing filter and pagination
$args = wp_parse_args( parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY) );
unset($args['filter']);
unset($args['paged']);
$this_page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
switch($column_name){
case "size":
return "<span title='".number_format($item[$column_name],0,"",",")." Bytes' >".size_format($item[$column_name], 2)."</span>";
break;
default:
return $item[$column_name];
}
}
function prepare_items(){
$screen = get_current_screen();
/**
* setup pagination default number per page
*/
$per_page_option = $screen->id . '_per_page';
$per_page = get_option($per_page_option, 20);
$per_page = ($per_page != false) ? $per_page : 20;
/**
* Define column headers. This includes a complete
* array of columns to be displayed (slugs & titles), a list of columns
* to keep hidden, and a list of columns that are sortable. Each of these
* can be defined in another method (as we've done here) before being
* used to build the value for our _column_headers property.
*/
$columns = $this->get_columns();
$hidden_cols = get_user_option( 'manage' . $screen->id . 'columnshidden' );
$hidden = ( $hidden_cols ) ? $hidden_cols : array();
$sortable = $this->get_sortable_columns();
/**
* Build an array to be used by the class for column
* headers. The $this->_column_headers property takes an array which contains
* 3 other arrays. One for all columns, one for hidden columns, and one
* for sortable columns.
*/
$this->_column_headers = array($columns, $hidden, $sortable);
$columns = get_column_headers( $screen );
/**
* Fetch the data for use in this table.
*/
$this->items = Simple_Backup_Manager::get_backup_files();
$data = $this->items;
usort($data, array($this, 'usort_reorder') );
/**
* Figure out what page the user is currently looking at.
*/
$current_page = $this->get_pagenum();
/**
* REQUIRED for pagination. Let's check how many items are in our data array.
* In real-world use, this would be the total number of items in your database,
* without filtering. We'll need this later, so you should always include it
* in your own package classes.
*/
$total_items = count($data);
/**
* manual pagination
*/
$data = array_slice($data,(($current_page-1)*$per_page),$per_page);
/**
* Add our *sorted* data to the items property
*/
$this->items = $data;
/**
* Register our pagination options & calculations.
*/
$this->set_pagination_args( array(
'total_items' => $total_items, //calculate the total number of items
'per_page' => $per_page, //determine how many items to show on a page
'total_pages' => ceil($total_items/$per_page) //calculate the total number of pages
) );
}
/**
* This checks for sorting input and sorts the data in our array accordingly.
*/
function usort_reorder($a,$b){
$orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'date'; //If no sort, default to title
$order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'desc'; //If no order, default to asc
$result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
}
}
?>