WP-DBManager - Version 2.00

Version Description

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-DBManager
Version 2.00
Comparing to
See all releases

Version 2.00

Files changed (4) hide show
  1. database-manager.php +601 -0
  2. dbmanager.php +36 -0
  3. readme-install.txt +24 -0
  4. readme.txt +13 -0
database-manager.php ADDED
@@ -0,0 +1,601 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ +----------------------------------------------------------------+
4
+ | |
5
+ | WordPress 2.0 Plugin: WP-DBManager 2.00 |
6
+ | Copyright (c) 2005 Lester "GaMerZ" Chan |
7
+ | |
8
+ | File Written By: |
9
+ | - Lester "GaMerZ" Chan |
10
+ | - http://www.lesterchan.net |
11
+ | |
12
+ | File Information: |
13
+ | - Manage Your WordPress Database |
14
+ | - wp-admin/database-manager.php |
15
+ | |
16
+ +----------------------------------------------------------------+
17
+ */
18
+
19
+
20
+ ### Require Admin Header
21
+ require_once('./admin.php');
22
+
23
+
24
+ ### Variables Variables Variables
25
+ $title = __('Manage Database');
26
+ $this_file = 'database-manager.php';
27
+ $parent_file = 'database-manager.php';
28
+ $mode = trim($_GET['mode']);
29
+ $backup = array();
30
+ $backup['date'] = time();
31
+ $backup['mysqldumppath'] = 'mysqldump';
32
+ $backup['mysqlpath'] = 'mysql';
33
+ $backup['path'] = ABSPATH.'wp-backup-db/';
34
+
35
+
36
+ ### Cancel
37
+ if(isset($_POST['cancel'])) {
38
+ Header('Location: database-manager.php');
39
+ exit();
40
+ }
41
+
42
+
43
+ ### Format Bytes Into KB/MB
44
+ function format_size($rawSize) {
45
+ if ($rawSize / 1048576 > 1)
46
+ return round($rawSize/1048576, 1) . ' MB';
47
+ else if ($rawSize / 1024 > 1)
48
+ return round($rawSize/1024, 1) . ' KB';
49
+ else
50
+ return round($rawSize, 1) . ' bytes';
51
+ }
52
+
53
+
54
+ ### Check Folder Whether There Is Any File Inside
55
+ function is_emtpy_folder($folder){
56
+ if(is_dir($folder) ){
57
+ $handle = opendir($folder);
58
+ while( (gettype( $name = readdir($handle)) != 'boolean')){
59
+ $name_array[] = $name;
60
+ }
61
+ foreach($name_array as $temp)
62
+ $folder_content .= $temp;
63
+
64
+ if($folder_content == '...')
65
+ return true;
66
+ else
67
+ return false;
68
+ closedir($handle);
69
+ }
70
+ else
71
+ return true; // folder doesnt exist
72
+ }
73
+
74
+
75
+ ### Form Processing
76
+ if($_POST['do']) {
77
+ // Lets Prepare The Variables
78
+ $database_file = trim($_POST['database_file']);
79
+ $optimize = $_POST['optimize'];
80
+ $delete = $_POST['delete'];
81
+ $nice_file_date = date('l, jS F Y @ H:i', substr($database_file, 0, 10));
82
+
83
+ // Decide What To Do
84
+ switch($_POST['do']) {
85
+ case 'Backup':
86
+ $gzip = intval($_POST['gzip']);
87
+ if($gzip == 1) {
88
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
89
+ $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
90
+ $backup['command'] = $backup['mysqldumppath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' --add-drop-table '.DB_NAME.' | gzip > '.$backup['filepath'];
91
+ } else {
92
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
93
+ $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
94
+ $backup['command'] = $backup['mysqldumppath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' --add-drop-table '.DB_NAME.' > '.$backup['filepath'];
95
+ }
96
+ passthru($backup['command'], $error);
97
+ if(!is_writable($backup['path'])) {
98
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Backup Folder Not Writable</font>";
99
+ } elseif(filesize($backup['filepath']) == 0) {
100
+ unlink($backup['filepath']);
101
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Backup File Size Is 0KB</font>";
102
+ } elseif(!is_file($backup['filepath'])) {
103
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Invalid Backup File Path</font>";
104
+ } elseif($error) {
105
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'</font>";
106
+ } else {
107
+ $text = "<font color=\"green\">Database Backed Up Successfully On '".date('l, jS F Y @ H:i')."'</font>";
108
+ }
109
+ break;
110
+ case 'Restore':
111
+ if(!empty($database_file)) {
112
+ if(stristr($database_file, '.gz')) {
113
+ $backup['command'] = 'gunzip < '.$backup['path'].'/'.$database_file.' | '.$backup['mysqlpath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' '.DB_NAME;
114
+ } else {
115
+ $backup['command'] = $backup['mysqlpath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' '.DB_NAME.' < '.$backup['path'].'/'.$database_file;
116
+ }
117
+ passthru($backup['command'], $error);
118
+ if($error) {
119
+ $text = "<font color=\"red\">Database On '$nice_file_date' Failed To Restore</font>";
120
+ } else {
121
+ $text = "<font color=\"green\">Database On '$nice_file_date' Restored Successfully</font>";
122
+ }
123
+ } else {
124
+ $text = '<font color="red">No Backup Database File Selected</font>';
125
+ }
126
+ break;
127
+ case 'Delete':
128
+ if(!empty($delete)) {
129
+ foreach($delete as $dbbackup) {
130
+ $nice_file_date = date('l, jS F Y @ H:i', substr($dbbackup, 0, 10));
131
+ if(is_file($backup['path'].'/'.$dbbackup)) {
132
+ if(!unlink($backup['path'].'/'.$dbbackup)) {
133
+ $text .= "<font color=\"red\">Unable To Delete Database Backup File On '$nice_file_date'</font><br />";
134
+ } else {
135
+ $text .= "<font color=\"green\">Database Backup File On '$nice_file_date' Deleted Successfully</font><br />";
136
+ }
137
+ } else {
138
+ $text = "<font color=\"red\">Invalid Database Backup File On '$nice_file_date'</font>";
139
+ }
140
+ }
141
+ } else {
142
+ $text = '<font color="red">No Backup Database File Selected</font>';
143
+ }
144
+ break;
145
+ case 'Download':
146
+ if(!empty($database_file)) {
147
+ $file_path = $backup['path'].'/'.$database_file;
148
+ $nice_file_name = date('jS_F_Y', substr($database_file, 0, 10)).'-'.substr($database_file, 13);
149
+ header("Pragma: public");
150
+ header("Expires: 0");
151
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
152
+ header("Content-Type: application/force-download");
153
+ header("Content-Type: application/octet-stream");
154
+ header("Content-Type: application/download");
155
+ header("Content-Disposition: attachment; filename=".basename($nice_file_name).";");
156
+ header("Content-Transfer-Encoding: binary");
157
+ header("Content-Length: ".filesize($file_path));
158
+ @readfile($file_path);
159
+ } else {
160
+ $text = '<font color="red">No Backup Database File Selected</font>';
161
+ }
162
+ break;
163
+ case 'Optimize':
164
+ foreach($optimize as $key => $value) {
165
+ if($value == 'yes') {
166
+ $tables_string .= ', '.$key;
167
+ }
168
+ }
169
+ $selected_tables = substr($tables_string, 2);
170
+ if(!empty($selected_tables)) {
171
+ $optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables");
172
+ if(!$optimize2) {
173
+ $text = "<font color=\"red\">Table(s) '$selected_tables' Failed To Be Optimized</font>";
174
+ } else {
175
+ $text = "<font color=\"green\">Table(s) '$selected_tables' Optimized Successfully</font>";
176
+ }
177
+ } else {
178
+ $text = '<font color="red">No Tables Selected</font>';
179
+ }
180
+ break;
181
+ case 'Run':
182
+ $sql_queries2 = trim($_POST['sql_query']);
183
+ $totalquerycount = 0;
184
+ $successquery = 0;
185
+ if($sql_queries2) {
186
+ $sql_queries = array();
187
+ $sql_queries2 = explode("\n", $sql_queries2);
188
+ foreach($sql_queries2 as $sql_query2) {
189
+ $sql_query2 = trim(stripslashes($sql_query2));
190
+ $sql_query2 = preg_replace("/[\r\n]+/", '', $sql_query2);
191
+ if(!empty($sql_query2)) {
192
+ $sql_queries[] = $sql_query2;
193
+ }
194
+ }
195
+ if($sql_queries) {
196
+ foreach($sql_queries as $sql_query) {
197
+ if (preg_match("/^\\s*(insert|update|replace|delete|create) /i",$sql_query)) {
198
+ $run_query = $wpdb->query($sql_query);
199
+ if(!$run_query) {
200
+ $text .= "<font color=\"red\">$sql_query</font><br />";
201
+ } else {
202
+ $successquery++;
203
+ $text .= "<font color=\"green\">$sql_query</font><br />";
204
+ }
205
+ $totalquerycount++;
206
+ } elseif (preg_match("/^\\s*(select|drop|show|grant) /i",$sql_query)) {
207
+ $text .= "<font color=\"red\">$sql_query</font><br />";
208
+ $totalquerycount++;
209
+ }
210
+ }
211
+ $text .= "<font color=\"blue\">$successquery/$totalquerycount Query(s) Executed Successfully</font>";
212
+ } else {
213
+ $text = "<font color=\"red\">Empty Query</font>";
214
+ }
215
+ } else {
216
+ $text = "<font color=\"red\">Empty Query</font>";
217
+ }
218
+ break;
219
+ }
220
+ }
221
+
222
+
223
+ ### Switch $mode
224
+ switch($mode) {
225
+ // Backup Database
226
+ case 'backup':
227
+ $title = __('Backup Database');
228
+ require("./admin-header.php");
229
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
230
+ ?>
231
+ <ul id="submenu">
232
+ <li><a href="database-manager.php"><?php _e('Manage Database'); ?></a></li>
233
+ <li><a href="database-manager.php?mode=backup" class="current"><?php _e('Backup DB'); ?></a></li>
234
+ <li><a href="database-manager.php?mode=optimize"><?php _e('Optimize DB'); ?></a></li>
235
+ <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>
236
+ <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li>
237
+ <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li>
238
+ </ul>
239
+ <!-- Backup Database -->
240
+ <div class="wrap">
241
+ <h2>Backup Database</h2>
242
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
243
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
244
+ <tr style='background-color: #eee'>
245
+ <th align="left" scope="row">Database Name:</th>
246
+ <td><?=DB_NAME?></td>
247
+ </tr>
248
+ <tr style='background-color: none'>
249
+ <th align="left" scope="row">Database Backup To:</th>
250
+ <td><?=$backup['path']?></td>
251
+ </tr>
252
+ <tr style='background-color: #eee'>
253
+ <th align="left" scope="row">Database Backup Date:</th>
254
+ <td><?=date('jS F Y', $backup['date'])?></td>
255
+ </tr>
256
+ <tr style='background-color: none'>
257
+ <th align="left" scope="row">Database Backup File Name:</th>
258
+ <td><?=$backup['filename']?> / <?=date('jS_F_Y', substr($backup['filename'], 0, 10)).'-'.substr($backup['filename'], 13);?></td>
259
+ </tr>
260
+ <tr style='background-color: #eee'>
261
+ <th align="left" scope="row">Database Backup Type:</th>
262
+ <td>Full (Structure and Data)</td>
263
+ </tr>
264
+ <tr style='background-color: none'>
265
+ <th align="left" scope="row">MYSQL Dump Location</th>
266
+ <td><?=$backup['mysqldumppath']?></td>
267
+ </tr>
268
+ <tr style='background-color: #eee'>
269
+ <th align="left" scope="row">GZIP Database Backup File?</th>
270
+ <td><input type="radio" name="gzip" value="1">Yes&nbsp;&nbsp;<input type="radio" name="gzip" value="0" CHECKED>No</td>
271
+ </tr>
272
+ <tr>
273
+ <td colspan="2" align="center"><input type="submit" name="do" value="Backup" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></td>
274
+ </tr>
275
+ </table>
276
+ </form>
277
+ </div>
278
+ <?php
279
+ break;
280
+ // Optimize Database
281
+ case 'optimize':
282
+ $title = __('Optimize Database');
283
+ require("./admin-header.php");
284
+ $tables = $wpdb->get_results("SHOW TABLES");
285
+ ?>
286
+ <ul id="submenu">
287
+ <li><a href="database-manager.php"><?php _e('Manage Database'); ?></a></li>
288
+ <li><a href="database-manager.php?mode=backup"><?php _e('Backup DB'); ?></a></li>
289
+ <li><a href="database-manager.php?mode=optimize" class="current"><?php _e('Optimize DB'); ?></a></li>
290
+ <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>
291
+ <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li>
292
+ <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li>
293
+ </ul>
294
+ <!-- Optimize Database -->
295
+ <div class="wrap">
296
+ <h2>Optimize Database</h2>
297
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
298
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
299
+ <tr>
300
+ <th align="left" scope="col">Tables</th>
301
+ <th align="left" scope="col">Options</th>
302
+ </tr>
303
+ <?php
304
+ foreach($tables as $dbtable) {
305
+ if($no%2 == 0) {
306
+ $style = 'style=\'background-color: #eee\'';
307
+ } else {
308
+ $style = 'style=\'background-color: none\'';
309
+ }
310
+ $no++;
311
+ $table_name = '$dbtable->Tables_in_'.DB_NAME;
312
+ eval("\$table_name = \"$table_name\";");
313
+ echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
314
+ echo "<td><input type=\"radio\" name=\"optimize[$table_name]\" value=\"no\">No&nbsp;&nbsp;<input type=\"radio\" name=\"optimize[$table_name]\" value=\"yes\" CHECKED>Yes</td></tr>";
315
+ }
316
+ ?>
317
+ <tr>
318
+ <td colspan="2" align="center">Database should be optimize once every month.</td>
319
+ </tr>
320
+ <tr>
321
+ <td colspan="2" align="center"><input type="submit" name="do" value="Optimize" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></td>
322
+ </tr>
323
+ </table>
324
+ </form>
325
+ </div>
326
+ <?php
327
+ break;
328
+ // Restore Database
329
+ case 'restore':
330
+ $title = __('Restore/Download Database');
331
+ require("./admin-header.php");
332
+ ?>
333
+ <ul id="submenu">
334
+ <li><a href="database-manager.php"><?php _e('Manage Database'); ?></a></li>
335
+ <li><a href="database-manager.php?mode=backup"><?php _e('Backup DB'); ?></a></li>
336
+ <li><a href="database-manager.php?mode=optimize"><?php _e('Optimize DB'); ?></a></li>
337
+ <li><a href="database-manager.php?mode=restore" class="current"><?php _e('Restore/Download DB'); ?></a></li>
338
+ <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li>
339
+ <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li>
340
+ </ul>
341
+ <!-- Restore/Download Database -->
342
+ <div class="wrap">
343
+ <h2>Restore/Download Database</h2>
344
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
345
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
346
+ <tr>
347
+ <th align="left" scope="row" colspan="5">Choose A Backup Date To Restore Or Download</th>
348
+ </tr>
349
+ <tr>
350
+ <th align="left" scope="col">No.</th>
351
+ <th align="left" scope="col">Database File</th>
352
+ <th align="left" scope="col">Date/Time</th>
353
+ <th align="left" scope="col">Size</th>
354
+ <th align="left" scope="col">Select</th>
355
+ </tr>
356
+ <?php
357
+ if(!is_emtpy_folder($backup['path'])) {
358
+ if ($handle = opendir($backup['path'])) {
359
+ $database_files = array();
360
+ while (false !== ($file = readdir($handle))) {
361
+ if ($file != '.' && $file != '..') {
362
+ $database_files[] = $file;
363
+ }
364
+ }
365
+ closedir($handle);
366
+ for($i = (sizeof($database_files)-1); $i > -1; $i--) {
367
+ if($no%2 == 0) {
368
+ $style = 'style=\'background-color: #eee\'';
369
+ } else {
370
+ $style = 'style=\'background-color: none\'';
371
+ }
372
+ $no++;
373
+ $database_text = substr($database_files[$i], 13);
374
+ $date_text = date('l, jS F Y @ H:i', substr($database_files[$i], 0, 10));
375
+ $size_text = filesize($backup['path'].'/'.$database_files[$i]);
376
+ echo "<tr $style>\n<td>$no</td>";
377
+ echo "<td>$database_text</td>";
378
+ echo "<td>$date_text</td>";
379
+ echo '<td>'.format_size($size_text).'</td>';
380
+ echo "<td><input type=\"radio\" name=\"database_file\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
381
+ $totalsize += $size_text;
382
+ }
383
+ } else {
384
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
385
+ }
386
+ } else {
387
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
388
+ }
389
+ ?>
390
+ </tr>
391
+ <tr>
392
+ <th align="left" colspan="3"><?=$no?> Backup File(s)</th>
393
+ <th align="left"><?=format_size($totalsize)?></th>
394
+ <td>&nbsp;</td>
395
+ </tr>
396
+ <tr>
397
+ <td colspan="5" align="center"><input type="submit" name="do" value="Download" class="button">&nbsp;&nbsp;<input type="submit" class="button" name="do" value="Restore" onclick="return confirm('You Are About To Restore A Database.\nThis Action Is Not Reversible.\nAny Data Inserted After The Backup Date Will Be Gone.\n\n Choose \'Cancel\' to stop, \'OK\' to restore.')" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></td>
398
+ </tr>
399
+ </table>
400
+ </form>
401
+ </div>
402
+ <?php
403
+ break;
404
+ // Delete Database Backup Files
405
+ case 'delete':
406
+ $title = __('Delete Backup Database');
407
+ require("./admin-header.php");
408
+ ?>
409
+ <ul id="submenu">
410
+ <li><a href="database-manager.php"><?php _e('Manage Database'); ?></a></li>
411
+ <li><a href="database-manager.php?mode=backup"><?php _e('Backup DB'); ?></a></li>
412
+ <li><a href="database-manager.php?mode=optimize"><?php _e('Optimize DB'); ?></a></li>
413
+ <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>
414
+ <li><a href="database-manager.php?mode=delete" class="current"><?php _e('Delete Backup DB'); ?></a></li>
415
+ <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li>
416
+ </ul>
417
+ <!-- Delete Database Backup Files -->
418
+ <div class="wrap">
419
+ <h2>Delete Database Backup Files</h2>
420
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
421
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
422
+ <tr>
423
+ <th align="left" scope="row" colspan="5">Choose Database Backup Files To Delete</th>
424
+ </tr>
425
+ <tr>
426
+ <th align="left" scope="col">No.</th>
427
+ <th align="left" scope="col">Database File</th>
428
+ <th align="left" scope="col">Date/Time</th>
429
+ <th align="left" scope="col">Size</th>
430
+ <th align="left" scope="col">Select</th>
431
+ </tr>
432
+ <?php
433
+ if(!is_emtpy_folder($backup['path'])) {
434
+ if ($handle = opendir($backup['path'])) {
435
+ $database_files = array();
436
+ while (false !== ($file = readdir($handle))) {
437
+ if ($file != '.' && $file != '..') {
438
+ $database_files[] = $file;
439
+ }
440
+ }
441
+ closedir($handle);
442
+ for($i = (sizeof($database_files)-1); $i > -1; $i--) {
443
+ if($no%2 == 0) {
444
+ $style = 'style=\'background-color: #eee\'';
445
+ } else {
446
+ $style = 'style=\'background-color: none\'';
447
+ }
448
+ $no++;
449
+ $database_text = substr($database_files[$i], 13);
450
+ $date_text = date('l, jS F Y @ H:i', substr($database_files[$i], 0, 10));
451
+ $size_text = filesize($backup['path'].'/'.$database_files[$i]);
452
+ echo "<tr $style>\n<td>$no</td>";
453
+ echo "<td>$database_text</td>";
454
+ echo "<td>$date_text</td>";
455
+ echo '<td>'.format_size($size_text).'</td>';
456
+ echo "<td><input type=\"checkbox\" name=\"delete[]\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
457
+ $totalsize += $size_text;
458
+ }
459
+ } else {
460
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
461
+ }
462
+ } else {
463
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
464
+ }
465
+ ?>
466
+ </tr>
467
+ <tr>
468
+ <th align="left" colspan="3"><?=$no?> Backup File(s)</th>
469
+ <th align="left"><?=format_size($totalsize)?></th>
470
+ <td>&nbsp;</td>
471
+ </tr>
472
+ <tr>
473
+ <td colspan="5" align="center"><input type="submit" class="button" name="do" value="Delete" onclick="return confirm('You Are About To Delete The Selected Database Backup Files.\nThis Action Is Not Reversible.\n\n Choose \'Cancel\' to stop, \'OK\' to delete.')">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></td>
474
+ </tr>
475
+ </table>
476
+ </form>
477
+ </div>
478
+ <?php
479
+ break;
480
+ // Run SQL Query
481
+ case 'run':
482
+ $title = __('Run SQL Query');
483
+ require("./admin-header.php");
484
+ ?>
485
+ <ul id="submenu">
486
+ <li><a href="database-manager.php"><?php _e('Manage Database'); ?></a></li>
487
+ <li><a href="database-manager.php?mode=backup"><?php _e('Backup DB'); ?></a></li>
488
+ <li><a href="database-manager.php?mode=optimize"><?php _e('Optimize DB'); ?></a></li>
489
+ <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>
490
+ <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li>
491
+ <li class="last"><a href="database-manager.php?mode=run" class="current"><?php _e('Run SQL Query'); ?></a></li>
492
+ </ul>
493
+ <!-- Run SQL Query -->
494
+ <div class="wrap">
495
+ <h2>Run SQL Query</h2>
496
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
497
+ <p><b>Seperate Multiple Queries With A New Line</b><br /><font color="green">Use Only INSERT, UPDATE, REPLACE, DELETE and CREATE statements.</font></p>
498
+ <p align="center"><textarea cols="150" rows="30" name="sql_query"></textarea></p>
499
+ <p align="center"><input type="submit" name="do" Value="Run" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></p>
500
+ <p>1. CREATE statement will return an error, which is perfectly normal due to the database class. To confirm that your table has been created check the Manage Database page.<br />2. UPDATE statement may return an error sometimes due to the newly updated value being the same as the previous value.</font></p>
501
+ </form>
502
+ </div>
503
+ <?php
504
+ break;
505
+ // Database Information
506
+ default:
507
+ $title = __('Manage Database');
508
+ require("./admin-header.php");
509
+ // Get MYSQL Version
510
+ $sqlversion = $wpdb->get_var("SELECT VERSION() AS version");
511
+ ?>
512
+ <ul id="submenu">
513
+ <li><a href="database-manager.php" class="current"><?php _e('Manage Database'); ?></a></li>
514
+ <li><a href="database-manager.php?mode=backup"><?php _e('Backup DB'); ?></a></li>
515
+ <li><a href="database-manager.php?mode=optimize"><?php _e('Optimize DB'); ?></a></li>
516
+ <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>
517
+ <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li>
518
+ <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li>
519
+ </ul>
520
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
521
+ <!-- Database Information -->
522
+ <div class="wrap">
523
+ <h2>Database Information</h2>
524
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
525
+ <tr>
526
+ <th align="left" scope="col">Setting</th>
527
+ <th align="left" scope="col">Value</th>
528
+ </tr>
529
+ <tr>
530
+ <td>Database Host</td>
531
+ <td><?=DB_HOST?></td>
532
+ </tr>
533
+ <tr>
534
+ <td>Database Name</td>
535
+ <td><?=DB_NAME?></td>
536
+ </tr>
537
+ <tr>
538
+ <td>Database User</td>
539
+ <td><?=DB_USER?></td>
540
+ </tr>
541
+ <tr>
542
+ <td>Database Type</td>
543
+ <td>MYSQL</td>
544
+ </tr>
545
+ <tr>
546
+ <td>Database Version</td>
547
+ <td>v<?=$sqlversion?></td>
548
+ </tr>
549
+ </table>
550
+ </div>
551
+ <div class="wrap">
552
+ <h2>Tables Information</h2>
553
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
554
+ <tr>
555
+ <th align="left" scope="col">No.</th>
556
+ <th align="left" scope="col">Tables</th>
557
+ <th align="left" scope="col">Records</th>
558
+ <th align="left" scope="col">Data Usage</th>
559
+ <th align="left" scope="col">Index Usage</th>
560
+ <th align="left" scope="col">Overhead</th>
561
+ </tr>
562
+ <?php
563
+ // If MYSQL Version More Than 3.23, Get More Info
564
+ if($sqlversion >= '3.23') {
565
+ $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
566
+ foreach($tablesstatus as $tablestatus) {
567
+ if($no%2 == 0) {
568
+ $style = 'style=\'background-color: #eee\'';
569
+ } else {
570
+ $style = 'style=\'background-color: none\'';
571
+ }
572
+ $no++;
573
+ echo "<tr $style>\n<td>$no</td>\n";
574
+ echo "<td>$tablestatus->Name</td>\n";
575
+ echo "<td>".number_format($tablestatus->Rows)."</td>\n";
576
+ echo "<td>".format_size($tablestatus->Data_length)."</td>\n";
577
+ echo "<td>".format_size($tablestatus->Index_length)."</td>\n";
578
+ echo "<td>".format_size($tablestatus->Data_free)."</td>\n";
579
+ $row_usage += $tablestatus->Rows;
580
+ $data_usage += $tablestatus->Data_length;
581
+ $index_usage += $tablestatus->Index_length;
582
+ $overhead_usage += $tablestatus->Data_free;
583
+ }
584
+ echo "<tr><th align=\"left\" scope=\"row\">Total:</th>\n";
585
+ echo "<th align=\"left\" scope=\"row\">$no Tables</th>\n";
586
+ echo "<th align=\"left\" scope=\"row\">".number_format($row_usage)."</th>\n";
587
+ echo "<th align=\"left\" scope=\"row\">".format_size($data_usage)."</th>\n";
588
+ echo "<th align=\"left\" scope=\"row\">".format_size($index_usage)."</th>";
589
+ echo "<th align=\"left\" scope=\"row\">".format_size($overhead_usage)."</th></tr>";
590
+ } else {
591
+ echo '<tr><td colspan="6" align="center"><b>Could Not Show Table Status Due To Your MYSQL Version Is Lower Than 3.23.</b></td></tr>';
592
+ }
593
+ ?>
594
+ </table>
595
+ </div>
596
+ <?php
597
+ } // End switch($mode)
598
+
599
+ ### Require Admin Footer
600
+ require_once 'admin-footer.php';
601
+ ?>
dbmanager.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-DBManager
4
+ Plugin URI: http://www.lesterchan.net/portfolio/programming.php
5
+ Description: Manages your Wordpress database. Allows you to optimizee, backup, restore, delete backup database and run selected queries.
6
+ Version: 2.00
7
+ Author: GaMerZ
8
+ Author URI: http://www.lesterchan.net
9
+ */
10
+
11
+
12
+ /* Copyright 2005 Lester Chan (email : gamerz84@hotmail.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
+ */
28
+
29
+ ### Function: Poll Menu
30
+ add_action('admin_menu', 'dbmanager_menu');
31
+ function dbmanager_menu() {
32
+ if (function_exists('add_menu_page')) {
33
+ add_menu_page('Database', 'Database', 1, 'database-manager.php');
34
+ }
35
+ }
36
+ ?>
readme-install.txt ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Installation Instructions
2
+ --------------------------------------------------
3
+ // Create a folder called 'wp-backup-db' under your root Wordpress folder
4
+
5
+
6
+ // CHMOD 'wp-backup-db' to 777
7
+
8
+
9
+ // Open wp-admin folder
10
+
11
+ Put:
12
+ ------------------------------------------------------------------
13
+ database-manager.php
14
+ ------------------------------------------------------------------
15
+
16
+ // Open wp-content/plugins folder
17
+
18
+ Put:
19
+ ------------------------------------------------------------------
20
+ dbmanager.php
21
+ ------------------------------------------------------------------
22
+
23
+
24
+ // Activate dbmanager plugin
readme.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Database Manager For WordPress 2.0
2
+ --------------------------------------------------
3
+ Author -> Lester 'GaMerZ' Chan
4
+ Email -> lesterch@singnet.com.sg
5
+ Website -> http://www.lesterchan.net/
6
+ Demo -> N/A
7
+ Updated -> 1st January 2006
8
+ --------------------------------------------------
9
+
10
+
11
+ // Version 2.00 (01-01-2006)
12
+ - NEW: Compatible With WordPress 2.0
13
+ - NEW: GPL License Added