| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
class WPDB_Admin { |
| 7 |
|
| 8 |
public function __construct() { |
| 9 |
add_action('admin_init', array( $this,'wp_db_backup_admin_init')); |
| 10 |
add_action( 'init', array( $this, 'admin_scripts_style' ) ); |
| 11 |
add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 ); |
| 12 |
add_filter('cron_schedules', array( $this,'wp_db_backup_cron_schedules')); |
| 13 |
add_action('wp_db_backup_event', array( $this,'wp_db_backup_event_process')); |
| 14 |
add_action('wp', array( $this,'wp_db_backup_scheduler_activation')); |
| 15 |
|
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
public function admin_menu() |
| 20 |
{ |
| 21 |
|
| 22 |
$page = add_management_page('WP-DB Backup', 'WP-DB Backup ', 'manage_options', 'wp-database-backup', array( $this,'wp_db_backup_settings_page')); |
| 23 |
|
| 24 |
|
| 25 |
} |
| 26 |
function wp_db_backup_admin_init() { |
| 27 |
|
| 28 |
if(isset($_POST['wp_db_backup_email_id'])) |
| 29 |
{ |
| 30 |
|
| 31 |
update_option('wp_db_backup_email_id',$_POST['wp_db_backup_email_id']); |
| 32 |
} |
| 33 |
if(isset($_POST['wp_db_backup_email_attachment'])) |
| 34 |
{ |
| 35 |
$email_attachment=$_POST['wp_db_backup_email_attachment']; |
| 36 |
update_option('wp_db_backup_email_attachment',$email_attachment); |
| 37 |
} |
| 38 |
if(($_GET['page']=="wp-database-backup" && $_GET['action']=="unlink")) |
| 39 |
{ |
| 40 |
// Specify the target directory and add forward slash |
| 41 |
$dir = plugin_dir_path(__FILE__)."Destination/Dropbox/tokens/"; |
| 42 |
|
| 43 |
// Open the directory |
| 44 |
$dirHandle = opendir($dir); |
| 45 |
// Loop over all of the files in the folder |
| 46 |
while ($file = readdir($dirHandle)) { |
| 47 |
// If $file is NOT a directory remove it |
| 48 |
if(!is_dir($file)) { |
| 49 |
unlink ("$dir"."$file"); // unlink() deletes the files |
| 50 |
} |
| 51 |
} |
| 52 |
// Close the directory |
| 53 |
closedir($dirHandle); |
| 54 |
wp_redirect(get_bloginfo('url').'/wp-admin/tools.php?page=wp-database-backup'); |
| 55 |
|
| 56 |
} |
| 57 |
if(isset($_GET['action'])) { |
| 58 |
switch((string)$_GET['action']) { |
| 59 |
|
| 60 |
case 'createdbbackup': |
| 61 |
$this->wp_db_backup_event_process(); |
| 62 |
wp_redirect(get_bloginfo('url').'/wp-admin/tools.php?page=wp-database-backup'); |
| 63 |
break; |
| 64 |
case 'removebackup': |
| 65 |
$index = (int)$_GET['index']; |
| 66 |
$options = get_option('wp_db_backup_backups'); |
| 67 |
$newoptions = array(); |
| 68 |
$count = 0; |
| 69 |
foreach($options as $option) { |
| 70 |
if($count != $index) { |
| 71 |
$newoptions[] = $option; |
| 72 |
} |
| 73 |
$count++; |
| 74 |
} |
| 75 |
|
| 76 |
unlink($options[$index]['dir']); |
| 77 |
update_option('wp_db_backup_backups', $newoptions); |
| 78 |
wp_redirect(get_bloginfo('url').'/wp-admin/tools.php?page=wp-database-backup'); |
| 79 |
break; |
| 80 |
case 'restorebackup': |
| 81 |
$index = (int)$_GET['index']; |
| 82 |
$options = get_option('wp_db_backup_backups'); |
| 83 |
$newoptions = array(); |
| 84 |
$count = 0; |
| 85 |
foreach($options as $option) { |
| 86 |
if($count != $index) { |
| 87 |
$newoptions[] = $option; |
| 88 |
} |
| 89 |
$count++; |
| 90 |
} |
| 91 |
$database_file=($options[$index]['dir']); |
| 92 |
$database_name=$this->wp_backup_get_config_db_name(); |
| 93 |
$database_user=$this->wp_backup_get_config_data('DB_USER'); |
| 94 |
$datadase_password=$this->wp_backup_get_config_data('DB_PASSWORD'); |
| 95 |
$database_host=$this->wp_backup_get_config_data('DB_HOST'); |
| 96 |
|
| 97 |
ini_set("max_execution_time", "5000"); |
| 98 |
ini_set("max_input_time", "5000"); |
| 99 |
ini_set('memory_limit', '1000M'); |
| 100 |
set_time_limit(0); |
| 101 |
|
| 102 |
|
| 103 |
if((trim((string)$database_name) != '') && (trim((string)$database_user) != '') && (trim((string)$datadase_password) != '') && (trim((string)$database_host) != '') && ($conn = @mysql_connect((string)$database_host, (string)$database_user, (string)$datadase_password))) { |
| 104 |
/*BEGIN: Select the Database*/ |
| 105 |
if(!mysql_select_db((string)$database_name, $conn)) { |
| 106 |
$sql = "CREATE DATABASE IF NOT EXISTS `".(string)$database_name."`"; |
| 107 |
mysql_query($sql, $conn); |
| 108 |
mysql_select_db((string)$database_name, $conn); |
| 109 |
} |
| 110 |
/*END: Select the Database*/ |
| 111 |
|
| 112 |
/*BEGIN: Remove All Tables from the Database*/ |
| 113 |
$found_tables = null; |
| 114 |
if($result = mysql_query("SHOW TABLES FROM `{".(string)$database_name."}`", $conn)){ |
| 115 |
while($row = mysql_fetch_row($result)){ |
| 116 |
$found_tables[] = $row[0]; |
| 117 |
} |
| 118 |
if (count($found_tables) > 0) { |
| 119 |
foreach($found_tables as $table_name){ |
| 120 |
mysql_query("DROP TABLE `{".(string)$database_name."}`.{$table_name}", $conn); |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
/*END: Remove All Tables from the Database*/ |
| 125 |
|
| 126 |
/*BEGIN: Restore Database Content*/ |
| 127 |
if(isset($database_file)) |
| 128 |
{ |
| 129 |
|
| 130 |
$database_file=$database_file; |
| 131 |
$sql_file = @file_get_contents($database_file, true); |
| 132 |
|
| 133 |
$sql_queries = explode(";\n", $sql_file); |
| 134 |
|
| 135 |
|
| 136 |
for($i = 0; $i < count($sql_queries); $i++) { |
| 137 |
mysql_query($sql_queries[$i], $conn); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
} |
| 142 |
} |
| 143 |
break; |
| 144 |
|
| 145 |
/*END: Restore Database Content*/ |
| 146 |
|
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
register_setting('wp_db_backup_options', 'wp_db_backup_options', array( $this,'wp_db_backup_validate')); |
| 151 |
@add_settings_section('wp_db_backup_main', '', 'wp_db_backup_section_text', array( $this,'wp-database-backup')); |
| 152 |
} |
| 153 |
function wp_db_backup_validate($input) { |
| 154 |
return $input; |
| 155 |
} |
| 156 |
public function wp_db_backup_settings_page(){ |
| 157 |
$options = get_option('wp_db_backup_backups'); |
| 158 |
$settings = get_option('wp_db_backup_options'); |
| 159 |
?> <div class="panel panel-info"> |
| 160 |
<div class="panel-heading"> |
| 161 |
<h2><a href="http://walkeprashant.wordpress.com" target="blank"><img src="<?php echo WPDB_PLUGIN_URL.'/assets/images/wp-database-backup.png';?>" ></a>Database Backup Settings</h2> |
| 162 |
</div> |
| 163 |
<div class="panel-body"> |
| 164 |
<ul class="nav nav-tabs"> |
| 165 |
<li class=""><a href="#db_home" data-toggle="tab">Database Backups</a></li> |
| 166 |
<li><a href="#db_schedul" data-toggle="tab">Scheduler</a></li> |
| 167 |
<li><a href="#db_help" data-toggle="tab">Help</a></li> |
| 168 |
<li><a href="#db_destination" data-toggle="tab">Destination</a></li> |
| 169 |
</ul> |
| 170 |
|
| 171 |
<?php |
| 172 |
echo '<div class="tab-content">'; |
| 173 |
echo '<div class="tab-pane active" id="db_home">'; |
| 174 |
echo '<p class="submit">'; |
| 175 |
echo '<a href="'.get_bloginfo('url').'/wp-admin/tools.php?page=wp-database-backup&action=createdbbackup" class="button-primary"><span class="glyphicon glyphicon-plus-sign"></span> Create New Database Backup<a/>'; |
| 176 |
echo '</p>'; |
| 177 |
if($options) { |
| 178 |
echo '<table class="widefat">'; |
| 179 |
echo '<thead>'; |
| 180 |
echo '<tr class="wpdb-header">'; |
| 181 |
echo '<th class="manage-column" scope="col" width="15%" style="text-align: center;">SL No</th>'; |
| 182 |
echo '<th class="manage-column" scope="col" width="25%">Date</th>'; |
| 183 |
echo '<th class="manage-column" scope="col" width="15%">Backup File</th>'; |
| 184 |
echo '<th class="manage-column" scope="col" width="15%">Size</th>'; |
| 185 |
echo '<th class="manage-column" scope="col" width="15%"></th>'; |
| 186 |
echo '<th class="manage-column" scope="col" width="15%"></th>'; |
| 187 |
echo '</tr>'; |
| 188 |
echo '</thead>'; |
| 189 |
echo '<tfoot>'; |
| 190 |
echo '<tr>'; |
| 191 |
echo '<th class="manage-column" scope="col" width="15%" style="text-align: center;">SL No</th>'; |
| 192 |
echo '<th class="manage-column" scope="col" width="25%">Date</th>'; |
| 193 |
echo '<th class="manage-column" scope="col" width="15%">Backup File</th>'; |
| 194 |
echo '<th class="manage-column" scope="col" width="15%">Size</th>'; |
| 195 |
echo '<th class="manage-column" scope="col" width="15%"></th>'; |
| 196 |
echo '<th class="manage-column" scope="col" width="15%"></th>'; |
| 197 |
echo '</tr>'; |
| 198 |
echo '</tfoot>'; |
| 199 |
echo '<tbody>'; |
| 200 |
$count = 1; |
| 201 |
foreach($options as $option) { |
| 202 |
echo '<tr '.((($count % 2) == 0)?' class="alternate"':'').'>'; |
| 203 |
echo '<td style="text-align: center;">'.$count.'</td>'; |
| 204 |
echo '<td>'.date('jS, F Y', $option['date']).'<br />'.date('h:i:s A', $option['date']).'</td>'; |
| 205 |
echo '<td><a href="'.$option['url'].'" style="color: #21759B;"><span class="glyphicon glyphicon-download-alt"></span> Download</a></td>'; |
| 206 |
echo '<td>'.$this->wp_db_backup_format_bytes($option['size']).'</td>'; |
| 207 |
echo '<td><a href="'.get_bloginfo('url').'/wp-admin/tools.php?page=wp-database-backup&action=removebackup&index='.($count - 1).'" class="button-secondary"><span style="color:red" class="glyphicon glyphicon-remove"></span> Remove Database Backup<a/></td>'; |
| 208 |
echo '<td><a href="'.get_bloginfo('url').'/wp-admin/tools.php?page=wp-database-backup&action=restorebackup&index='.($count - 1).'" class="button-secondary"><span class="glyphicon glyphicon-refresh" style="color:blue"></span> Restore Database Backup<a/></td>'; |
| 209 |
echo '</tr>'; |
| 210 |
$count++; |
| 211 |
} |
| 212 |
echo '</tbody>'; |
| 213 |
echo '</table>'; |
| 214 |
} else { |
| 215 |
echo '<p>No Database Backups Created!</p>'; |
| 216 |
} |
| 217 |
|
| 218 |
echo '</div>'; |
| 219 |
|
| 220 |
echo '<div class="tab-pane" id="db_schedul">'; |
| 221 |
echo '<form method="post" action="options.php" name="wp_auto_commenter_form">'; |
| 222 |
settings_fields('wp_db_backup_options'); |
| 223 |
do_settings_sections('wp-database-backup'); |
| 224 |
|
| 225 |
echo '<p>Enable Auto Backups '; |
| 226 |
echo '<input type="checkbox" name="wp_db_backup_options[enable_autobackups]" value="1" '.@checked(1, $settings['enable_autobackups'], false).'/>'; |
| 227 |
echo '</p>'; |
| 228 |
echo '<p>Auto Database Backup Frequency<br />'; |
| 229 |
echo '<select name="wp_db_backup_options[autobackup_frequency]" style="width: 100%; margin: 5px 0 0;">'; |
| 230 |
echo '<option value="daily" '.selected('daily', $settings['autobackup_frequency'], false).'>Daily</option>'; |
| 231 |
echo '<option value="weekly" '.selected('weekly', $settings['autobackup_frequency'], false).'>Weekly</option>'; |
| 232 |
echo '<option value="monthly" '.selected('monthly', $settings['autobackup_frequency'], false).'>Monthly</option>'; |
| 233 |
echo '</select>'; |
| 234 |
echo '</p>'; |
| 235 |
|
| 236 |
echo '<p class="submit">'; |
| 237 |
echo '<input type="submit" name="Submit" class="button-primary" value="Save Settings" />'; |
| 238 |
echo '</p>'; |
| 239 |
echo '</form>'; |
| 240 |
echo '</div>'; |
| 241 |
|
| 242 |
echo '<div class="tab-pane" id="db_help">'; |
| 243 |
echo '<p>'; |
| 244 |
?> |
| 245 |
<div class="panel-group" id="accordion"> |
| 246 |
<div class="panel panel-default"> |
| 247 |
<div class="panel-heading"> |
| 248 |
<h4 class="panel-title"> |
| 249 |
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"> |
| 250 |
Create Backup |
| 251 |
</a> |
| 252 |
</h4> |
| 253 |
</div> |
| 254 |
<div id="collapseOne" class="panel-collapse collapse in"> |
| 255 |
<div class="panel-body"> |
| 256 |
<p>Step 1) Click on Create New Database Backup</p> |
| 257 |
<p>Step 2) Download Database Backup file.</p> |
| 258 |
</div> |
| 259 |
</div> |
| 260 |
</div> |
| 261 |
|
| 262 |
|
| 263 |
<div class="panel-group" id="accordion"> |
| 264 |
<div class="panel panel-default"> |
| 265 |
<div class="panel-heading"> |
| 266 |
<h4 class="panel-title"> |
| 267 |
<a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo"> |
| 268 |
Restore Backup |
| 269 |
</a> |
| 270 |
</h4> |
| 271 |
</div> |
| 272 |
<div id="collapseTwo" class="panel-collapse collapse in"> |
| 273 |
<div class="panel-body"> |
| 274 |
<p>Click on Restore Database Backup </p><p>OR</p> |
| 275 |
|
| 276 |
<p>Step 1) Login to phpMyAdmin.</p> |
| 277 |
<p>Step 2) Click Databases and select the database that you will be importing your data into.</p> |
| 278 |
<p>Step 3) Across the top of the screen will be a row of tabs. Click the Import tab.</p> |
| 279 |
<p>Step 4) On the next screen will be a location of text file box, and next to that a button named Browse.</p> |
| 280 |
<p>Step 5) Click Browse. Locate the backup file stored on your computer.</p> |
| 281 |
<p>Step 6) Click the Go button.</p> |
| 282 |
</div> |
| 283 |
</div> |
| 284 |
</div> |
| 285 |
<div class="panel-group" id="accordion"> |
| 286 |
<div class="panel panel-default"> |
| 287 |
<div class="panel-heading"> |
| 288 |
<h4 class="panel-title"> |
| 289 |
<a data-toggle="collapse" data-parent="#accordion" href="#collapseThree"> |
| 290 |
Wish you more feature? |
| 291 |
</a> |
| 292 |
</h4> |
| 293 |
</div> |
| 294 |
<div id="collapseThree" class="panel-collapse collapse in"> |
| 295 |
<div class="panel-body"> |
| 296 |
<p><span class="glyphicon glyphicon-envelope"><p>If you want more feature or any suggestion then drop me mail we are try to implement in our wp-database-backup plugin and also try to make it more user friendly</p></span> Drop Mail :walke.prashant28@gmail.com</p> |
| 297 |
<p><a title="WP-DB-Backup" href="http://walkeprashant.wordpress.com/wp-database-backup/" target="_blank">More Information</a></p> |
| 298 |
|
| 299 |
</div> |
| 300 |
</div> |
| 301 |
</div> |
| 302 |
|
| 303 |
</div> |
| 304 |
</div></div> |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
</div> <?php |
| 309 |
echo '<div class="tab-pane" id="db_destination">'; |
| 310 |
?> |
| 311 |
<div class="panel panel-default"> |
| 312 |
<div class="panel-heading"> |
| 313 |
<h4 class="panel-title"> |
| 314 |
<a data-toggle="collapse" data-parent="#accordion" href="#collapseI"> |
| 315 |
<h2>FTP/sFTP </h2> |
| 316 |
|
| 317 |
</a> |
| 318 |
</h4> |
| 319 |
</div> |
| 320 |
<div id="collapseI" class="panel-collapse collapse in"> |
| 321 |
<div class="panel-body"> |
| 322 |
<p>FTP/sFTP Destination Define an FTP destination connection. You can define destination which use FTP.</p> |
| 323 |
<?php include plugin_dir_path(__FILE__).'Destination/FTP/ftp-form.php';?> |
| 324 |
</div> |
| 325 |
</div> |
| 326 |
</div> |
| 327 |
<div class="panel panel-default"> |
| 328 |
<div class="panel-heading"> |
| 329 |
<h4 class="panel-title"> |
| 330 |
<a data-toggle="collapse" data-parent="#accordion" href="#collapseII"> |
| 331 |
<h2>Email Notification</h2> |
| 332 |
|
| 333 |
</a> |
| 334 |
</h4> |
| 335 |
</div> |
| 336 |
<div id="collapseII" class="panel-collapse collapse in"> |
| 337 |
<div class="panel-body"> |
| 338 |
|
| 339 |
<?php echo '<form name="wp-email_form" method="post" action="" >'; |
| 340 |
|
| 341 |
$wp_db_backup_email_id=""; |
| 342 |
$wp_db_backup_email_id=get_option('wp_db_backup_email_id'); |
| 343 |
$wp_db_backup_email_attachment=""; |
| 344 |
$wp_db_backup_email_attachment=get_option('wp_db_backup_email_attachment'); |
| 345 |
echo '<p>'; |
| 346 |
echo '<span class="glyphicon glyphicon-envelope"></span> Send Email Notification</br></p>'; |
| 347 |
echo '<p>Email Id : '; |
| 348 |
echo '<input type="text" name="wp_db_backup_email_id" value="'.$wp_db_backup_email_id.'" placeholder="Your Email Id">'; |
| 349 |
echo '<p>Leave blank if you don\'t want use this feature</p>'; |
| 350 |
echo '<p>Attach backup file : '; |
| 351 |
$selected_option=get_option( 'wp_db_backup_email_attachment' ); |
| 352 |
|
| 353 |
if($selected_option=="yes") $selected_yes="selected=\"selected\""; |
| 354 |
else |
| 355 |
$selected_yes=""; |
| 356 |
if($selected_option=="no") $selected_no="selected=\"selected\""; |
| 357 |
else |
| 358 |
$selected_no=""; |
| 359 |
echo '<select id="lead-theme" name="wp_db_backup_email_attachment">'; |
| 360 |
echo '<option value="none">Select</option>'; |
| 361 |
|
| 362 |
echo '<option value="yes"'.$selected_yes.'>Yes</option>'; |
| 363 |
echo '<option value="no" '.$selected_no.'>No</option>'; |
| 364 |
|
| 365 |
|
| 366 |
echo '</select></p>'; |
| 367 |
|
| 368 |
echo '<p>If you want attache backup file to email then select "yes" (File attached only when backup file size <=25MB)</p>'; |
| 369 |
|
| 370 |
echo '</p>'; |
| 371 |
echo '<p class="submit">'; |
| 372 |
echo '<input type="submit" name="Submit" class="button-primary" value="Save Settings" />'; |
| 373 |
echo '</p>'; |
| 374 |
echo '</form>';?> |
| 375 |
</div> |
| 376 |
</div> |
| 377 |
</div> |
| 378 |
|
| 379 |
<div class="panel panel-default"> |
| 380 |
<div class="panel-heading"> |
| 381 |
<h4 class="panel-title"> |
| 382 |
<a data-toggle="collapse" data-parent="#accordion" href="#collapseIII"> |
| 383 |
<h2>Dropbox </h2> |
| 384 |
|
| 385 |
</a> |
| 386 |
</h4> |
| 387 |
</div> |
| 388 |
<div id="collapseIII" class="panel-collapse collapse in"> |
| 389 |
<div class="panel-body"> |
| 390 |
|
| 391 |
<?php include plugin_dir_path(__FILE__).'Destination/Dropbox/dropboxupload.php';?> |
| 392 |
</div> |
| 393 |
</div> |
| 394 |
</div> |
| 395 |
|
| 396 |
<?php |
| 397 |
echo '</div>'; |
| 398 |
?> |
| 399 |
|
| 400 |
|
| 401 |
</div> |
| 402 |
<div class="panel panel-footer">Thank you for using the <a href="http://walkeprashant.wordpress.com/wp-database-backup/" target="_blank">WP Database Backup</a>.</div> |
| 403 |
|
| 404 |
|
| 405 |
<?php |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
} |
| 410 |
|
| 411 |
function wp_db_backup_format_bytes($bytes, $precision = 2) { |
| 412 |
$units = array('B', 'KB', 'MB', 'GB', 'TB'); |
| 413 |
$bytes = max($bytes, 0); |
| 414 |
$pow = floor(($bytes ? log($bytes) : 0) / log(1024)); |
| 415 |
$pow = min($pow, count($units) - 1); |
| 416 |
$bytes /= pow(1024, $pow); |
| 417 |
return round($bytes, $precision) . ' ' . $units[$pow]; |
| 418 |
} |
| 419 |
function wp_db_backup_create_mysql_backup() { |
| 420 |
global $wpdb; |
| 421 |
/*BEGIN : Prevent saving backup plugin settings in the database dump*/ |
| 422 |
$options_backup = get_option('wp_db_backup_backups'); |
| 423 |
$settings_backup = get_option('wp_db_backup_options'); |
| 424 |
delete_option('wp_db_backup_backups'); |
| 425 |
delete_option('wp_db_backup_options'); |
| 426 |
/*END : Prevent saving backup plugin settings in the database dump*/ |
| 427 |
|
| 428 |
$tables = $wpdb->get_col('SHOW TABLES'); |
| 429 |
$output = ''; |
| 430 |
foreach($tables as $table) { |
| 431 |
$result = $wpdb->get_results("SELECT * FROM {$table}", ARRAY_N); |
| 432 |
$row2 = $wpdb->get_row('SHOW CREATE TABLE '.$table, ARRAY_N); |
| 433 |
$output .= "\n\n".$row2[1].";\n\n"; |
| 434 |
for($i = 0; $i < count($result); $i++) { |
| 435 |
$row = $result[$i]; |
| 436 |
$output .= 'INSERT INTO '.$table.' VALUES('; |
| 437 |
for($j=0; $j<count($result[0]); $j++) { |
| 438 |
$row[$j] = mysql_real_escape_string($row[$j]); |
| 439 |
$output .= (isset($row[$j])) ? '"'.$row[$j].'"' : '""'; |
| 440 |
if ($j < (count($result[0])-1)) { |
| 441 |
$output .= ','; |
| 442 |
} |
| 443 |
} |
| 444 |
$output .= ");\n"; |
| 445 |
} |
| 446 |
$output .= "\n"; |
| 447 |
} |
| 448 |
$wpdb->flush(); |
| 449 |
/*BEGIN : Prevent saving backup plugin settings in the database dump*/ |
| 450 |
add_option('wp_db_backup_backups', $options_backup); |
| 451 |
add_option('wp_db_backup_options', $settings_backup); |
| 452 |
/*END : Prevent saving backup plugin settings in the database dump*/ |
| 453 |
return $output; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
function wp_db_backup_create_archive() { |
| 459 |
/*Begin : Setup Upload Directory, Secure it and generate a random file name*/ |
| 460 |
|
| 461 |
$source_directory = $this->wp_db_backup_wp_config_path(); |
| 462 |
|
| 463 |
$path_info = wp_upload_dir(); |
| 464 |
|
| 465 |
wp_mkdir_p($path_info['basedir'].'/db-backup'); |
| 466 |
fclose(fopen($path_info['basedir'].'/db-backup/index.php', 'w')); |
| 467 |
/*Begin : Generate SQL DUMP and save to file database.sql*/ |
| 468 |
$filename=Date("Y_m_d").'_'.Time("H:M:S").'_database.sql'; |
| 469 |
$handle = fopen($path_info['basedir'].'/db-backup/'.$filename,'w+'); |
| 470 |
fwrite($handle, $this->wp_db_backup_create_mysql_backup()); |
| 471 |
fclose($handle); |
| 472 |
|
| 473 |
/*End : Generate SQL DUMP and save to file database.sql*/ |
| 474 |
$upload_path = array( |
| 475 |
'filename' => ($filename), |
| 476 |
'dir' => ($path_info['basedir'].'/db-backup/'.$filename), |
| 477 |
'url' => ($path_info['baseurl'].'/db-backup/'.$filename), |
| 478 |
'size' => 0 |
| 479 |
); |
| 480 |
$upload_path['size']=filesize($upload_path['dir']); |
| 481 |
return $upload_path; |
| 482 |
|
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
function wp_db_backup_wp_config_path() { |
| 487 |
$base = dirname(__FILE__); |
| 488 |
$path = false; |
| 489 |
if (@file_exists(dirname(dirname($base))."/wp-config.php")) { |
| 490 |
$path = dirname(dirname($base)); |
| 491 |
} else { |
| 492 |
if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php")) { |
| 493 |
$path = dirname(dirname(dirname($base))); |
| 494 |
} else { |
| 495 |
$path = false; |
| 496 |
} |
| 497 |
} |
| 498 |
if ($path != false) { |
| 499 |
$path = str_replace("\\", "/", $path); |
| 500 |
} |
| 501 |
return $path; |
| 502 |
} |
| 503 |
function wp_db_backup_event_process() { |
| 504 |
$options = get_option('wp_db_backup_backups'); |
| 505 |
$details = $this->wp_db_backup_create_archive(); |
| 506 |
|
| 507 |
if(!$options) { |
| 508 |
$options = array(); |
| 509 |
} |
| 510 |
$options[] = array( |
| 511 |
'date' => mktime(), |
| 512 |
'filename' => $details['filename'], |
| 513 |
'url' => $details['url'], |
| 514 |
'dir' => $details['dir'], |
| 515 |
'size' => $details['size'] |
| 516 |
); |
| 517 |
update_option('wp_db_backup_backups', $options); |
| 518 |
|
| 519 |
//FTP |
| 520 |
include plugin_dir_path(__FILE__).'Destination/FTP/preflight.php'; |
| 521 |
$filename = $details['filename']; |
| 522 |
$filename = $details['filename']; |
| 523 |
include plugin_dir_path(__FILE__).'Destination/FTP/sendaway.php'; |
| 524 |
|
| 525 |
//Dropbox |
| 526 |
$dropb_autho=get_option('dropb_autho'); |
| 527 |
if($dropb_autho=="yes") |
| 528 |
{ |
| 529 |
include plugin_dir_path(__FILE__).'Destination/Dropbox/dropboxupload.php'; |
| 530 |
|
| 531 |
|
| 532 |
$wp_upload_dir = wp_upload_dir(); |
| 533 |
|
| 534 |
$wp_upload_dir['basedir'] = str_replace('\\', '/', $wp_upload_dir['basedir']); |
| 535 |
|
| 536 |
$localfile = trailingslashit($wp_upload_dir['basedir'].'/backup/').$filename; |
| 537 |
|
| 538 |
|
| 539 |
$dropbox->UploadFile($localfile, $filename); |
| 540 |
|
| 541 |
} |
| 542 |
|
| 543 |
//Email |
| 544 |
if(get_option('wp_db_backup_email_id')) |
| 545 |
{ |
| 546 |
$to=get_option('wp_db_backup_email_id'); |
| 547 |
$subject="Database Backup Created Successfully"; |
| 548 |
$filename=$details['filename']; |
| 549 |
$filesze=$details['size']; |
| 550 |
$message="Hi, \n\n Database Backup Created Successfully \n\n File Name :$filename \n\n File Size :".$this->wp_db_backup_format_bytes($filesze)." \n\n Thank you for using WP-Database-Backup Plugin \n\n For Advanced Feature drop mail walke.prashant28@gmail.com"; |
| 551 |
$headers=""; |
| 552 |
$wp_db_backup_email_attachment_file=get_option('wp_db_backup_email_attachment'); |
| 553 |
if($wp_db_backup_email_attachment_file=="yes" && $details['size']<=209700000) |
| 554 |
{ |
| 555 |
$wp_upload_dir = wp_upload_dir(); |
| 556 |
$wp_upload_dir['basedir'] = str_replace('\\', '/', $wp_upload_dir['basedir']); |
| 557 |
$filename = $details['filename']; |
| 558 |
$attachments = trailingslashit($wp_upload_dir['basedir'].'/db-backup'). $filename; |
| 559 |
} |
| 560 |
else |
| 561 |
$attachments=""; |
| 562 |
wp_mail( $to, $subject, $message, $headers, $attachments ); |
| 563 |
} |
| 564 |
} |
| 565 |
public function wp_db_backup_cron_schedules($schedules) { |
| 566 |
$schedules['weekly'] = array( |
| 567 |
'interval' => 604800, |
| 568 |
'display' => 'Once Weekly' |
| 569 |
); |
| 570 |
$schedules['monthly'] = array( |
| 571 |
'interval' => 2635200, |
| 572 |
'display' => 'Once a month' |
| 573 |
); |
| 574 |
return $schedules; |
| 575 |
} |
| 576 |
public function wp_db_backup_scheduler_activation() { |
| 577 |
$options= get_option('wp_db_backup_options'); |
| 578 |
if ((!wp_next_scheduled('wp_db_backup_event')) && (@$options['enable_autobackups'])) { |
| 579 |
wp_schedule_event(time(), $options['autobackup_frequency'], 'wp_db_backup_event'); |
| 580 |
} |
| 581 |
} |
| 582 |
function wp_backup_get_config_data($key) { |
| 583 |
$filepath=get_home_path().'/wp-config.php'; |
| 584 |
$config_file = @file_get_contents("$filepath", true); |
| 585 |
switch($key) { |
| 586 |
case 'DB_NAME': |
| 587 |
preg_match("/'DB_NAME',\s*'(.*)?'/", $config_file, $matches); |
| 588 |
break; |
| 589 |
case 'DB_USER': |
| 590 |
preg_match("/'DB_USER',\s*'(.*)?'/", $config_file, $matches); |
| 591 |
break; |
| 592 |
case 'DB_PASSWORD': |
| 593 |
preg_match("/'DB_PASSWORD',\s*'(.*)?'/", $config_file, $matches); |
| 594 |
break; |
| 595 |
case 'DB_HOST': |
| 596 |
preg_match("/'DB_HOST',\s*'(.*)?'/", $config_file, $matches); |
| 597 |
break; |
| 598 |
} |
| 599 |
return $matches[1]; |
| 600 |
} |
| 601 |
|
| 602 |
function wp_backup_get_config_db_name() { |
| 603 |
$filepath=get_home_path().'/wp-config.php'; |
| 604 |
$config_file = @file_get_contents("$filepath", true); |
| 605 |
preg_match("/'DB_NAME',\s*'(.*)?'/", $config_file, $matches); |
| 606 |
return $matches[1]; |
| 607 |
} |
| 608 |
|
| 609 |
/** |
| 610 |
* Enqueue scripts and style |
| 611 |
*/ |
| 612 |
public function admin_scripts_style() { |
| 613 |
|
| 614 |
if (isset($_GET['page'])) { |
| 615 |
if ($_GET['page'] == "wp-database-backup") { |
| 616 |
|
| 617 |
wp_enqueue_script('jquery'); |
| 618 |
|
| 619 |
wp_enqueue_script('bootstrapjs',WPDB_PLUGIN_URL."/assets/js/bootstrap.min.js" ); |
| 620 |
wp_enqueue_script('bootstrapjs'); |
| 621 |
|
| 622 |
wp_enqueue_style('bootstrapcss',WPDB_PLUGIN_URL."/assets/css/bootstrap.min.css" ); |
| 623 |
wp_enqueue_style('bootstrapcss'); |
| 624 |
|
| 625 |
wp_enqueue_style('wpdbcss',WPDB_PLUGIN_URL."/assets/css/wpdb_admin.css" ); |
| 626 |
wp_enqueue_style('wpdbcss'); |
| 627 |
|
| 628 |
|
| 629 |
} |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
} |
| 635 |
|
| 636 |
return new WPDB_Admin(); |