WP-DB-Backup - Version 2.0.4

Version Description

Download this release

Release Info

Developer filosofo
Plugin Icon 128x128 WP-DB-Backup
Version 2.0.4
Comparing to
See all releases

Code changes from version 2.0.3 to 2.0.4

Files changed (2) hide show
  1. readme.txt +1 -1
  2. wp-db-backup.php +30 -18
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.ilfilosofo.com/blog/wp-db-backup/
4
  Tags: mysql, database, backup, cron
5
  Requires at least: 2.0
6
  Tested up to: 2.2
7
- Stable tag: 2.0.3
8
 
9
  On-demand backup of your WordPress database.
10
 
4
  Tags: mysql, database, backup, cron
5
  Requires at least: 2.0
6
  Tested up to: 2.2
7
+ Stable tag: 2.0.4
8
 
9
  On-demand backup of your WordPress database.
10
 
wp-db-backup.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.ilfilosofo.com/blog/wp-db-backup
5
  Description: On-demand backup of your WordPress database. Navigate to <a href="edit.php?page=wp-db-backup.php">Manage &rarr; Backup</a> to get started.
6
  Author: Austin Matzko
7
  Author URI: http://www.ilfilosofo.com/blog/
8
- Version: 2.0.2
9
 
10
  Development continued from that done by Skippy (http://www.skippy.net/)
11
 
@@ -56,6 +56,7 @@ class wpdbBackup {
56
  function wpdbBackup() {
57
  global $table_prefix, $wpdb;
58
  load_plugin_textdomain('wp-db-backup');
 
59
  add_action('wp_db_backup_cron', array(&$this, 'cron_backup'));
60
  add_action('wp_cron_daily', array(&$this, 'wp_cron_daily'));
61
  add_filter('cron_schedules', array(&$this, 'add_sched_options'));
@@ -414,13 +415,13 @@ class wpdbBackup {
414
  function stow($query_line) {
415
  if ($this->gzip()) {
416
  if(@gzwrite($this->fp, $query_line) === FALSE) {
417
- backup_error(__('There was an error writing a line to the backup script:','wp-db-backup'));
418
- backup_error('&nbsp;&nbsp;' . $query_line);
419
  }
420
  } else {
421
  if(@fwrite($this->fp, $query_line) === FALSE) {
422
- backup_error(__('There was an error writing a line to the backup script:','wp-db-backup'));
423
- backup_error('&nbsp;&nbsp;' . $query_line);
424
  }
425
  }
426
  }
@@ -447,7 +448,7 @@ class wpdbBackup {
447
 
448
  $table_structure = $wpdb->get_results("DESCRIBE $table");
449
  if (! $table_structure) {
450
- backup_error(__('Error getting table details','wp-db-backup') . ": $table");
451
  return FALSE;
452
  }
453
 
@@ -623,13 +624,24 @@ class wpdbBackup {
623
  }
624
 
625
  } //wp_db_backup
626
-
 
 
 
 
 
 
 
 
 
 
627
  function deliver_backup ($filename = '', $delivery = 'http', $recipient = '') {
628
  if ('' == $filename) { return FALSE; }
629
 
630
- $diskfile = ABSPATH . $this->backup_dir . $filename;
 
631
  if ('http' == $delivery) {
632
- if (! file_exists($diskfile)) {
633
  $msg = sprintf(__('File not found:%s','wp-db-backup'), "<br /><strong>$filename</strong><br />");
634
  $this_basename = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', __FILE__);
635
  $msg .= '<br /><a href="' . get_option('siteurl') . "/wp-admin/edit.php?page={$this_basename}" . '">' . __('Return to Backup','wp-db-backup');
@@ -637,34 +649,34 @@ class wpdbBackup {
637
  }
638
  header('Content-Description: File Transfer');
639
  header('Content-Type: application/octet-stream');
640
- header('Content-Length: ' . filesize($diskfile));
641
  header("Content-Disposition: attachment; filename=$filename");
642
- readfile($diskfile);
643
- unlink($diskfile);
644
  } elseif ('smtp' == $delivery) {
645
- if (! file_exists($diskfile)) return false;
646
 
647
  if (! is_email ($recipient)) {
648
  $recipient = get_option('admin_email');
649
  }
650
  $randomish = md5(time());
651
  $boundary = "==WPBACKUP-BY-SKIPPY-$randomish";
652
- $fp = fopen($diskfile,"rb");
653
- $file = fread($fp,filesize($diskfile));
654
  $this->close($fp);
655
  $data = chunk_split(base64_encode($file));
656
  $headers = "MIME-Version: 1.0\n";
657
  $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
658
  $headers .= 'From: ' . get_option('admin_email') . "\n";
659
 
660
- $message = sprintf(__("Attached to this email is\n %1s\n Size:%2s kilobytes\n",'wp-db-backup'), $filename, round(filesize($diskfile)/1024));
661
  // Add a multipart boundary above the plain message
662
  $message = "This is a multi-part message in MIME format.\n\n" .
663
  "--{$boundary}\n" .
664
  "Content-Type: text/plain; charset=\"utf-8\"\n" .
665
  "Content-Transfer-Encoding: 7bit\n\n" .
666
  $message . "\n\n";
667
-
668
  // Add file attachment to the message
669
  $message .= "--{$boundary}\n" .
670
  "Content-Type: application/octet-stream;\n" .
@@ -681,7 +693,7 @@ class wpdbBackup {
681
  mail ($recipient, get_bloginfo('name') . ' ' . __('Database Backup','wp-db-backup'), $message, $headers);
682
  }
683
 
684
- unlink($diskfile);
685
  }
686
  return;
687
  }
5
  Description: On-demand backup of your WordPress database. Navigate to <a href="edit.php?page=wp-db-backup.php">Manage &rarr; Backup</a> to get started.
6
  Author: Austin Matzko
7
  Author URI: http://www.ilfilosofo.com/blog/
8
+ Version: 2.0.4
9
 
10
  Development continued from that done by Skippy (http://www.skippy.net/)
11
 
56
  function wpdbBackup() {
57
  global $table_prefix, $wpdb;
58
  load_plugin_textdomain('wp-db-backup');
59
+ add_action('phpmailer_init', array(&$this, 'setup_phpmailer'));
60
  add_action('wp_db_backup_cron', array(&$this, 'cron_backup'));
61
  add_action('wp_cron_daily', array(&$this, 'wp_cron_daily'));
62
  add_filter('cron_schedules', array(&$this, 'add_sched_options'));
415
  function stow($query_line) {
416
  if ($this->gzip()) {
417
  if(@gzwrite($this->fp, $query_line) === FALSE) {
418
+ $this->backup_error(__('There was an error writing a line to the backup script:','wp-db-backup'));
419
+ $this->backup_error('&nbsp;&nbsp;' . $query_line);
420
  }
421
  } else {
422
  if(@fwrite($this->fp, $query_line) === FALSE) {
423
+ $this->backup_error(__('There was an error writing a line to the backup script:','wp-db-backup'));
424
+ $this->backup_error('&nbsp;&nbsp;' . $query_line);
425
  }
426
  }
427
  }
448
 
449
  $table_structure = $wpdb->get_results("DESCRIBE $table");
450
  if (! $table_structure) {
451
+ $this->backup_error(__('Error getting table details','wp-db-backup') . ": $table");
452
  return FALSE;
453
  }
454
 
624
  }
625
 
626
  } //wp_db_backup
627
+
628
+ /**
629
+ * Sets up the attachment to work with phpmailer, which appears in WP 2.2+
630
+ * @return bool
631
+ */
632
+ function setup_phpmailer(&$phpmailer) {
633
+ $phpmailer->AddAttachment($this->diskfile, $this->filename);
634
+ $phpmailer->Body = $this->message;
635
+ return true;
636
+ }
637
+
638
  function deliver_backup ($filename = '', $delivery = 'http', $recipient = '') {
639
  if ('' == $filename) { return FALSE; }
640
 
641
+ $this->diskfile = ABSPATH . $this->backup_dir . $filename;
642
+ $this->filename = $filename;
643
  if ('http' == $delivery) {
644
+ if (! file_exists($this->diskfile)) {
645
  $msg = sprintf(__('File not found:%s','wp-db-backup'), "<br /><strong>$filename</strong><br />");
646
  $this_basename = preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', __FILE__);
647
  $msg .= '<br /><a href="' . get_option('siteurl') . "/wp-admin/edit.php?page={$this_basename}" . '">' . __('Return to Backup','wp-db-backup');
649
  }
650
  header('Content-Description: File Transfer');
651
  header('Content-Type: application/octet-stream');
652
+ header('Content-Length: ' . filesize($this->diskfile));
653
  header("Content-Disposition: attachment; filename=$filename");
654
+ readfile($this->diskfile);
655
+ unlink($this->diskfile);
656
  } elseif ('smtp' == $delivery) {
657
+ if (! file_exists($this->diskfile)) return false;
658
 
659
  if (! is_email ($recipient)) {
660
  $recipient = get_option('admin_email');
661
  }
662
  $randomish = md5(time());
663
  $boundary = "==WPBACKUP-BY-SKIPPY-$randomish";
664
+ $fp = fopen($this->diskfile,"rb");
665
+ $file = fread($fp,filesize($this->diskfile));
666
  $this->close($fp);
667
  $data = chunk_split(base64_encode($file));
668
  $headers = "MIME-Version: 1.0\n";
669
  $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
670
  $headers .= 'From: ' . get_option('admin_email') . "\n";
671
 
672
+ $this->message = $message = sprintf(__("Attached to this email is\n %1s\n Size:%2s kilobytes\n",'wp-db-backup'), $filename, round(filesize($this->diskfile)/1024));
673
  // Add a multipart boundary above the plain message
674
  $message = "This is a multi-part message in MIME format.\n\n" .
675
  "--{$boundary}\n" .
676
  "Content-Type: text/plain; charset=\"utf-8\"\n" .
677
  "Content-Transfer-Encoding: 7bit\n\n" .
678
  $message . "\n\n";
679
+
680
  // Add file attachment to the message
681
  $message .= "--{$boundary}\n" .
682
  "Content-Type: application/octet-stream;\n" .
693
  mail ($recipient, get_bloginfo('name') . ' ' . __('Database Backup','wp-db-backup'), $message, $headers);
694
  }
695
 
696
+ unlink($this->diskfile);
697
  }
698
  return;
699
  }