| 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.02 |
| 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', 'dbmanager/database-manager.php'); |
| 35 |
} |
| 36 |
if (function_exists('add_submenu_page')) { |
| 37 |
add_submenu_page('dbmanager/database-manager.php', __('Backup DB'), __('Backup DB'), 'manage_database', 'dbmanager/database-backup.php'); |
| 38 |
add_submenu_page('dbmanager/database-manager.php', __('Manage Backup DB'), __('Manage Backup DB'), 'manage_database', 'dbmanager/database-manage.php'); |
| 39 |
add_submenu_page('dbmanager/database-manager.php', __('Optimize DB'), __('Optimize DB'), 'manage_database', 'dbmanager/database-optimize.php'); |
| 40 |
add_submenu_page('dbmanager/database-manager.php', __('Empty/Drop Tables'), __('Empty/Drop Tables'), 'manage_database', 'dbmanager/database-empty.php'); |
| 41 |
add_submenu_page('dbmanager/database-manager.php', __('Run SQL Query'), __('Run SQL Query'), 'manage_database', 'dbmanager/database-run.php'); |
| 42 |
add_submenu_page('dbmanager/database-manager.php', __('DB Options'), __('DB Options'), 'manage_database', 'dbmanager/dbmanager.php', 'dbmanager_options'); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
### Function: Database Manager Role |
| 48 |
add_action('activate_dbmanager/dbmanager.php', 'dbmanager_init'); |
| 49 |
function dbmanager_init() { |
| 50 |
// Add Options |
| 51 |
$backup_options = array(); |
| 52 |
$backup_options['mysqldumppath'] = 'mysqldump'; |
| 53 |
$backup_options['mysqlpath'] = 'mysql'; |
| 54 |
$backup_options['path'] = ABSPATH.'wp-content/backup-db'; |
| 55 |
add_option('dbmanager_options', $backup_options, 'WP-DBManager Options'); |
| 56 |
|
| 57 |
// Create Backup Folder |
| 58 |
if(!is_dir(ABSPATH.'/wp-content/backup-db')) { |
| 59 |
mkdir(ABSPATH.'/wp-content/backup-db'); |
| 60 |
} |
| 61 |
|
| 62 |
// Set 'manage_database' Capabilities To Administrator |
| 63 |
$role = get_role('administrator'); |
| 64 |
if(!$role->has_cap('manage_database')) { |
| 65 |
$role->add_cap('manage_database'); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
### Function: Database Options |
| 71 |
function dbmanager_options() { |
| 72 |
global $wpdb; |
| 73 |
$text = ''; |
| 74 |
$backup_options = array(); |
| 75 |
$backup_options = get_settings('dbmanager_options'); |
| 76 |
if($_POST['Submit']) { |
| 77 |
$backup_options['mysqldumppath'] = trim($_POST['db_mysqldumppath']); |
| 78 |
$backup_options['mysqlpath'] = trim($_POST['db_mysqlpath']); |
| 79 |
$backup_options['path'] = trim($_POST['db_path']); |
| 80 |
$update_db_options = update_option('dbmanager_options', $backup_options); |
| 81 |
if($update_db_options) { |
| 82 |
$text = '<font color="green">'.__('DB Options Updated').'</font>'; |
| 83 |
} |
| 84 |
if(empty($text)) { |
| 85 |
$text = '<font color="red">'.__('No DB Option Updated').'</font>'; |
| 86 |
} |
| 87 |
} |
| 88 |
?> |
| 89 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> |
| 90 |
<!-- Database Options --> |
| 91 |
<div class="wrap"> |
| 92 |
<h2>Database Options</h2> |
| 93 |
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"> |
| 94 |
<table width="100%" cellspacing="3" cellpadding="3" border="0"> |
| 95 |
<tr> |
| 96 |
<td valign="top"><b>Path To mysqldump:</b></td> |
| 97 |
<td> |
| 98 |
<input type="text" name="db_mysqldumppath" size="100" maxlength="100" value="<?php echo $backup_options['mysqldumppath']; ?>" /><br />The absolute path to mysqldump without trailing slash. If unsure, please email your server administrator about this. |
| 99 |
</td> |
| 100 |
</tr> |
| 101 |
<tr> |
| 102 |
<td valign="top"><b>Path To mysql:</b></td> |
| 103 |
<td> |
| 104 |
<input type="text" name="db_mysqlpath" size="100" maxlength="100" value="<?php echo $backup_options['mysqlpath']; ?>" /><br />The absolute path to mysql without trailing slash. If unsure, please email your server administrator about this. |
| 105 |
</td> |
| 106 |
</tr> |
| 107 |
<tr> |
| 108 |
<td valign="top"><b>Path To Backup:</b></td> |
| 109 |
<td> |
| 110 |
<input type="text" name="db_path" size="100" maxlength="100" value="<?php echo $backup_options['path']; ?>" /> |
| 111 |
<br />The absolute path to your database backup folder without trailing slash. Make sure the folder is writable. |
| 112 |
</td> |
| 113 |
</tr> |
| 114 |
<tr> |
| 115 |
<td width="100%" colspan="2"> |
| 116 |
<p class="submit"><input type="submit" name="Submit" value="<?php _e('Update Options'); ?> »" /></p> |
| 117 |
</td> |
| 118 |
</tr> |
| 119 |
</table> |
| 120 |
</form> |
| 121 |
<p> |
| 122 |
<b>Windows Server</b><br /> |
| 123 |
For mysqldump path, you can try '<b>mysqldump.exe</b>'.<br /> |
| 124 |
For mysql path, you can try '<b>mysql.exe</b>'.<br /> |
| 125 |
<br /> |
| 126 |
<b>Linux Server</b><br /> |
| 127 |
For mysqldump path, normally is just '<b>mysqldump</b>'.<br /> |
| 128 |
For mysql path, normally is just '<b>mysql</b>'.<br /> |
| 129 |
</p> |
| 130 |
</div> |
| 131 |
<?php |
| 132 |
} |
| 133 |
?> |