| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: WP-DBManager |
| 4 |
Plugin URI: http://lesterchan.net/portfolio/programming/php/ |
| 5 |
Description: Manages your Wordpress database. Allows you to optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. Supports automatic scheduling of backing up and optimizing of database. |
| 6 |
Version: 2.40 |
| 7 |
Author: Lester 'GaMerZ' Chan |
| 8 |
Author URI: http://lesterchan.net |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
/* |
| 13 |
Copyright 2008 Lester Chan (email : lesterchan@gmail.com) |
| 14 |
|
| 15 |
This program is free software; you can redistribute it and/or modify |
| 16 |
it under the terms of the GNU General Public License as published by |
| 17 |
the Free Software Foundation; either version 2 of the License, or |
| 18 |
(at your option) any later version. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with this program; if not, write to the Free Software |
| 27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 |
*/ |
| 29 |
|
| 30 |
|
| 31 |
### Create Text Domain For Translations |
| 32 |
add_action('init', 'dbmanager_textdomain'); |
| 33 |
function dbmanager_textdomain() { |
| 34 |
load_plugin_textdomain('wp-dbmanager', false, 'wp-dbmanager'); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
### Function: Database Manager Menu |
| 39 |
add_action('admin_menu', 'dbmanager_menu'); |
| 40 |
function dbmanager_menu() { |
| 41 |
if (function_exists('add_menu_page')) { |
| 42 |
add_menu_page(__('Database', 'wp-dbmanager'), __('Database', 'wp-dbmanager'), 'manage_database', 'wp-dbmanager/database-manager.php', '', plugins_url('wp-dbmanager/images/database.png')); |
| 43 |
} |
| 44 |
if (function_exists('add_submenu_page')) { |
| 45 |
add_submenu_page('wp-dbmanager/database-manager.php', __('Backup DB', 'wp-dbmanager'), __('Backup DB', 'wp-dbmanager'), 'manage_database', 'wp-dbmanager/database-backup.php'); |
| 46 |
add_submenu_page('wp-dbmanager/database-manager.php', __('Manage Backup DB', 'wp-dbmanager'), __('Manage Backup DB', 'wp-dbmanager'), 'manage_database', 'wp-dbmanager/database-manage.php'); |
| 47 |
add_submenu_page('wp-dbmanager/database-manager.php', __('Optimize DB', 'wp-dbmanager'), __('Optimize DB', 'wp-dbmanager'), 'manage_database', 'wp-dbmanager/database-optimize.php'); |
| 48 |
add_submenu_page('wp-dbmanager/database-manager.php', __('Repair DB', 'wp-dbmanager'), __('Repair DB', 'wp-dbmanager'), 'manage_database', 'wp-dbmanager/database-repair.php'); |
| 49 |
add_submenu_page('wp-dbmanager/database-manager.php', __('Empty/Drop Tables', 'wp-dbmanager'), __('Empty/Drop Tables', 'wp-dbmanager'), 'manage_database', 'wp-dbmanager/database-empty.php'); |
| 50 |
add_submenu_page('wp-dbmanager/database-manager.php', __('Run SQL Query', 'wp-dbmanager'), __('Run SQL Query', 'wp-dbmanager'), 'manage_database', 'wp-dbmanager/database-run.php'); |
| 51 |
add_submenu_page('wp-dbmanager/database-manager.php', __('DB Options', 'wp-dbmanager'), __('DB Options', 'wp-dbmanager'), 'manage_database', 'wp-dbmanager/wp-dbmanager.php', 'dbmanager_options'); |
| 52 |
add_submenu_page('wp-dbmanager/database-manager.php', __('Uninstall WP-DBManager', 'wp-dbmanager'), __('Uninstall WP-DBManager', 'wp-dbmanager'), 'manage_database', 'wp-dbmanager/database-uninstall.php'); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
### Function: Displays DBManager Header In WP-Admin |
| 58 |
add_action('admin_head-wp-dbmanager/database-manager.php', 'dbmanager_header_admin'); |
| 59 |
add_action('admin_head-wp-dbmanager/database-backup.php', 'dbmanager_header_admin'); |
| 60 |
add_action('admin_head-wp-dbmanager/database-manage.php', 'dbmanager_header_admin'); |
| 61 |
add_action('admin_head-wp-dbmanager/database-optimize.php', 'dbmanager_header_admin'); |
| 62 |
add_action('admin_head-wp-dbmanager/database-repair.php', 'dbmanager_header_admin'); |
| 63 |
add_action('admin_head-wp-dbmanager/database-empty.php', 'dbmanager_header_admin'); |
| 64 |
add_action('admin_head-wp-dbmanager/database-run.php', 'dbmanager_header_admin'); |
| 65 |
add_action('admin_head-database_page_wp-dbmanager/wp-dbmanager', 'dbmanager_header_admin'); |
| 66 |
add_action('admin_head-wp-dbmanager/database-uninstall.php', 'dbmanager_header_admin'); |
| 67 |
function dbmanager_header_admin() { |
| 68 |
wp_register_style('wp-dbmanager-admin', plugins_url('wp-dbmanager/database-admin-css.css'), false, '2.40', 'all'); |
| 69 |
echo "\n".'<!-- Start Of Script Generated By WP-DBManager 2.40 -->'."\n"; |
| 70 |
wp_print_styles('wp-dbmanager-admin'); |
| 71 |
echo '<!-- End Of Script Generated By WP-DBManager 2.40 -->'."\n"; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
### Funcion: Database Manager Cron |
| 76 |
add_filter('cron_schedules', 'cron_dbmanager_reccurences'); |
| 77 |
add_action('dbmanager_cron_backup', 'cron_dbmanager_backup'); |
| 78 |
add_action('dbmanager_cron_optimize', 'cron_dbmanager_optimize'); |
| 79 |
function cron_dbmanager_backup() { |
| 80 |
global $wpdb; |
| 81 |
$backup_options = get_option('dbmanager_options'); |
| 82 |
$backup_email = stripslashes($backup_options['backup_email']); |
| 83 |
if(intval($backup_options['backup_period']) > 0) { |
| 84 |
$current_date = mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', current_time('timestamp'))); |
| 85 |
$backup = array(); |
| 86 |
$backup['date'] = current_time('timestamp'); |
| 87 |
$backup['mysqldumppath'] = $backup_options['mysqldumppath']; |
| 88 |
$backup['mysqlpath'] = $backup_options['mysqlpath']; |
| 89 |
$backup['path'] = $backup_options['path']; |
| 90 |
$backup['command'] = ''; |
| 91 |
if(intval($backup_options['backup_gzip']) == 1) { |
| 92 |
$backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz'; |
| 93 |
$backup['filepath'] = $backup['path'].'/'.$backup['filename']; |
| 94 |
$backup['command'] = $backup['mysqldumppath'].' --host="'.DB_HOST.'" --user="'.DB_USER.'" --password="'.DB_PASSWORD.'" --add-drop-table --skip-lock-tables '.DB_NAME.' | gzip > '.$backup['filepath']; |
| 95 |
} else { |
| 96 |
$backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql'; |
| 97 |
$backup['filepath'] = $backup['path'].'/'.$backup['filename']; |
| 98 |
$backup['command'] = $backup['mysqldumppath'].' --host="'.DB_HOST.'" --user="'.DB_USER.'" --password="'.DB_PASSWORD.'" --add-drop-table --skip-lock-tables '.DB_NAME.' > '.$backup['filepath']; |
| 99 |
} |
| 100 |
execute_backup($backup['command']); |
| 101 |
if(!empty($backup_email)) { |
| 102 |
// Get And Read The Database Backup File |
| 103 |
$file_path = $backup['filepath']; |
| 104 |
$file_size = format_size(filesize($file_path)); |
| 105 |
$file_date = mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', substr($backup['filename'], 0, 10))); |
| 106 |
$file = fopen($file_path,'rb'); |
| 107 |
$file_data = fread($file,filesize($file_path)); |
| 108 |
fclose($file); |
| 109 |
$file_data = chunk_split(base64_encode($file_data)); |
| 110 |
// Create Mail To, Mail Subject And Mail Header |
| 111 |
$mail_subject = sprintf(__('%s Database Backup File For %s', 'wp-dbmanager'), get_bloginfo('name'), $file_date); |
| 112 |
$mail_header = 'From: '.get_bloginfo('name').' Administrator <'.get_option('admin_email').'>'; |
| 113 |
// MIME Boundary |
| 114 |
$random_time = md5(time()); |
| 115 |
$mime_boundary = "==WP-DBManager- $random_time"; |
| 116 |
// Create Mail Header And Mail Message |
| 117 |
$mail_header .= "\nMIME-Version: 1.0\n" . |
| 118 |
"Content-Type: multipart/mixed;\n" . |
| 119 |
" boundary=\"{$mime_boundary}\""; |
| 120 |
$mail_message = __('Website Name:', 'wp-dbmanager').' '.get_bloginfo('name')."\n". |
| 121 |
__('Website URL:', 'wp-dbmanager').' '.get_bloginfo('siteurl')."\n". |
| 122 |
__('Backup File Name:', 'wp-dbmanager').' '.$backup['filename']."\n". |
| 123 |
__('Backup File Date:', 'wp-dbmanager').' '.$file_date."\n". |
| 124 |
__('Backup File Size:', 'wp-dbmanager').' '.$file_size."\n\n". |
| 125 |
__('With Regards,', 'wp-dbmanager')."\n". |
| 126 |
get_bloginfo('name').' '. __('Administrator', 'wp-dbmanager')."\n". |
| 127 |
get_bloginfo('siteurl'); |
| 128 |
$mail_message = "This is a multi-part message in MIME format.\n\n" . |
| 129 |
"--{$mime_boundary}\n" . |
| 130 |
"Content-Type: text/plain; charset=\"utf-8\"\n" . |
| 131 |
"Content-Transfer-Encoding: 7bit\n\n".$mail_message."\n\n"; |
| 132 |
$mail_message .= "--{$mime_boundary}\n" . |
| 133 |
"Content-Type: application/octet-stream;\n" . |
| 134 |
" name=\"{$backup['filename']}\"\n" . |
| 135 |
"Content-Disposition: attachment;\n" . |
| 136 |
" filename=\"{$backup['filename']}\"\n" . |
| 137 |
"Content-Transfer-Encoding: base64\n\n" . |
| 138 |
$file_data."\n\n--{$mime_boundary}--\n"; |
| 139 |
mail($backup_email, $mail_subject, $mail_message, $mail_header); |
| 140 |
} |
| 141 |
} |
| 142 |
return; |
| 143 |
} |
| 144 |
function cron_dbmanager_optimize() { |
| 145 |
global $wpdb; |
| 146 |
$backup_options = get_option('dbmanager_options'); |
| 147 |
$optimize = intval($backup_options['optimize']); |
| 148 |
$optimize_period = intval($backup_options['optimize_period']); |
| 149 |
if($optimize_period > 0) { |
| 150 |
$optimize_tables = array(); |
| 151 |
$tables = $wpdb->get_col("SHOW TABLES"); |
| 152 |
foreach($tables as $table_name) { |
| 153 |
$optimize_tables[] = '`'.$table_name.'`'; |
| 154 |
} |
| 155 |
$wpdb->query('OPTIMIZE TABLE '.implode(',', $optimize_tables)); |
| 156 |
} |
| 157 |
return; |
| 158 |
} |
| 159 |
function cron_dbmanager_reccurences($schedules) { |
| 160 |
$backup_options = get_option('dbmanager_options'); |
| 161 |
$backup = intval($backup_options['backup'])*intval($backup_options['backup_period']); |
| 162 |
$optimize = intval($backup_options['optimize'])*intval($backup_options['optimize_period']); |
| 163 |
if($backup == 0) { |
| 164 |
$backup = 31536000; |
| 165 |
} |
| 166 |
if($optimize == 0) { |
| 167 |
$optimize = 31536000; |
| 168 |
} |
| 169 |
$schedules['dbmanager_backup'] = array('interval' => $backup, 'display' => __('WP-DBManager Backup Schedule', 'wp-dbmanager')); |
| 170 |
$schedules['dbmanager_optimize'] = array('interval' => $optimize, 'display' => __('WP-DBManager Optimize Schedule', 'wp-dbmanager')); |
| 171 |
return $schedules; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
### Function: Auto Detect MYSQL and MYSQL Dump Paths |
| 176 |
function detect_mysql() { |
| 177 |
global $wpdb; |
| 178 |
$paths = array('mysq' => '', 'mysqldump' => ''); |
| 179 |
if(substr(PHP_OS,0,3) == 'WIN') { |
| 180 |
$mysql_install = $wpdb->get_row("SHOW VARIABLES LIKE 'basedir'"); |
| 181 |
if($mysql_install) { |
| 182 |
$install_path = str_replace('\\', '/', $mysql_install->Value); |
| 183 |
$paths['mysql'] = $install_path.'bin/mysql.exe'; |
| 184 |
$paths['mysqldump'] = $install_path.'bin/mysqldump.exe'; |
| 185 |
} else { |
| 186 |
$paths['mysql'] = 'mysql.exe'; |
| 187 |
$paths['mysqldump'] = 'mysqldump.exe'; |
| 188 |
} |
| 189 |
} else { |
| 190 |
if(function_exists('exec')) { |
| 191 |
$paths['mysql'] = @exec('which mysql'); |
| 192 |
$paths['mysqldump'] = @exec('which mysqldump'); |
| 193 |
} else { |
| 194 |
$paths['mysql'] = 'mysql'; |
| 195 |
$paths['mysqldump'] = 'mysqldump'; |
| 196 |
} |
| 197 |
} |
| 198 |
return $paths; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
### Executes OS-Dependent mysqldump Command (By: Vlad Sharanhovich) |
| 203 |
function execute_backup($command) { |
| 204 |
$backup_options = get_option('dbmanager_options'); |
| 205 |
check_backup_files(); |
| 206 |
if(substr(PHP_OS, 0, 3) == 'WIN') { |
| 207 |
$writable_dir = $backup_options['path']; |
| 208 |
$tmpnam = $writable_dir.'/wp-dbmanager.bat'; |
| 209 |
$fp = fopen($tmpnam, 'w'); |
| 210 |
fwrite($fp, $command); |
| 211 |
fclose($fp); |
| 212 |
system($tmpnam.' > NUL', $error); |
| 213 |
unlink($tmpnam); |
| 214 |
} else { |
| 215 |
passthru($command, $error); |
| 216 |
} |
| 217 |
return $error; |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
### Function: Format Bytes Into KB/MB |
| 222 |
if(!function_exists('format_size')) { |
| 223 |
function format_size($rawSize) { |
| 224 |
if($rawSize / 1073741824 > 1) |
| 225 |
return number_format_i18n($rawSize/1048576, 1) . ' '.__('GiB', 'wp-dbmanager'); |
| 226 |
else if ($rawSize / 1048576 > 1) |
| 227 |
return number_format_i18n($rawSize/1048576, 1) . ' '.__('MiB', 'wp-dbmanager'); |
| 228 |
else if ($rawSize / 1024 > 1) |
| 229 |
return number_format_i18n($rawSize/1024, 1) . ' '.__('KiB', 'wp-dbmanager'); |
| 230 |
else |
| 231 |
return number_format_i18n($rawSize, 0) . ' '.__('bytes', 'wp-dbmanager'); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
### Function: Get File Extension |
| 237 |
if(!function_exists('file_ext')) { |
| 238 |
function file_ext($file_name) { |
| 239 |
return substr(strrchr($file_name, '.'), 1); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
### Function: Check Folder Whether There Is Any File Inside |
| 245 |
if(!function_exists('is_emtpy_folder')) { |
| 246 |
function is_emtpy_folder($folder){ |
| 247 |
if(is_dir($folder) ){ |
| 248 |
$handle = opendir($folder); |
| 249 |
while( (gettype( $name = readdir($handle)) != 'boolean')){ |
| 250 |
if($name != '.htaccess') { |
| 251 |
$name_array[] = $name; |
| 252 |
} |
| 253 |
} |
| 254 |
foreach($name_array as $temp) |
| 255 |
$folder_content .= $temp; |
| 256 |
|
| 257 |
if($folder_content == '...') |
| 258 |
return true; |
| 259 |
else |
| 260 |
return false; |
| 261 |
closedir($handle); |
| 262 |
} |
| 263 |
else |
| 264 |
return true; |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
### Function: Make Sure Maximum Number Of Database Backup Files Does Not Exceed |
| 270 |
function check_backup_files() { |
| 271 |
$backup_options = get_option('dbmanager_options'); |
| 272 |
$database_files = array(); |
| 273 |
if(!is_emtpy_folder($backup_options['path'])) { |
| 274 |
if ($handle = opendir($backup_options['path'])) { |
| 275 |
while (false !== ($file = readdir($handle))) { |
| 276 |
if ($file != '.' && $file != '..' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) { |
| 277 |
$database_files[] = $file; |
| 278 |
} |
| 279 |
} |
| 280 |
closedir($handle); |
| 281 |
sort($database_files); |
| 282 |
} |
| 283 |
} |
| 284 |
if(sizeof($database_files) >= $backup_options['max_backup']) { |
| 285 |
@unlink($backup_options['path'].'/'.$database_files[0]); |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
### Function: Database Manager Role |
| 291 |
add_action('activate_wp-dbmanager/wp-dbmanager.php', 'dbmanager_init'); |
| 292 |
function dbmanager_init() { |
| 293 |
global $wpdb; |
| 294 |
$auto = detect_mysql(); |
| 295 |
// Add Options |
| 296 |
$backup_options = array(); |
| 297 |
$backup_options['mysqldumppath'] = $auto['mysqldump']; |
| 298 |
$backup_options['mysqlpath'] = $auto['mysql']; |
| 299 |
$backup_options['path'] = str_replace('\\', '/', WP_CONTENT_DIR).'/backup-db'; |
| 300 |
$backup_options['max_backup'] = 10; |
| 301 |
$backup_options['backup'] = 1; |
| 302 |
$backup_options['backup_gzip'] = 0; |
| 303 |
$backup_options['backup_period'] = 604800; |
| 304 |
$backup_options['backup_email'] = get_option('admin_email'); |
| 305 |
$backup_options['optimize'] = 3; |
| 306 |
$backup_options['optimize_period'] = 86400; |
| 307 |
add_option('dbmanager_options', $backup_options, 'WP-DBManager Options'); |
| 308 |
|
| 309 |
// Create Backup Folder |
| 310 |
if(!is_dir(WP_CONTENT_DIR.'/backup-db')) { |
| 311 |
mkdir(WP_CONTENT_DIR.'/backup-db'); |
| 312 |
} |
| 313 |
|
| 314 |
// Set 'manage_database' Capabilities To Administrator |
| 315 |
$role = get_role('administrator'); |
| 316 |
if(!$role->has_cap('manage_database')) { |
| 317 |
$role->add_cap('manage_database'); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
### Function: Download Database |
| 323 |
add_action('init', 'download_database'); |
| 324 |
function download_database() { |
| 325 |
if($_POST['do'] == __('Download', 'wp-dbmanager') && !empty($_POST['database_file'])) { |
| 326 |
if(strpos($_SERVER['HTTP_REFERER'], admin_url('admin.php?page=wp-dbmanager/database-manage.php')) !== false) { |
| 327 |
$backup_options = get_option('dbmanager_options'); |
| 328 |
$file_path = $backup_options['path'].'/'.$_POST['database_file']; |
| 329 |
header("Pragma: public"); |
| 330 |
header("Expires: 0"); |
| 331 |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
| 332 |
header("Content-Type: application/force-download"); |
| 333 |
header("Content-Type: application/octet-stream"); |
| 334 |
header("Content-Type: application/download"); |
| 335 |
header("Content-Disposition: attachment; filename=".basename($file_path).";"); |
| 336 |
header("Content-Transfer-Encoding: binary"); |
| 337 |
header("Content-Length: ".filesize($file_path)); |
| 338 |
@readfile($file_path); |
| 339 |
} |
| 340 |
exit(); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
### Function: Database Options |
| 346 |
function dbmanager_options() { |
| 347 |
global $wpdb; |
| 348 |
$text = ''; |
| 349 |
$backup_options = array(); |
| 350 |
$backup_options = get_option('dbmanager_options'); |
| 351 |
if($_POST['Submit']) { |
| 352 |
$backup_options['mysqldumppath'] = trim($_POST['db_mysqldumppath']); |
| 353 |
$backup_options['mysqlpath'] = trim($_POST['db_mysqlpath']); |
| 354 |
$backup_options['path'] = trim($_POST['db_path']); |
| 355 |
$backup_options['max_backup'] = intval($_POST['db_max_backup']); |
| 356 |
$backup_options['backup'] = intval($_POST['db_backup']); |
| 357 |
$backup_options['backup_gzip'] = intval($_POST['db_backup_gzip']); |
| 358 |
$backup_options['backup_period'] = intval($_POST['db_backup_period']); |
| 359 |
$backup_options['backup_email'] = trim(addslashes($_POST['db_backup_email'])); |
| 360 |
$backup_options['optimize'] = intval($_POST['db_optimize']); |
| 361 |
$backup_options['optimize_period'] = intval($_POST['db_optimize_period']); |
| 362 |
$update_db_options = update_option('dbmanager_options', $backup_options); |
| 363 |
if($update_db_options) { |
| 364 |
$text = '<font color="green">'.__('Database Options Updated', 'wp-dbmanager').'</font>'; |
| 365 |
} |
| 366 |
if(empty($text)) { |
| 367 |
$text = '<font color="red">'.__('No Database Option Updated', 'wp-dbmanager').'</font>'; |
| 368 |
} |
| 369 |
wp_clear_scheduled_hook('dbmanager_cron_backup'); |
| 370 |
if($backup_options['backup_period'] > 0) { |
| 371 |
if (!wp_next_scheduled('dbmanager_cron_backup')) { |
| 372 |
wp_schedule_event(time(), 'dbmanager_backup', 'dbmanager_cron_backup'); |
| 373 |
} |
| 374 |
} |
| 375 |
wp_clear_scheduled_hook('dbmanager_cron_optimize'); |
| 376 |
if($backup_options['optimize_period'] > 0) { |
| 377 |
if (!wp_next_scheduled('dbmanager_cron_optimize')) { |
| 378 |
wp_schedule_event(time(), 'dbmanager_optimize', 'dbmanager_cron_optimize'); |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
$path = detect_mysql(); |
| 383 |
?> |
| 384 |
<script type="text/javascript"> |
| 385 |
/* <![CDATA[*/ |
| 386 |
function mysqlpath() { |
| 387 |
document.getElementById('db_mysqlpath').value = '<?php echo $path['mysql']; ?>'; |
| 388 |
} |
| 389 |
function mysqldumppath() { |
| 390 |
document.getElementById('db_mysqldumppath').value = '<?php echo $path['mysqldump']; ?>'; |
| 391 |
} |
| 392 |
/* ]]> */ |
| 393 |
</script> |
| 394 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> |
| 395 |
<!-- Database Options --> |
| 396 |
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"> |
| 397 |
<div class="wrap"> |
| 398 |
<div id="icon-wp-dbmanager" class="icon32"><br /></div> |
| 399 |
<h2><?php _e('Database Options', 'wp-dbmanager'); ?></h2> |
| 400 |
<h3><?php _e('Paths', 'wp-dbmanager'); ?></h3> |
| 401 |
<table class="form-table"> |
| 402 |
<tr> |
| 403 |
<td width="20%" valign="top"><strong><?php _e('Path To mysqldump:', 'wp-dbmanager'); ?></strong></td> |
| 404 |
<td width="80%"> |
| 405 |
<input type="text" id="db_mysqldumppath" name="db_mysqldumppath" size="60" maxlength="100" value="<?php echo stripslashes($backup_options['mysqldumppath']); ?>" dir="ltr" /> <input type="button" value="<?php _e('Auto Detect', 'wp-dbmanager'); ?>" onclick="mysqldumppath();" /> |
| 406 |
<p><?php _e('The absolute path to mysqldump without trailing slash. If unsure, please email your server administrator about this.', 'wp-dbmanager'); ?></p> |
| 407 |
</td> |
| 408 |
</tr> |
| 409 |
<tr> |
| 410 |
<td valign="top"><strong><?php _e('Path To mysql:', 'wp-dbmanager'); ?></strong></td> |
| 411 |
<td> |
| 412 |
<input type="text" id="db_mysqlpath" name="db_mysqlpath" size="60" maxlength="100" value="<?php echo stripslashes($backup_options['mysqlpath']); ?>" dir="ltr" /> <input type="button" value="<?php _e('Auto Detect', 'wp-dbmanager'); ?>" onclick="mysqlpath();" /> |
| 413 |
<p><?php _e('The absolute path to mysql without trailing slash. If unsure, please email your server administrator about this.', 'wp-dbmanager'); ?></p> |
| 414 |
</td> |
| 415 |
</tr> |
| 416 |
<tr> |
| 417 |
<td valign="top"><strong><?php _e('Path To Backup:', 'wp-dbmanager'); ?></strong></td> |
| 418 |
<td> |
| 419 |
<input type="text" name="db_path" size="60" maxlength="100" value="<?php echo stripslashes($backup_options['path']); ?>" dir="ltr" /> |
| 420 |
<p><?php _e('The absolute path to your database backup folder without trailing slash. Make sure the folder is writable.', 'wp-dbmanager'); ?></p> |
| 421 |
</td> |
| 422 |
</tr> |
| 423 |
<tr> |
| 424 |
<td valign="top"><strong><?php _e('Maximum Backup Files:', 'wp-dbmanager'); ?></strong></td> |
| 425 |
<td> |
| 426 |
<input type="text" name="db_max_backup" size="5" maxlength="5" value="<?php echo stripslashes($backup_options['max_backup']); ?>" /> |
| 427 |
<p><?php _e('The maximum number of database backup files that is allowed in the backup folder as stated above. The oldest database backup file is always deleted in order to maintain this value. This is to prevent the backup folder from getting too large.', 'wp-dbmanager'); ?></p> |
| 428 |
</td> |
| 429 |
</tr> |
| 430 |
</table> |
| 431 |
|
| 432 |
<h3><?php _e('Note', 'wp-dbmanager'); ?></h3> |
| 433 |
<table class="form-table"> |
| 434 |
<tr> |
| 435 |
<td> |
| 436 |
<strong><?php _e('Windows Server', 'wp-dbmanager'); ?></strong><br /> |
| 437 |
<?php _e('For mysqldump path, you can try \'<strong>mysqldump.exe</strong>\'.', 'wp-dbmanager'); ?><br /> |
| 438 |
<?php _e('For mysql path, you can try \'<strong>mysql.exe</strong>\'.', 'wp-dbmanager'); ?> |
| 439 |
</td> |
| 440 |
</tr> |
| 441 |
<tr> |
| 442 |
<td> |
| 443 |
<strong><?php _e('Linux Server', 'wp-dbmanager'); ?></strong><br /> |
| 444 |
<?php _e('For mysqldump path, normally is just \'<strong>mysqldump</strong>\'.', 'wp-dbmanager'); ?><br /> |
| 445 |
<?php _e('For mysql path, normally is just \'<strong>mysql</strong>\'.', 'wp-dbmanager'); ?> |
| 446 |
</td> |
| 447 |
</tr> |
| 448 |
<tr> |
| 449 |
<td> |
| 450 |
<strong><?php _e('Note', 'wp-dbmanager'); ?></strong><br /> |
| 451 |
<?php _e('The \'Auto Detect\' function does not work for some servers. If it does not work for you, please contact your server administrator for the MYSQL and MYSQL DUMP paths.', 'wp-dbmanager'); ?> |
| 452 |
</td> |
| 453 |
</tr> |
| 454 |
</table> |
| 455 |
|
| 456 |
<h3><?php _e('Automatic Scheduling', 'wp-dbmanager'); ?></h3> |
| 457 |
<table class="form-table"> |
| 458 |
<tr> |
| 459 |
<td valign="top"><strong><?php _e('Automatic Backing Up Of DB:', 'wp-dbmanager'); ?></strong></td> |
| 460 |
<td> |
| 461 |
<?php |
| 462 |
_e('Next backup date: ', 'wp-dbmanager'); |
| 463 |
if(wp_next_scheduled('dbmanager_cron_backup')) { |
| 464 |
echo '<strong>'.mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', (wp_next_scheduled('dbmanager_cron_backup') + (get_option('gmt_offset') * 3600)))).'</strong>'; |
| 465 |
} else { |
| 466 |
_e('N/A', 'wp-dbmanager'); |
| 467 |
} |
| 468 |
?> |
| 469 |
<p> |
| 470 |
<?php _e('Every', 'wp-dbmanager'); ?> <input type="text" name="db_backup" size="3" maxlength="5" value="<?php echo intval($backup_options['backup']); ?>" /> |
| 471 |
<select name="db_backup_period" size="1"> |
| 472 |
<option value="0"<?php selected('0', $backup_options['backup_period']); ?>><?php _e('Disable', 'wp-dbmanager'); ?></option> |
| 473 |
<option value="60"<?php selected('60', $backup_options['backup_period']); ?>><?php _e('Minutes(s)', 'wp-dbmanager'); ?></option> |
| 474 |
<option value="3600"<?php selected('3600', $backup_options['backup_period']); ?>><?php _e('Hour(s)', 'wp-dbmanager'); ?></option> |
| 475 |
<option value="86400"<?php selected('86400', $backup_options['backup_period']); ?>><?php _e('Day(s)', 'wp-dbmanager'); ?></option> |
| 476 |
<option value="604800"<?php selected('604800', $backup_options['backup_period']); ?>><?php _e('Week(s)', 'wp-dbmanager'); ?></option> |
| 477 |
<option value="18144000"<?php selected('18144000', $backup_options['backup_period']); ?>><?php _e('Month(s)', 'wp-dbmanager'); ?></option> |
| 478 |
</select> |
| 479 |
<?php _e('Gzip', 'wp-dbmanager'); ?> |
| 480 |
<select name="db_backup_gzip" size="1"> |
| 481 |
<option value="0"<?php selected('0', $backup_options['backup_gzip']); ?>><?php _e('No', 'wp-dbmanager'); ?></option> |
| 482 |
<option value="1"<?php selected('1', $backup_options['backup_gzip']); ?>><?php _e('Yes', 'wp-dbmanager'); ?></option> |
| 483 |
</select> |
| 484 |
</p> |
| 485 |
<p><?php _e('E-mail backup to:', 'wp-dbmanager'); ?> <input type="text" name="db_backup_email" size="30" maxlength="50" value="<?php echo stripslashes($backup_options['backup_email']) ?>" dir="ltr" /> <?php _e('(Leave blank to disable this feature)', 'wp-dbmanager'); ?></p> |
| 486 |
<p><?php _e('WP-DBManager can automatically backup your database after a certain period.', 'wp-dbmanager'); ?></p> |
| 487 |
</td> |
| 488 |
</tr> |
| 489 |
<tr> |
| 490 |
<td valign="top"><strong><?php _e('Automatic Optimizing Of DB:', 'wp-dbmanager'); ?></strong></td> |
| 491 |
<td> |
| 492 |
<?php |
| 493 |
_e('Next optimize date: ', 'wp-dbmanager'); |
| 494 |
if(wp_next_scheduled('dbmanager_cron_optimize')) { |
| 495 |
echo '<strong>'.mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', (wp_next_scheduled('dbmanager_cron_optimize') + (get_option('gmt_offset') * 3600)))).'</strong>'; |
| 496 |
} else { |
| 497 |
_e('N/A', 'wp-dbmanager'); |
| 498 |
} |
| 499 |
?> |
| 500 |
<p> |
| 501 |
<?php _e('Every', 'wp-dbmanager'); ?> <input type="text" name="db_optimize" size="3" maxlength="5" value="<?php echo intval($backup_options['optimize']); ?>" /> |
| 502 |
<select name="db_optimize_period" size="1"> |
| 503 |
<option value="0"<?php selected('0', $backup_options['optimize_period']); ?>><?php _e('Disable', 'wp-dbmanager'); ?></option> |
| 504 |
<option value="60"<?php selected('60', $backup_options['optimize_period']); ?>><?php _e('Minutes(s)', 'wp-dbmanager'); ?></option> |
| 505 |
<option value="3600"<?php selected('3600', $backup_options['optimize_period']); ?>><?php _e('Hour(s)', 'wp-dbmanager'); ?></option> |
| 506 |
<option value="86400"<?php selected('86400', $backup_options['optimize_period']); ?>><?php _e('Day(s)', 'wp-dbmanager'); ?></option> |
| 507 |
<option value="604800"<?php selected('604800', $backup_options['optimize_period']); ?>><?php _e('Week(s)', 'wp-dbmanager'); ?></option> |
| 508 |
<option value="18144000"<?php selected('18144000', $backup_options['optimize_period']); ?>><?php _e('Month(s)', 'wp-dbmanager'); ?></option> |
| 509 |
</select> |
| 510 |
</p> |
| 511 |
<p><?php _e('WP-DBManager can automatically optimize your database after a certain period.', 'wp-dbmanager'); ?></p> |
| 512 |
</td> |
| 513 |
</tr> |
| 514 |
</table> |
| 515 |
<p class="submit"> |
| 516 |
<input type="submit" name="Submit" class="button" value="<?php _e('Save Changes', 'wp-dbmanager'); ?>" /> |
| 517 |
</p> |
| 518 |
</div> |
| 519 |
</form> |
| 520 |
<?php |
| 521 |
} |
| 522 |
?> |