WP-DBManager - Version 2.80.1

Version Description

Download this release

Release Info

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

Code changes from version 2.80 to 2.80.1

Files changed (4) hide show
  1. database-backup.php +4 -5
  2. database-manage.php +26 -35
  3. readme.txt +6 -1
  4. wp-dbmanager.php +72 -38
database-backup.php CHANGED
@@ -38,15 +38,14 @@ if(!empty($_POST['do'])) {
38
  }
39
  }
40
  $gzip = isset( $_POST['gzip'] ) ? (int) $_POST['gzip'] : 0;
41
-
42
  if ( $gzip === 1 ) {
43
- $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
44
- $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
45
  do_action( 'wp_dbmanager_before_escapeshellcmd' );
46
  $backup['command'] = $brace . escapeshellcmd( $backup['mysqldumppath'] ) . $brace . ' --force --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' | gzip > ' . $brace . escapeshellcmd( $backup['filepath'] ) . $brace;
47
  } else {
48
- $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
49
- $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
50
  do_action( 'wp_dbmanager_before_escapeshellcmd' );
51
  $backup['command'] = $brace . escapeshellcmd( $backup['mysqldumppath'] ) . $brace . ' --force --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' > ' . $brace . escapeshellcmd( $backup['filepath'] ) . $brace;
52
  }
38
  }
39
  }
40
  $gzip = isset( $_POST['gzip'] ) ? (int) $_POST['gzip'] : 0;
41
+ $backup['filename'] = $backup['date'] . '_-_' . DB_NAME . '.sql';
42
  if ( $gzip === 1 ) {
43
+ $backup['filename'] .= '.gz';
44
+ $backup['filepath'] = $backup['path'] . '/' . $backup['filename'];
45
  do_action( 'wp_dbmanager_before_escapeshellcmd' );
46
  $backup['command'] = $brace . escapeshellcmd( $backup['mysqldumppath'] ) . $brace . ' --force --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' | gzip > ' . $brace . escapeshellcmd( $backup['filepath'] ) . $brace;
47
  } else {
48
+ $backup['filepath'] = $backup['path'] . '/' . $backup['filename'];
 
49
  do_action( 'wp_dbmanager_before_escapeshellcmd' );
50
  $backup['command'] = $brace . escapeshellcmd( $backup['mysqldumppath'] ) . $brace . ' --force --host=' . escapeshellarg( $backup['host'] ) . ' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' > ' . $brace . escapeshellcmd( $backup['filepath'] ) . $brace;
51
  }
database-manage.php CHANGED
@@ -22,7 +22,7 @@ if( !empty( $_POST['do'] ) ) {
22
  check_admin_referer('wp-dbmanager_manage');
23
  // Lets Prepare The Variables
24
  $database_file = ! empty ( $_POST['database_file'] ) ? sanitize_file_name( $_POST['database_file'] ) : '';
25
- $nice_file_date = mysql2date(sprintf(__('%s @ %s', 'wp-dbmanager'), get_option('date_format'), get_option('time_format')), gmdate('Y-m-d H:i:s', substr($database_file, 0, 10)));
26
  $text = '';
27
 
28
  // Decide What To Do
@@ -58,45 +58,45 @@ if( !empty( $_POST['do'] ) ) {
58
  passthru( $backup['command'], $error );
59
  }
60
  if($error) {
61
- $text = '<p style="color: red;">'.sprintf(__('Database On \'%s\' Failed To Restore', 'wp-dbmanager'), $nice_file_date).'</p>';
62
  } else {
63
- $text = '<p style="color: green;">'.sprintf(__('Database On \'%s\' Restored Successfully', 'wp-dbmanager'), $nice_file_date).'</p>';
64
  }
65
  } else {
66
- $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
67
  }
68
  break;
69
  case __('E-Mail', 'wp-dbmanager'):
70
  if(!empty($database_file)) {
71
  $to = ( !empty( $_POST['email_to'] ) ? sanitize_email( $_POST['email_to'] ) : get_option( 'admin_email' ) );
72
 
73
- if( dbmanager_email_backup( $to, $backup['path'].'/'.$database_file ) ) {
74
- $text .= '<p style="color: green;">'.sprintf(__('Database Backup File For \'%s\' Successfully E-Mailed To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</p>';
75
  } else {
76
- $text = '<p style="color: red;">'.sprintf(__('Unable To E-Mail Database Backup File For \'%s\' To \'%s\'', 'wp-dbmanager'), $nice_file_date, $to).'</p>';
77
  }
78
  } else {
79
- $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
80
  }
81
  break;
82
  case __('Download', 'wp-dbmanager'):
83
  if(empty($database_file)) {
84
- $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
85
  }
86
  break;
87
  case __('Delete', 'wp-dbmanager'):
88
  if ( ! empty( $database_file ) ) {
89
  if ( is_file( $backup['path'] . '/' . $database_file ) ) {
90
  if ( ! unlink( $backup['path'] . '/' . $database_file ) ) {
91
- $text .= '<p style="color: red;">'.sprintf(__('Unable To Delete Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</p>';
92
  } else {
93
- $text .= '<p style="color: green;">'.sprintf(__('Database Backup File On \'%s\' Deleted Successfully', 'wp-dbmanager'), $nice_file_date).'</p>';
94
  }
95
  } else {
96
- $text = '<p style="color: red;">'.sprintf(__('Invalid Database Backup File On \'%s\'', 'wp-dbmanager'), $nice_file_date).'</p>';
97
  }
98
  } else {
99
- $text = '<p style="color: red;">'.__('No Backup Database File Selected', 'wp-dbmanager').'</p>';
100
  }
101
  break;
102
  }
@@ -123,40 +123,31 @@ if( !empty( $_POST['do'] ) ) {
123
  <?php
124
  $no = 0;
125
  $totalsize = 0;
126
- if ( ! is_emtpy_folder( $backup['path'] ) && $handle = opendir($backup['path'] ) ) {
127
  $database_files = array();
128
- while (false !== ($file = readdir($handle))) {
129
  if ( $file !== '.' && $file !== '..' && $file !== '.htaccess' && ( file_ext( $file ) === 'sql' || file_ext( $file ) === 'gz' ) ) {
130
- $database_files[] = $file;
131
  }
132
  }
133
- closedir($handle);
134
- sort($database_files);
135
- $database_files_count = count( $database_files ) - 1;
136
- for ( $i = $database_files_count; $i > -1; $i-- ) {
137
  if ( $no % 2 === 0 ) {
138
  $style = '';
139
  } else {
140
  $style = ' class="alternate"';
141
  }
142
  $no++;
143
- $file_parts = explode( '_-_', $database_files[$i] );
144
- if ( count( $file_parts ) > 2 ) {
145
- list( $checksum_text, $date, $database_text ) = $file_parts;
146
- } else {
147
- $checksum_text = '-';
148
- list( $date, $database_text ) = $file_parts;
149
- }
150
- $date_text = mysql2date( sprintf( __( '%s @ %s', 'wp-dbmanager' ), get_option( 'date_format' ), get_option( 'time_format' ) ), gmdate( 'Y-m-d H:i:s', $date));
151
- $size_text = filesize($backup['path'].'/'.$database_files[$i]);
152
  echo '<tr'. $style .'>';
153
  echo '<td>' . number_format_i18n( $no ) . '</td>';
154
- echo '<td>' . $checksum_text . '</td>';
155
- echo '<td>' . $database_text .'</td>';
156
- echo '<td>' . $date_text . '</td>';
157
- echo '<td>' . format_size( $size_text ) . '</td>';
158
- echo '<td><input type="radio" name="database_file" value="'. esc_attr( $database_files[$i] ) .'" /></td></tr>';
159
- $totalsize += $size_text;
160
  }
161
  } else {
162
  echo '<tr><td align="center" colspan="6">'.__('There Are No Database Backup Files Available.', 'wp-dbmanager').'</td></tr>';
22
  check_admin_referer('wp-dbmanager_manage');
23
  // Lets Prepare The Variables
24
  $database_file = ! empty ( $_POST['database_file'] ) ? sanitize_file_name( $_POST['database_file'] ) : '';
25
+ $file = dbmanager_parse_filename( $database_file );
26
  $text = '';
27
 
28
  // Decide What To Do
58
  passthru( $backup['command'], $error );
59
  }
60
  if($error) {
61
+ $text = '<p style="color: red;">' . sprintf( __( 'Database On \'%s\' Failed To Restore', 'wp-dbmanager' ), $file['formatted_date'] ) . '</p>';
62
  } else {
63
+ $text = '<p style="color: green;">' . sprintf( __( 'Database On \'%s\' Restored Successfully', 'wp-dbmanager' ), $file['formatted_date'] ) . '</p>';
64
  }
65
  } else {
66
+ $text = '<p style="color: red;">' . __('No Backup Database File Selected', 'wp-dbmanager' ) . '</p>';
67
  }
68
  break;
69
  case __('E-Mail', 'wp-dbmanager'):
70
  if(!empty($database_file)) {
71
  $to = ( !empty( $_POST['email_to'] ) ? sanitize_email( $_POST['email_to'] ) : get_option( 'admin_email' ) );
72
 
73
+ if( dbmanager_email_backup( $to, $backup['path'] . '/' . $database_file ) ) {
74
+ $text .= '<p style="color: green;">' . sprintf( __( 'Database Backup File For \'%s\' Successfully E-Mailed To \'%s\'', 'wp-dbmanager' ), $file['formatted_date'], $to) . '</p>';
75
  } else {
76
+ $text = '<p style="color: red;">' . sprintf( __( 'Unable To E-Mail Database Backup File For \'%s\' To \'%s\'', 'wp-dbmanager' ), $file['formatted_date'], $to ) . '</p>';
77
  }
78
  } else {
79
+ $text = '<p style="color: red;">' . __('No Backup Database File Selected', 'wp-dbmanager' ) . '</p>';
80
  }
81
  break;
82
  case __('Download', 'wp-dbmanager'):
83
  if(empty($database_file)) {
84
+ $text = '<p style="color: red;">' . __( 'No Backup Database File Selected', 'wp-dbmanager' ) . '</p>';
85
  }
86
  break;
87
  case __('Delete', 'wp-dbmanager'):
88
  if ( ! empty( $database_file ) ) {
89
  if ( is_file( $backup['path'] . '/' . $database_file ) ) {
90
  if ( ! unlink( $backup['path'] . '/' . $database_file ) ) {
91
+ $text .= '<p style="color: red;">' . sprintf( __( 'Unable To Delete Database Backup File On \'%s\'', 'wp-dbmanager' ), $file['formatted_date'] ) . '</p>';
92
  } else {
93
+ $text .= '<p style="color: green;">' . sprintf( __( 'Database Backup File On \'%s\' Deleted Successfully', 'wp-dbmanager' ), $file['formatted_date'] ) . '</p>';
94
  }
95
  } else {
96
+ $text = '<p style="color: red;">' . sprintf( __( 'Invalid Database Backup File On \'%s\'', 'wp-dbmanager' ), $file['formatted_date'] ) . '</p>';
97
  }
98
  } else {
99
+ $text = '<p style="color: red;">' . __( 'No Backup Database File Selected', 'wp-dbmanager' ) . '</p>';
100
  }
101
  break;
102
  }
123
  <?php
124
  $no = 0;
125
  $totalsize = 0;
126
+ if ( ! is_emtpy_folder( $backup['path'] ) && $handle = opendir( $backup['path'] ) ) {
127
  $database_files = array();
128
+ while ( false !== ( $file = readdir( $handle ) ) ) {
129
  if ( $file !== '.' && $file !== '..' && $file !== '.htaccess' && ( file_ext( $file ) === 'sql' || file_ext( $file ) === 'gz' ) ) {
130
+ $database_files[filemtime( $backup['path'] . '/' . $file )] = $file;
131
  }
132
  }
133
+ closedir( $handle );
134
+ krsort( $database_files );
135
+ foreach( $database_files as $database_file_mtime => $database_file ) {
 
136
  if ( $no % 2 === 0 ) {
137
  $style = '';
138
  } else {
139
  $style = ' class="alternate"';
140
  }
141
  $no++;
142
+ $file = dbmanager_parse_file( $backup['path'] . '/'. $database_file );
 
 
 
 
 
 
 
 
143
  echo '<tr'. $style .'>';
144
  echo '<td>' . number_format_i18n( $no ) . '</td>';
145
+ echo '<td>' . $file['checksum'] . '</td>';
146
+ echo '<td>' . $file['database'] . '</td>';
147
+ echo '<td>' . $file['formatted_date'] . '</td>';
148
+ echo '<td>' . $file['formatted_size'] . '</td>';
149
+ echo '<td><input type="radio" name="database_file" value="'. esc_attr( $database_file ) .'" /></td></tr>';
150
+ $totalsize += $file['size'];
151
  }
152
  } else {
153
  echo '<tr><td align="center" colspan="6">'.__('There Are No Database Backup Files Available.', 'wp-dbmanager').'</td></tr>';
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://lesterchan.net/site/donation/
4
  Tags: database, manage, wp-dbmanager, manager, table, optimize, backup, queries, query, drop, empty, tables, table, run, repair, cron, schedule, scheduling, automatic
5
  Requires at least: 4.0
6
  Tested up to: 5.3
7
- Stable tag: 2.80
8
 
9
  Manages your WordPress database.
10
 
@@ -42,6 +42,11 @@ Allows you to optimize database, repair database, backup database, restore datab
42
  * To know about the difference between WP-DBManager and WP-DB-backup, checkout __What is the difference between WP-DBManager and WP-DB-Backup?__ in the [FAQ section](https://wordpress.org/plugins/wp-dbmanager/faq/).
43
 
44
  ## Changelog
 
 
 
 
 
45
  ### Version 2.80
46
  * NEW: Prefix MD5 checksum to the database backup file to prevent user from guessing the filename.
47
 
4
  Tags: database, manage, wp-dbmanager, manager, table, optimize, backup, queries, query, drop, empty, tables, table, run, repair, cron, schedule, scheduling, automatic
5
  Requires at least: 4.0
6
  Tested up to: 5.3
7
+ Stable tag: 2.80.1
8
 
9
  Manages your WordPress database.
10
 
42
  * To know about the difference between WP-DBManager and WP-DB-backup, checkout __What is the difference between WP-DBManager and WP-DB-Backup?__ in the [FAQ section](https://wordpress.org/plugins/wp-dbmanager/faq/).
43
 
44
  ## Changelog
45
+
46
+ ### Version 2.80.1
47
+ * FIXED: 1970 date issues.
48
+ * FIXED: Sorting order of backup files.
49
+
50
  ### Version 2.80
51
  * NEW: Prefix MD5 checksum to the database backup file to prevent user from guessing the filename.
52
 
wp-dbmanager.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP-DBManager
4
  Plugin URI: https://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, optimizing and repairing of database.
6
- Version: 2.80
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: https://lesterchan.net
9
  Text Domain: wp-dbmanager
@@ -11,7 +11,7 @@ Text Domain: wp-dbmanager
11
 
12
 
13
  /*
14
- Copyright 2019 Lester Chan (email : lesterchan@gmail.com)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
@@ -89,15 +89,15 @@ function cron_dbmanager_backup() {
89
  }
90
  }
91
  $backup['command'] = '';
 
92
  $brace = 0 === strpos( PHP_OS, 'WIN' ) ? '"' : '';
93
  if ( (int) $backup_options['backup_gzip'] === 1 ) {
94
- $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
95
- $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
96
  do_action( 'wp_dbmanager_before_escapeshellcmd' );
97
  $backup['command'] = $brace . escapeshellcmd( $backup['mysqldumppath'] ) . $brace . ' --force --host=' . escapeshellarg( $backup['host'] ).' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' | gzip > '. $brace . escapeshellcmd( $backup['filepath'] ) . $brace;
98
  } else {
99
- $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
100
- $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
101
  do_action( 'wp_dbmanager_before_escapeshellcmd' );
102
  $backup['command'] = $brace . escapeshellcmd( $backup['mysqldumppath'] ) . $brace . ' --force --host=' . escapeshellarg( $backup['host'] ).' --user=' . escapeshellarg( DB_USER ). ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' > ' . $brace . escapeshellcmd( $backup['filepath'] ) . $brace;
103
  }
@@ -109,6 +109,7 @@ function cron_dbmanager_backup() {
109
  }
110
  }
111
  }
 
112
  function cron_dbmanager_optimize() {
113
  global $wpdb;
114
  $backup_options = get_option('dbmanager_options');
@@ -122,6 +123,7 @@ function cron_dbmanager_optimize() {
122
  $wpdb->query('OPTIMIZE TABLE '.implode(',', $optimize_tables));
123
  }
124
  }
 
125
  function cron_dbmanager_repair() {
126
  global $wpdb;
127
  $backup_options = get_option('dbmanager_options');
@@ -135,6 +137,7 @@ function cron_dbmanager_repair() {
135
  $wpdb->query('REPAIR TABLE '.implode(',', $repair_tables));
136
  }
137
  }
 
138
  function cron_dbmanager_reccurences($schedules) {
139
  $backup_options = get_option( 'dbmanager_options' );
140
 
@@ -278,46 +281,77 @@ function dbmanager_is_valid_path( $path ) {
278
  return preg_match( '/^[^*?"<>|;]*$/', $path );
279
  }
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  ### Function: Email database backup
282
- function dbmanager_email_backup($to = '', $backup_file_path)
283
- {
284
- if( is_email( $to ) && file_exists( $backup_file_path ) )
285
- {
286
- $backup_options = get_option( 'dbmanager_options' );
287
 
288
- $file_name = basename( $backup_file_path );
289
- $file_gmt_date = gmdate( 'Y-m-d H:i:s', substr( $file_name, 0, 10 ) );
290
- $file_size = format_size( filesize( $backup_file_path) );
291
- $file_date = mysql2date( sprintf( __( '%s @ %s', 'wp-dbmanager' ), get_option( 'date_format' ), get_option( 'time_format' ) ), $file_gmt_date );
292
 
293
- $to = ( !empty( $to ) ? $to : get_option( 'admin_email' ) );
 
294
 
295
- $subject = ( !empty( $backup_options['backup_email_subject'] ) ? $backup_options['backup_email_subject'] : dbmanager_default_options( 'backup_email_subject' ) );
296
  $subject = str_replace(
297
- array(
298
- '%SITE_NAME%'
299
- , '%POST_DATE%'
300
- , '%POST_TIME%'
301
- )
302
- , array(
303
- wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES )
304
- , mysql2date( get_option( 'date_format' ), $file_gmt_date )
305
- , mysql2date( get_option( 'time_format' ), $file_gmt_date )
306
  )
307
  , $subject
308
  );
309
- $message = __( 'Website Name:', 'wp-dbmanager').' '. wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) . "\n".
310
- __( 'Website URL:', 'wp-dbmanager' ).' '.get_bloginfo( 'url' )."\n".
311
- __( 'Backup File Name:', 'wp-dbmanager' ).' '.$file_name."\n".
312
- __( 'Backup File Date:', 'wp-dbmanager' ).' '.$file_date."\n".
313
- __( 'Backup File Size:', 'wp-dbmanager' ).' '.$file_size."\n\n".
 
314
  __( 'With Regards,', 'wp-dbmanager' )."\n".
315
- wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ). ' ' . __('Administrator', 'wp-dbmanager' )."\n".
316
- get_bloginfo('url');
317
 
318
- $from = ( !empty( $backup_options['backup_email_from'] ) ? $backup_options['backup_email_from'] : dbmanager_default_options( 'backup_email_from' ) );
319
- $from_name = ( !empty( $backup_options['backup_email_from_name'] ) ? $backup_options['backup_email_from_name'] : dbmanager_default_options( 'backup_email_from_name' ) );
320
- $headers[] = 'From: "' . wp_specialchars_decode( stripslashes_deep( $from_name ), ENT_QUOTES ) . '" <'.$from.'>';
321
 
322
  return wp_mail( $to, $subject, $message, $headers, $backup_file_path );
323
  }
@@ -518,7 +552,7 @@ function download_database() {
518
  $backup_options = get_option( 'dbmanager_options' );
519
  $clean_file_name = sanitize_file_name( $database_file );
520
  $clean_file_name = str_replace( 'sql_.gz', 'sql.gz', $clean_file_name );
521
- $file_path = $backup_options['path'].'/'.$clean_file_name;
522
  header( 'Pragma: public' );
523
  header( 'Expires: 0' );
524
  header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
@@ -527,7 +561,7 @@ function download_database() {
527
  header( 'Content-Type: application/download' );
528
  header( 'Content-Disposition: attachment; filename=' . basename( $file_path ) . ';' );
529
  header( 'Content-Transfer-Encoding: binary' );
530
- header( 'Content-Length: '.filesize( $file_path ) );
531
  @readfile( $file_path );
532
  }
533
  exit();
3
  Plugin Name: WP-DBManager
4
  Plugin URI: https://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, optimizing and repairing of database.
6
+ Version: 2.80.1
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: https://lesterchan.net
9
  Text Domain: wp-dbmanager
11
 
12
 
13
  /*
14
+ Copyright 2019 Lester Chan (email : lesterchan@gmail.com)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
89
  }
90
  }
91
  $backup['command'] = '';
92
+ $backup['filename'] = $backup['date'] . '_-_' . DB_NAME . '.sql';
93
  $brace = 0 === strpos( PHP_OS, 'WIN' ) ? '"' : '';
94
  if ( (int) $backup_options['backup_gzip'] === 1 ) {
95
+ $backup['filename'] .= '.gz';
96
+ $backup['filepath'] = $backup['path'] . '/'. $backup['filename'];
97
  do_action( 'wp_dbmanager_before_escapeshellcmd' );
98
  $backup['command'] = $brace . escapeshellcmd( $backup['mysqldumppath'] ) . $brace . ' --force --host=' . escapeshellarg( $backup['host'] ).' --user=' . escapeshellarg( DB_USER ) . ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' | gzip > '. $brace . escapeshellcmd( $backup['filepath'] ) . $brace;
99
  } else {
100
+ $backup['filepath'] = $backup['path'] . '/'. $backup['filename'];
 
101
  do_action( 'wp_dbmanager_before_escapeshellcmd' );
102
  $backup['command'] = $brace . escapeshellcmd( $backup['mysqldumppath'] ) . $brace . ' --force --host=' . escapeshellarg( $backup['host'] ).' --user=' . escapeshellarg( DB_USER ). ' --password=' . escapeshellarg( DB_PASSWORD ) . $backup['port'] . $backup['sock'] . $backup['charset'] . ' --add-drop-table --skip-lock-tables ' . DB_NAME . ' > ' . $brace . escapeshellcmd( $backup['filepath'] ) . $brace;
103
  }
109
  }
110
  }
111
  }
112
+
113
  function cron_dbmanager_optimize() {
114
  global $wpdb;
115
  $backup_options = get_option('dbmanager_options');
123
  $wpdb->query('OPTIMIZE TABLE '.implode(',', $optimize_tables));
124
  }
125
  }
126
+
127
  function cron_dbmanager_repair() {
128
  global $wpdb;
129
  $backup_options = get_option('dbmanager_options');
137
  $wpdb->query('REPAIR TABLE '.implode(',', $repair_tables));
138
  }
139
  }
140
+
141
  function cron_dbmanager_reccurences($schedules) {
142
  $backup_options = get_option( 'dbmanager_options' );
143
 
281
  return preg_match( '/^[^*?"<>|;]*$/', $path );
282
  }
283
 
284
+ ### Functionn : Breakdown the file name into array
285
+ function dbmanager_parse_filename( $filename ) {
286
+ $file_parts = explode( '_-_', $filename );
287
+ if ( count( $file_parts ) > 2 ) {
288
+ $file = array(
289
+ 'checksum' => $file_parts[0],
290
+ 'timestamp' => $file_parts[1],
291
+ 'database' => $file_parts[2],
292
+ );
293
+ } else {
294
+ $file = array(
295
+ 'checksum' => '-',
296
+ 'timestamp' => $file_parts[0],
297
+ 'database' => $file_parts[1],
298
+ );
299
+ }
300
+
301
+ $file['name'] = $filename;
302
+ $file['formatted_date'] = mysql2date( sprintf( __( '%s @ %s', 'wp-dbmanager' ), get_option( 'date_format' ), get_option( 'time_format' ) ), gmdate( 'Y-m-d H:i:s', $file['timestamp'] ) );
303
+
304
+ return $file;
305
+ }
306
+
307
+ ### Functionn : Return extra information like file size and nice date of the file
308
+ function dbmanager_parse_file( $filepath ) {
309
+ $filename = basename( $filepath );
310
+ $file_parts = dbmanager_parse_filename( $filename );
311
+ $file_parts['path'] = dirname( $filepath );
312
+ $file_parts['size'] = filesize( $filepath );
313
+ $file_parts['formatted_size'] = format_size( $file_parts['size'] );
314
+
315
+ return $file_parts;
316
+ }
317
+
318
  ### Function: Email database backup
319
+ function dbmanager_email_backup( $to, $backup_file_path ) {
320
+ $to = ( !empty( $to ) ? $to : get_option( 'admin_email' ) );
 
 
 
321
 
322
+ if( is_email( $to ) && file_exists( $backup_file_path ) ) {
323
+ $backup_options = get_option( 'dbmanager_options' );
 
 
324
 
325
+ $file = dbmanager_parse_file( $backup_file_path );
326
+ $file_gmt_date = gmdate( 'Y-m-d H:i:s', $file['timestamp'] );
327
 
328
+ $subject = ( ! empty( $backup_options['backup_email_subject'] ) ? $backup_options['backup_email_subject'] : dbmanager_default_options( 'backup_email_subject' ) );
329
  $subject = str_replace(
330
+ array(
331
+ '%SITE_NAME%',
332
+ '%POST_DATE%',
333
+ '%POST_TIME%'
334
+ ),
335
+ array(
336
+ wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
337
+ mysql2date( get_option( 'date_format' ), $file_gmt_date ),
338
+ mysql2date( get_option( 'time_format' ), $file_gmt_date )
339
  )
340
  , $subject
341
  );
342
+ $message = __( 'Website Name:', 'wp-dbmanager' ) . ' ' . wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) . "\n" .
343
+ __( 'Website URL:', 'wp-dbmanager' ) . ' '. get_bloginfo( 'url' ) . "\n\n" .
344
+ __( 'Backup File Name:', 'wp-dbmanager' ) . ' ' . $file['name'] . "\n" .
345
+ __( 'Backup File MD5 Checksum:', 'wp-dbmanager' ) . ' ' . $file['checksum'] . "\n" .
346
+ __( 'Backup File Date:', 'wp-dbmanager' ) . ' ' . $file['formatted_date'] . "\n" .
347
+ __( 'Backup File Size:', 'wp-dbmanager' ) . ' ' . $file['formatted_size'] . "\n\n" .
348
  __( 'With Regards,', 'wp-dbmanager' )."\n".
349
+ wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) . ' ' . __('Administrator', 'wp-dbmanager' ) . "\n" .
350
+ get_bloginfo( 'url' );
351
 
352
+ $from = ( ! empty( $backup_options['backup_email_from'] ) ? $backup_options['backup_email_from'] : dbmanager_default_options( 'backup_email_from' ) );
353
+ $from_name = ( ! empty( $backup_options['backup_email_from_name'] ) ? $backup_options['backup_email_from_name'] : dbmanager_default_options( 'backup_email_from_name' ) );
354
+ $headers[] = 'From: "' . wp_specialchars_decode( stripslashes_deep( $from_name ), ENT_QUOTES ) . '" <' . $from . '>';
355
 
356
  return wp_mail( $to, $subject, $message, $headers, $backup_file_path );
357
  }
552
  $backup_options = get_option( 'dbmanager_options' );
553
  $clean_file_name = sanitize_file_name( $database_file );
554
  $clean_file_name = str_replace( 'sql_.gz', 'sql.gz', $clean_file_name );
555
+ $file_path = $backup_options['path'] . '/' . $clean_file_name;
556
  header( 'Pragma: public' );
557
  header( 'Expires: 0' );
558
  header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
561
  header( 'Content-Type: application/download' );
562
  header( 'Content-Disposition: attachment; filename=' . basename( $file_path ) . ';' );
563
  header( 'Content-Transfer-Encoding: binary' );
564
+ header( 'Content-Length: ' . filesize( $file_path ) );
565
  @readfile( $file_path );
566
  }
567
  exit();