Ticket #2509: wp-db-backup.diff
File wp-db-backup.diff, 20.3 KB (added by , 19 years ago) |
---|
-
E:/PHP/WordPress/SVN/wp-content/plugins/wp-db-backup.php
17 17 // CHANGE THIS IF YOU WANT TO USE A 18 18 // DIFFERENT BACKUP LOCATION 19 19 20 load_plugin_textdomain('wp-db-backup'); 21 20 22 $rand = substr( md5( md5( DB_PASSWORD ) ), -5 ); 21 23 22 24 define('WP_BACKUP_DIR', 'wp-content/backup-' . $rand); … … 64 66 global $user_level; 65 67 get_currentuserinfo(); 66 68 67 if ($user_level < 9) die(__('Need higher user level.' ));69 if ($user_level < 9) die(__('Need higher user level.', 'wp-db-backup')); 68 70 69 71 if (isset($_GET['backup'])) { 70 72 $via = isset($_GET['via']) ? $_GET['via'] : 'http'; … … 85 87 } 86 88 } 87 89 echo ' 88 alert("' . __('Backup Complete!' ) . '");90 alert("' . __('Backup Complete!', 'wp-db-backup') . '"); 89 91 </script> 90 92 '; 91 93 break; … … 111 113 112 114 echo "<div class='wrap'>"; 113 115 //echo "<pre>" . print_r($_POST, 1) . "</pre>"; 114 echo '<h2>' . __('Backup' ) . '</h2>115 <fieldset class="options"><legend>' . __('Progress' ) . '</legend>116 echo '<h2>' . __('Backup', 'wp-db-backup') . '</h2> 117 <fieldset class="options"><legend>' . __('Progress', 'wp-db-backup') . '</legend> 116 118 <p><strong>' . 117 __('DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:' ).119 __('DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:', 'wp-db-backup'). 118 120 '</strong></p> 119 121 <ol> 120 <li>'.__('Close this browser' ).'</li>121 <li>'.__('Reload this page' ).'</li>122 <li>'.__('Click the Stop or Back buttons in your browser' ).'</li>122 <li>'.__('Close this browser', 'wp-db-backup').'</li> 123 <li>'.__('Reload this page', 'wp-db-backup').'</li> 124 <li>'.__('Click the Stop or Back buttons in your browser', 'wp-db-backup').'</li> 123 125 </ol> 124 <p><strong>' . __('Progress:' ) . '</strong></p>126 <p><strong>' . __('Progress:', 'wp-db-backup') . '</strong></p> 125 127 <div id="meterbox" style="height:11px;width:80%;padding:3px;border:1px solid #659fff;"><div id="meter" style="height:11px;background-color:#659fff;width:0%;text-align:center;font-size:6pt;"> </div></div> 126 128 <div id="progress_message"></div> 127 129 <div id="errors"></div> … … 164 166 switch($_POST['deliver']) { 165 167 case 'http': 166 168 echo ' 167 setProgress("' . sprintf(__("Backup complete, preparing <a href=\\\"%s\\\">backup</a> for download..." ), $download_uri) . '");169 setProgress("' . sprintf(__("Backup complete, preparing <a href=\\\"%s\\\">backup</a> for download...", 'wp-db-backup'), $download_uri) . '"); 168 170 fram.src = "' . $download_uri . '"; 169 171 '; 170 172 break; 171 173 case 'smtp': 172 174 echo ' 173 setProgress("' . sprintf(__("Backup complete, sending <a href=\\\"%s\\\">backup</a> via email..." ), $download_uri) . '");175 setProgress("' . sprintf(__("Backup complete, sending <a href=\\\"%s\\\">backup</a> via email...", 'wp-db-backup'), $download_uri) . '"); 174 176 fram.src = "' . $download_uri . '&via=email&recipient=' . $_POST['backup_recipient'] . '"; 175 177 '; 176 178 break; 177 179 default: 178 180 echo ' 179 setProgress("' . sprintf(__("Backup complete, download <a href=\\\"%s\\\">here</a>." ), $download_uri) . '");181 setProgress("' . sprintf(__("Backup complete, download <a href=\\\"%s\\\">here</a>.", 'wp-db-backup'), $download_uri) . '"); 180 182 '; 181 183 } 182 184 … … 228 230 echo "$table:$segment:$filename"; 229 231 230 232 if($table == '') { 231 $msg = __('Creating backup file...' );233 $msg = __('Creating backup file...', 'wp-db-backup'); 232 234 } else { 233 235 if($segment == -1) { 234 $msg = sprintf(__('Finished backing up table \\"%s\\".' ), $table);236 $msg = sprintf(__('Finished backing up table \\"%s\\".', 'wp-db-backup'), $table); 235 237 } else { 236 $msg = sprintf(__('Backing up table \\"%s\\"...' ), $table);238 $msg = sprintf(__('Backing up table \\"%s\\"...', 'wp-db-backup'), $table); 237 239 } 238 240 } 239 241 … … 245 247 if (is_writable(ABSPATH . $this->backup_dir)) { 246 248 $this->fp = $this->open(ABSPATH . $this->backup_dir . $filename, 'a'); 247 249 if(!$this->fp) { 248 $this->backup_error(__('Could not open the backup file for writing!' ));249 $this->fatal_error = __('The backup file could not be saved. Please check the permissions for writing to your backup directory and try again.' );250 $this->backup_error(__('Could not open the backup file for writing!', 'wp-db-backup')); 251 $this->fatal_error = __('The backup file could not be saved. Please check the permissions for writing to your backup directory and try again.', 'wp-db-backup'); 250 252 } 251 253 else { 252 254 if($table == '') { … … 271 273 } 272 274 } 273 275 } else { 274 $this->backup_error(__('The backup directory is not writeable!' ));275 $this->fatal_error = __('The backup directory is not writeable! Please check the permissions for writing to your backup directory and try again.' );276 $this->backup_error(__('The backup directory is not writeable!', 'wp-db-backup')); 277 $this->fatal_error = __('The backup directory is not writeable! Please check the permissions for writing to your backup directory and try again.', 'wp-db-backup'); 276 278 } 277 279 278 280 if($this->fp) $this->close($this->fp); … … 321 323 322 324 /////////////////////////////// 323 325 function admin_menu() { 324 add_management_page(__('Backup' ), __('Backup'), 9, basename(__FILE__), array(&$this, 'backup_menu'));326 add_management_page(__('Backup', 'wp-db-backup'), __('Backup', 'wp-db-backup'), 9, basename(__FILE__), array(&$this, 'backup_menu')); 325 327 } 326 328 327 329 function fragment_menu() { 328 add_management_page(__('Backup' ), __('Backup'), 9, basename(__FILE__), array(&$this, 'build_backup_script'));330 add_management_page(__('Backup', 'wp-db-backup'), __('Backup', 'wp-db-backup'), 9, basename(__FILE__), array(&$this, 'build_backup_script')); 329 331 } 330 332 331 333 ///////////////////////////////////////////////////////// … … 392 394 function stow($query_line) { 393 395 if ($this->gzip()) { 394 396 if(@gzwrite($this->fp, $query_line) === FALSE) { 395 backup_error(__('There was an error writing a line to the backup script:' ));397 backup_error(__('There was an error writing a line to the backup script:', 'wp-db-backup')); 396 398 backup_error(' ' . $query_line); 397 399 } 398 400 } else { 399 401 if(@fwrite($this->fp, $query_line) === FALSE) { 400 backup_error(__('There was an error writing a line to the backup script:' ));402 backup_error(__('There was an error writing a line to the backup script:', 'wp-db-backup')); 401 403 backup_error(' ' . $query_line); 402 404 } 403 405 } … … 407 409 if(count($this->backup_errors) < 20) { 408 410 $this->backup_errors[] = $err; 409 411 } elseif(count($this->backup_errors) == 20) { 410 $this->backup_errors[] = __('Subsequent errors have been omitted from this log.' );412 $this->backup_errors[] = __('Subsequent errors have been omitted from this log.', 'wp-db-backup'); 411 413 } 412 414 } 413 415 … … 426 428 427 429 $table_structure = $wpdb->get_results("DESCRIBE $table"); 428 430 if (! $table_structure) { 429 backup_errors(__('Error getting table details' ) . ": $table");431 backup_errors(__('Error getting table details', 'wp-db-backup') . ": $table"); 430 432 return FALSE; 431 433 } 432 434 … … 451 453 452 454 $create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N); 453 455 if (FALSE === $create_table) { 454 $this->backup_error(sprintf(__("Error with SHOW CREATE TABLE for %s." ), $table));456 $this->backup_error(sprintf(__("Error with SHOW CREATE TABLE for %s.", 'wp-db-backup'), $table)); 455 457 $this->stow("#\n# Error with SHOW CREATE TABLE for $table!\n#\n"); 456 458 } 457 459 $this->stow($create_table[0][1] . ' ;'); 458 460 459 461 if (FALSE === $table_structure) { 460 $this->backup_error(sprintf(__("Error getting table structure of %s" ), $table));462 $this->backup_error(sprintf(__("Error getting table structure of %s", 'wp-db-backup'), $table)); 461 463 $this->stow("#\n# Error getting table structure of $table!\n#\n"); 462 464 } 463 465 … … 566 568 if (is_writable(ABSPATH . $this->backup_dir)) { 567 569 $this->fp = $this->open(ABSPATH . $this->backup_dir . $wp_backup_filename); 568 570 if(!$this->fp) { 569 $this->backup_error(__('Could not open the backup file for writing!' ));571 $this->backup_error(__('Could not open the backup file for writing!', 'wp-db-backup')); 570 572 return false; 571 573 } 572 574 } else { 573 $this->backup_error(__('The backup directory is not writeable!' ));575 $this->backup_error(__('The backup directory is not writeable!', 'wp-db-backup')); 574 576 return false; 575 577 } 576 578 … … 614 616 $diskfile = ABSPATH . $this->backup_dir . $filename; 615 617 if ('http' == $delivery) { 616 618 if (! file_exists($diskfile)) { 617 $msg = sprintf(__('File not found:%s' ), "<br /><strong>$filename</strong><br />");619 $msg = sprintf(__('File not found:%s', 'wp-db-backup'), "<br /><strong>$filename</strong><br />"); 618 620 $this_basename = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', __FILE__); 619 $msg .= '<br /><a href="' . get_settings('siteurl') . "/wp-admin/edit.php?page={$this_basename}" . '">' . __('Return to Backup' );621 $msg .= '<br /><a href="' . get_settings('siteurl') . "/wp-admin/edit.php?page={$this_basename}" . '">' . __('Return to Backup', 'wp-db-backup'); 620 622 die($msg); 621 623 } 622 624 header('Content-Description: File Transfer'); … … 641 643 $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n"; 642 644 $headers .= 'From: ' . get_settings('admin_email') . "\n"; 643 645 644 $message = sprintf(__("Attached to this email is\n %1s\n Size:%2s kilobytes\n" ), $filename, round(filesize($diskfile)/1024));646 $message = sprintf(__("Attached to this email is\n %1s\n Size:%2s kilobytes\n", 'wp-db-backup'), $filename, round(filesize($diskfile)/1024)); 645 647 // Add a multipart boundary above the plain message 646 648 $message = "This is a multi-part message in MIME format.\n\n" . 647 649 "--{$boundary}\n" . … … 660 662 "--{$boundary}--\n"; 661 663 662 664 if (function_exists('wp_mail')) { 663 wp_mail ($recipient, get_bloginfo('name') . ' ' . __('Database Backup' ), $message, $headers);665 wp_mail ($recipient, get_bloginfo('name') . ' ' . __('Database Backup', 'wp-db-backup'), $message, $headers); 664 666 } else { 665 mail ($recipient, get_bloginfo('name') . ' ' . __('Database Backup' ), $message, $headers);667 mail ($recipient, get_bloginfo('name') . ' ' . __('Database Backup', 'wp-db-backup'), $message, $headers); 666 668 } 667 669 668 670 unlink($diskfile); … … 678 680 679 681 // did we just do a backup? If so, let's report the status 680 682 if ( $this->backup_complete ) { 681 $feedback = '<div class="updated"><p>' . __('Backup Successful' ) . '!';683 $feedback = '<div class="updated"><p>' . __('Backup Successful', 'wp-db-backup') . '!'; 682 684 $file = $this->backup_file; 683 685 switch($_POST['deliver']) { 684 686 case 'http': 685 $feedback .= '<br />' . sprintf(__('Your backup file: <a href="%1s">%2s</a> should begin downloading shortly.' ), get_settings('siteurl') . "/{$this->backup_dir}{$this->backup_file}", $this->backup_file);687 $feedback .= '<br />' . sprintf(__('Your backup file: <a href="%1s">%2s</a> should begin downloading shortly.', 'wp-db-backup'), get_settings('siteurl') . "/{$this->backup_dir}{$this->backup_file}", $this->backup_file); 686 688 break; 687 689 case 'smtp': 688 690 if (! is_email($_POST['backup_recipient'])) { … … 690 692 } else { 691 693 $feedback .= $_POST['backup_recipient']; 692 694 } 693 $feedback = '<br />' . sprintf(__('Your backup has been emailed to %s' ), $feedback);695 $feedback = '<br />' . sprintf(__('Your backup has been emailed to %s', 'wp-db-backup'), $feedback); 694 696 break; 695 697 case 'none': 696 $feedback .= '<br />' . __('Your backup file has been saved on the server. If you would like to download it now, right click and select "Save As"' );697 $feedback .= ':<br /> <a href="' . get_settings('siteurl') . "/{$this->backup_dir}$file\">$file</a> : " . sprintf(__('%s bytes' ), filesize(ABSPATH . $this->backup_dir . $file));698 $feedback .= '<br />' . __('Your backup file has been saved on the server. If you would like to download it now, right click and select "Save As"', 'wp-db-backup'); 699 $feedback .= ':<br /> <a href="' . get_settings('siteurl') . "/{$this->backup_dir}$file\">$file</a> : " . sprintf(__('%s bytes', 'wp-db-backup'), filesize(ABSPATH . $this->backup_dir . $file)); 698 700 } 699 701 $feedback .= '</p></div>'; 700 702 } 701 703 702 704 if (count($this->backup_errors)) { 703 $feedback .= '<div class="updated error">' . __('The following errors were reported:' ) . "<pre>";705 $feedback .= '<div class="updated error">' . __('The following errors were reported:', 'wp-db-backup') . "<pre>"; 704 706 foreach($this->backup_errors as $error) { 705 707 $feedback .= "{$error}\n"; //Errors are already localized 706 708 } … … 714 716 if (is_email($_POST['cron_backup_recipient'])) { 715 717 update_option('wp_cron_backup_recipient', $_POST['cron_backup_recipient'], FALSE); 716 718 } 717 $feedback .= '<div class="updated"><p>' . __('Scheduled Backup Options Saved!' ) . '</p></div>';719 $feedback .= '<div class="updated"><p>' . __('Scheduled Backup Options Saved!', 'wp-db-backup') . '</p></div>'; 718 720 } 719 721 720 722 // Simple table name storage … … 745 747 if ( @ mkdir( ABSPATH . $this->backup_dir) ) { 746 748 @ chmod( ABSPATH . $this->backup_dir, $dir_perms); 747 749 } else { 748 echo '<div class="updated error"><p align="center">' . __('WARNING: Your wp-content directory is <strong>NOT</strong> writable! We can not create the backup directory.' ) . '<br />' . ABSPATH . $this->backup_dir . "</p></div>";750 echo '<div class="updated error"><p align="center">' . __('WARNING: Your wp-content directory is <strong>NOT</strong> writable! We can not create the backup directory.', 'wp-db-backup') . '<br />' . ABSPATH . $this->backup_dir . "</p></div>"; 749 751 $WHOOPS = TRUE; 750 752 } 751 753 } 752 754 753 755 if ( !is_writable( ABSPATH . $this->backup_dir) ) { 754 echo '<div class="updated error"><p align="center">' . __('WARNING: Your backup directory is <strong>NOT</strong> writable! We can not create the backup directory.' ) . '<br />' . ABSPATH . "</p></div>";756 echo '<div class="updated error"><p align="center">' . __('WARNING: Your backup directory is <strong>NOT</strong> writable! We can not create the backup directory.', 'wp-db-backup') . '<br />' . ABSPATH . "</p></div>"; 755 757 } 756 758 757 759 if ( !file_exists( ABSPATH . $this->backup_dir . 'index.php') ) { … … 759 761 } 760 762 761 763 echo "<div class='wrap'>"; 762 echo '<h2>' . __('Backup' ) . '</h2>';763 echo '<fieldset class="options"><legend>' . __('Tables' ) . '</legend>';764 echo '<h2>' . __('Backup', 'wp-db-backup') . '</h2>'; 765 echo '<fieldset class="options"><legend>' . __('Tables', 'wp-db-backup') . '</legend>'; 764 766 echo '<form method="post">'; 765 767 echo '<table align="center" cellspacing="5" cellpadding="5"><tr><td width="50%" align="left" class="alternate" valign="top">'; 766 echo __('These core WordPress tables will always be backed up:' ) . '<br /><ul>';768 echo __('These core WordPress tables will always be backed up:', 'wp-db-backup') . '<br /><ul>'; 767 769 foreach ($wp_backup_default_tables as $table) { 768 770 echo "<li><input type='hidden' name='core_tables[]' value='$table' />$table</li>"; 769 771 } 770 772 echo '</ul></td><td width="50%" align="left" valign="top">'; 771 773 if (count($other_tables) > 0) { 772 echo __('You may choose to include any of the following tables:' ) . ' <br />';774 echo __('You may choose to include any of the following tables:', 'wp-db-backup') . ' <br />'; 773 775 foreach ($other_tables as $table) { 774 776 echo "<label style=\"display:block;\"><input type='checkbox' name='other_tables[]' value='{$table}' /> {$table}</label>"; 775 777 } 776 778 } 777 779 echo '</tr></table></fieldset>'; 778 echo '<fieldset class="options"><legend>' . __('Backup Options' ) . '</legend>';779 echo __('What to do with the backup file:' ) . "<br />";780 echo '<label style="display:block;"><input type="radio" name="deliver" value="none" /> ' . __('Save to server' ) . " ({$this->backup_dir})</label>";781 echo '<label style="display:block;"><input type="radio" checked="checked" name="deliver" value="http" /> ' . __('Download to your computer' ) . '</label>';780 echo '<fieldset class="options"><legend>' . __('Backup Options', 'wp-db-backup') . '</legend>'; 781 echo __('What to do with the backup file:', 'wp-db-backup') . "<br />"; 782 echo '<label style="display:block;"><input type="radio" name="deliver" value="none" /> ' . __('Save to server', 'wp-db-backup') . " ({$this->backup_dir})</label>"; 783 echo '<label style="display:block;"><input type="radio" checked="checked" name="deliver" value="http" /> ' . __('Download to your computer', 'wp-db-backup') . '</label>'; 782 784 echo '<div><input type="radio" name="deliver" id="do_email" value="smtp" /> '; 783 echo '<label for="do_email">'.__('Email backup to:' ).'</label><input type="text" name="backup_recipient" size="20" value="' . get_settings('admin_email') . '" />';785 echo '<label for="do_email">'.__('Email backup to:', 'wp-db-backup').'</label><input type="text" name="backup_recipient" size="20" value="' . get_settings('admin_email') . '" />'; 784 786 785 787 // Check DB dize. 786 788 $table_status = $wpdb->get_results("SHOW TABLE STATUS FROM " . $this->backquote(DB_NAME)); … … 798 800 799 801 if (! $WHOOPS) { 800 802 echo '<input type="hidden" name="do_backup" id="do_backup" value="backup" /></div>'; 801 echo '<p class="submit"><input type="submit" name="submit" onclick="document.getElementById(\'do_backup\').value=\'fragments\';" value="' . __('Backup' ) . '!" / ></p>';803 echo '<p class="submit"><input type="submit" name="submit" onclick="document.getElementById(\'do_backup\').value=\'fragments\';" value="' . __('Backup', 'wp-db-backup') . '!" / ></p>'; 802 804 } else { 803 echo '<p class="alternate">' . __('WARNING: Your backup directory is <strong>NOT</strong> writable!' ) . '</p>';805 echo '<p class="alternate">' . __('WARNING: Your backup directory is <strong>NOT</strong> writable!', 'wp-db-backup') . '</p>'; 804 806 } 805 807 echo '</fieldset>'; 806 808 echo '</form>'; 807 809 808 810 // this stuff only displays if wp_cron is installed 809 811 if (function_exists('wp_cron_init')) { 810 echo '<fieldset class="options"><legend>' . __('Scheduled Backup' ) . '</legend>';812 echo '<fieldset class="options"><legend>' . __('Scheduled Backup', 'wp-db-backup') . '</legend>'; 811 813 $datetime = get_settings('date_format') . ' @ ' . get_settings('time_format'); 812 echo '<p>' . __('Last WP-Cron Daily Execution' ) . ': ' . date($datetime, get_option('wp_cron_daily_lastrun')) . '<br />';813 echo __('Next WP-Cron Daily Execution' ) . ': ' . date($datetime, (get_option('wp_cron_daily_lastrun') + 86400)) . '</p>';814 echo '<p>' . __('Last WP-Cron Daily Execution', 'wp-db-backup') . ': ' . date($datetime, get_option('wp_cron_daily_lastrun')) . '<br />'; 815 echo __('Next WP-Cron Daily Execution', 'wp-db-backup') . ': ' . date($datetime, (get_option('wp_cron_daily_lastrun') + 86400)) . '</p>'; 814 816 echo '<form method="post">'; 815 817 echo '<table width="100%" callpadding="5" cellspacing="5">'; 816 818 echo '<tr><td align="center">'; 817 echo __('Schedule: 819 echo __('Schedule:', 'wp-db-backup'); 818 820 $wp_cron_backup_schedule = get_option('wp_cron_backup_schedule'); 819 $schedule = array(0 => __('None'), 1 => __('Daily' ));821 $schedule = array(0 => __('None'), 1 => __('Daily', 'wp-db-backup')); 820 822 foreach ($schedule as $value => $name) { 821 823 echo ' <input type="radio" name="cron_schedule"'; 822 824 if ($wp_cron_backup_schedule == $value) { 823 825 echo ' checked="checked" '; 824 826 } 825 echo 'value="' . $value . '" /> ' . __($name);827 echo 'value="' . $value . '" /> ' . $name; 826 828 } 827 829 echo '</td><td align="center">'; 828 830 $cron_recipient = get_option('wp_cron_backup_recipient'); 829 831 if (! is_email($cron_recipient)) { 830 832 $cron_recipient = get_settings('admin_email'); 831 833 } 832 echo __('Email backup to:' ) . ' <input type="text" name="cron_backup_recipient" size="20" value="' . $cron_recipient . '" />';834 echo __('Email backup to:', 'wp-db-backup') . ' <input type="text" name="cron_backup_recipient" size="20" value="' . $cron_recipient . '" />'; 833 835 echo '</td></tr>'; 834 836 $cron_tables = get_option('wp_cron_backup_tables'); 835 837 if (! is_array($cron_tables)) { 836 838 $cron_tables = array(); 837 839 } 838 840 if (count($other_tables) > 0) { 839 echo '<tr><td colspan="2" align="left">' . __('Tables to include:' ) . '<br />';841 echo '<tr><td colspan="2" align="left">' . __('Tables to include:', 'wp-db-backup') . '<br />'; 840 842 foreach ($other_tables as $table) { 841 843 echo '<input type="checkbox" '; 842 844 if (in_array($table, $cron_tables)) {