WP-DBManager - Version 2.01

Version Description

Download this release

Release Info

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

Version 2.01

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