mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-09-05 09:19:53 +08:00
Fixed: CodeFactor issues
This commit is contained in:
parent
3ce0b519f2
commit
1df25aa2cd
1 changed files with 131 additions and 319 deletions
|
@ -1,8 +1,5 @@
|
|||
<?php
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
/**
|
||||
* Credits
|
||||
*
|
||||
* Plugin-Name: BackUpWordPress
|
||||
|
@ -14,7 +11,6 @@
|
|||
*
|
||||
* The code is used for the MainWP BackUpWordPress Extension
|
||||
* Extension URL: https://mainwp.com/extension/backupwordpress/
|
||||
*
|
||||
*/
|
||||
|
||||
class MainWP_Child_Back_Up_Wordpress {
|
||||
|
@ -49,7 +45,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
|
||||
|
||||
if ( get_option( 'mainwp_backupwordpress_hide_plugin' ) === 'hide' ) {
|
||||
if ( 'hide' === get_option( 'mainwp_backupwordpress_hide_plugin' ) ) {
|
||||
add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
|
||||
add_action( 'admin_menu', array( $this, 'remove_menu' ) );
|
||||
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
|
||||
|
@ -140,7 +136,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
$information = array( 'error' => 'Empty schedule id' );
|
||||
MainWP_Helper::write( $information );
|
||||
} else {
|
||||
$schedule_id = sanitize_text_field( urldecode( $schedule_id ) );
|
||||
$schedule_id = sanitize_text_field( rawurldecode( $schedule_id ) );
|
||||
HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
||||
if ( ! HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) {
|
||||
$information = array( 'result' => 'NOTFOUND' );
|
||||
|
@ -164,16 +160,16 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
// ok
|
||||
private function get_sync_data() {
|
||||
MainWP_Helper::check_classes_exists('HM\BackUpWordPress\Schedules');
|
||||
MainWP_Helper::check_methods('HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) );
|
||||
MainWP_Helper::check_classes_exists( 'HM\BackUpWordPress\Schedules' );
|
||||
MainWP_Helper::check_methods( 'HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) );
|
||||
|
||||
HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
||||
$schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
||||
$backups_time = array();
|
||||
|
||||
if ( is_array($schedules) && count($schedules) ) {
|
||||
$check = current($schedules);
|
||||
MainWP_Helper::check_methods($check, array( 'get_backups' ) );
|
||||
if ( is_array( $schedules ) && count( $schedules ) ) {
|
||||
$check = current( $schedules );
|
||||
MainWP_Helper::check_methods( $check, array( 'get_backups' ) );
|
||||
|
||||
foreach ( $schedules as $sche ) {
|
||||
$existing_backup = $sche->get_backups();
|
||||
|
@ -194,16 +190,15 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
}
|
||||
|
||||
function do_site_stats() {
|
||||
if ( has_action('mainwp_child_reports_log') ) {
|
||||
do_action( 'mainwp_child_reports_log', 'backupwordpress');
|
||||
if ( has_action( 'mainwp_child_reports_log' ) ) {
|
||||
do_action( 'mainwp_child_reports_log', 'backupwordpress' );
|
||||
} else {
|
||||
$this->do_reports_log('backupwordpress');
|
||||
$this->do_reports_log( 'backupwordpress' );
|
||||
}
|
||||
}
|
||||
|
||||
// ok
|
||||
public function do_reports_log( $ext = '' ) {
|
||||
if ( $ext !== 'backupwordpress' ) {
|
||||
if ( 'backupwordpress' !== $ext ) {
|
||||
return;
|
||||
}
|
||||
if ( ! $this->is_plugin_installed ) {
|
||||
|
@ -211,15 +206,15 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
}
|
||||
|
||||
try {
|
||||
MainWP_Helper::check_classes_exists('HM\BackUpWordPress\Schedules');
|
||||
MainWP_Helper::check_methods('HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ));
|
||||
MainWP_Helper::check_classes_exists( 'HM\BackUpWordPress\Schedules' );
|
||||
MainWP_Helper::check_methods( 'HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) );
|
||||
|
||||
// Refresh the schedules from the database to make sure we have the latest changes
|
||||
// Refresh the schedules from the database to make sure we have the latest changes.
|
||||
HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
|
||||
$schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
|
||||
if ( is_array($schedules) && count($schedules) > 0 ) {
|
||||
$check = current($schedules);
|
||||
MainWP_Helper::check_methods($check, array( 'get_backups', 'get_type' ));
|
||||
if ( is_array( $schedules ) && count( $schedules ) > 0 ) {
|
||||
$check = current( $schedules );
|
||||
MainWP_Helper::check_methods( $check, array( 'get_backups', 'get_type' ) );
|
||||
|
||||
foreach ( $schedules as $schedule ) {
|
||||
foreach ( $schedule->get_backups() as $file ) {
|
||||
|
@ -230,7 +225,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
$date = @filemtime( $file );
|
||||
if ( ! empty( $date ) ) {
|
||||
do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $date );
|
||||
MainWP_Helper::update_lasttime_backup('backupwordpress', $date); // to support backup before update feature
|
||||
MainWP_Helper::update_lasttime_backup( 'backupwordpress', $date ); // to support backup before update feature.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +246,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
function delete_schedule() {
|
||||
$schedule_id = $this->check_schedule();
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
||||
|
||||
if ( $schedule ) {
|
||||
$schedule->cancel( true );
|
||||
|
@ -265,10 +260,10 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
function hmbkp_request_cancel_backup() {
|
||||
$schedule_id = $this->check_schedule();
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
||||
|
||||
// Delete the running backup
|
||||
if ( method_exists($schedule, 'get_running_backup_filename' ) ) {
|
||||
// Delete the running backup.
|
||||
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
||||
if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) {
|
||||
unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() );
|
||||
}
|
||||
|
@ -277,7 +272,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
}
|
||||
} else {
|
||||
$status = $schedule->get_status();
|
||||
// Delete the running backup
|
||||
// Delete the running backup.
|
||||
if ( $status->get_backup_filename() && file_exists( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ) ) {
|
||||
unlink( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() );
|
||||
}
|
||||
|
@ -301,9 +296,9 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
function get_backup_status() {
|
||||
$schedule_id = $this->check_schedule();
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
||||
|
||||
if ( method_exists($schedule, 'get_running_backup_filename' ) ) {
|
||||
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
||||
$information['scheduleStatus'] = $schedule->get_status();
|
||||
} else {
|
||||
$status = $schedule->get_status();
|
||||
|
@ -317,16 +312,16 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
function run_schedule() {
|
||||
$schedule_id = $this->check_schedule();
|
||||
if ( function_exists('hmbkp_run_schedule_async') ) {
|
||||
hmbkp_run_schedule_async($schedule_id);
|
||||
} elseif ( function_exists('\HM\BackUpWordPress\run_schedule_async') ) {
|
||||
if ( function_exists( 'hmbkp_run_schedule_async' ) ) {
|
||||
hmbkp_run_schedule_async( $schedule_id );
|
||||
} elseif ( function_exists( '\HM\BackUpWordPress\run_schedule_async' ) ) {
|
||||
HM\BackUpWordPress\Path::get_instance()->cleanup();
|
||||
// Fixes an issue on servers which only allow a single session per client
|
||||
// Fixes an issue on servers which only allow a single session per client.
|
||||
session_write_close();
|
||||
$task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id );
|
||||
$task->schedule();
|
||||
} else {
|
||||
return array( 'error' => __('Error while trying to trigger the schedule', 'mainwp-child') );
|
||||
return array( 'error' => __( 'Error while trying to trigger the schedule', 'mainwp-child' ) );
|
||||
}
|
||||
return array( 'result' => 'SUCCESS' );
|
||||
}
|
||||
|
@ -351,8 +346,8 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
continue;
|
||||
}
|
||||
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
|
||||
$started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
||||
$started_ago = method_exists( $schedule, 'get_schedule_running_start_time' ) ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
|
||||
$out = array(
|
||||
'b' => $this->get_backupslist_html( $schedule ),
|
||||
'count' => count( $schedule->get_backups() ),
|
||||
|
@ -360,7 +355,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
'started_ago' => human_time_diff( $started_ago ),
|
||||
);
|
||||
|
||||
if ( method_exists($schedule, 'get_running_backup_filename' ) ) {
|
||||
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
||||
$out['scheduleStatus'] = $schedule->get_status();
|
||||
} else {
|
||||
$status = $schedule->get_status();
|
||||
|
@ -378,8 +373,8 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
if ( ! in_array( $sch_id, $scheduleIds ) ) {
|
||||
$current_option = get_option( 'hmbkp_schedule_' . $sch_id );
|
||||
if ( is_array( $current_option ) ) {
|
||||
unset( $current_option['excludes'] ); // not send this value
|
||||
$started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
|
||||
unset( $current_option['excludes'] );
|
||||
$started_ago = method_exists( $schedule, 'get_schedule_running_start_time' ) ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
|
||||
$send_back_schedules[ $sch_id ] = array(
|
||||
'options' => $current_option,
|
||||
'b' => $this->get_backupslist_html( $schedule ),
|
||||
|
@ -388,7 +383,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
'scheduleStatus' => $schedule->get_status(),
|
||||
'started_ago' => human_time_diff( $started_ago ),
|
||||
);
|
||||
if ( method_exists($schedule, 'get_running_backup_filename' ) ) {
|
||||
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
||||
$send_back_schedules['scheduleStatus'] = $schedule->get_status();
|
||||
} else {
|
||||
$status = $schedule->get_status();
|
||||
|
@ -398,7 +393,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
}
|
||||
}
|
||||
|
||||
if ( function_exists('HM\BackUpWordPress\Backup::get_home_path') ) {
|
||||
if ( function_exists( 'HM\BackUpWordPress\Backup::get_home_path' ) ) {
|
||||
$backups_path = str_replace( HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() );
|
||||
} else {
|
||||
$backups_path = str_replace( HM\BackUpWordPress\Path::get_home_path(), '', HM\BackUpWordPress\Path::get_path() );
|
||||
|
@ -418,9 +413,9 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
$schedule_id = $this->check_schedule();
|
||||
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
||||
|
||||
$deleted = $schedule->delete_backup(base64_decode( urldecode($_POST['hmbkp_backuparchive'] )));
|
||||
$deleted = $schedule->delete_backup( base64_decode( rawurldecode( $_POST['hmbkp_backuparchive'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
|
||||
|
||||
if ( is_wp_error( $deleted ) ) {
|
||||
return array( 'error' => $deleted->get_error_message() );
|
||||
|
@ -432,7 +427,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
'count' => count( $schedule->get_backups() ),
|
||||
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
|
||||
);
|
||||
if ( method_exists($schedule, 'get_running_backup_filename' ) ) {
|
||||
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
||||
$ret['scheduleStatus'] = $schedule->get_status();
|
||||
} else {
|
||||
$status = $schedule->get_status();
|
||||
|
@ -450,10 +445,10 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
<tr>
|
||||
|
||||
<th scope="col"><?php function_exists('hmbkp_backups_number') ? hmbkp_backups_number( $schedule ) : ( function_exists('backups_number') ? backups_number( $schedule ) : '' ); ?></th>
|
||||
<th scope="col"><?php esc_html_e( 'Size', 'mainwp-backupwordpress-extension' ); ?></th>
|
||||
<th scope="col"><?php esc_html_e( 'Type', 'mainwp-backupwordpress-extension' ); ?></th>
|
||||
<th scope="col"><?php esc_html_e( 'Actions', 'mainwp-backupwordpress-extension' ); ?></th>
|
||||
<th scope="col"><?php function_exists( 'hmbkp_backups_number' ) ? hmbkp_backups_number( $schedule ) : ( function_exists( 'backups_number' ) ? backups_number( $schedule ) : '' ); ?></th>
|
||||
<th scope="col"><?php esc_html_e( 'Size', 'mainwp-child' ); ?></th>
|
||||
<th scope="col"><?php esc_html_e( 'Type', 'mainwp-child' ); ?></th>
|
||||
<th scope="col"><?php esc_html_e( 'Actions', 'mainwp-child' ); ?></th>
|
||||
|
||||
</tr>
|
||||
|
||||
|
@ -480,7 +475,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
<tr>
|
||||
<td class="hmbkp-no-backups"
|
||||
colspan="4"><?php esc_html_e( 'This is where your backups will appear once you have some.', 'mainwp-backupwordpress-extension' ); ?></td>
|
||||
colspan="4"><?php esc_html_e( 'This is where your backups will appear once you have some.', 'mainwp-child' ); ?></td>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
@ -496,23 +491,23 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
|
||||
function hmbkp_get_site_size_text( HM\BackUpWordPress\Scheduled_Backup $schedule ) {
|
||||
if ( method_exists($schedule, 'is_site_size_cached') ) {
|
||||
if ( method_exists( $schedule, 'is_site_size_cached' ) ) {
|
||||
if ( ( 'database' === $schedule->get_type() ) || $schedule->is_site_size_cached() ) {
|
||||
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-backupwordpress-extension' ) . '">%s</code>)', esc_attr( $schedule->get_formatted_site_size() ) );
|
||||
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-child' ) . '">%s</code>)', esc_attr( $schedule->get_formatted_site_size() ) );
|
||||
}
|
||||
} else {
|
||||
$site_size = new HM\BackUpWordPress\Site_Size( $schedule->get_type(), $schedule->get_excludes() );
|
||||
if ( ( 'database' === $schedule->get_type() ) || $site_size->is_site_size_cached() ) {
|
||||
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'backupwordpress' ) . '">%s</code>)', esc_attr( $site_size->get_formatted_site_size() ) );
|
||||
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-child' ) . '">%s</code>)', esc_attr( $site_size->get_formatted_site_size() ) );
|
||||
}
|
||||
}
|
||||
|
||||
return sprintf( '(<code class="calculating" title="' . __( 'this shouldn\'t take long…', 'mainwp-backupwordpress-extension' ) . '">' . __( 'calculating the size of your backup…', 'mainwp-backupwordpress-extension' ) . '</code>)' );
|
||||
return sprintf( '(<code class="calculating" title="' . __( 'this shouldn\'t take long…', 'mainwp-child' ) . '">' . __( 'calculating the size of your backup…', 'mainwp-child' ) . '</code>)' );
|
||||
}
|
||||
|
||||
function hmbkp_get_backup_row( $file, HM\BackUpWordPress\Scheduled_Backup $schedule ) {
|
||||
|
||||
$encoded_file = urlencode( base64_encode( $file ) );
|
||||
$encoded_file = rawurlencode( base64_encode( $file ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
|
||||
$offset = get_option( 'gmt_offset' ) * 3600;
|
||||
|
||||
?>
|
||||
|
@ -527,25 +522,25 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
<?php echo esc_html( size_format( @filesize( $file ) ) ); ?>
|
||||
</td>
|
||||
|
||||
<td><?php echo function_exists('hmbkp_human_get_type') ? esc_html( hmbkp_human_get_type( $file, $schedule ) ) : esc_html( HM\BackUpWordPress\human_get_type( $file, $schedule)); ?></td>
|
||||
<td><?php echo function_exists( 'hmbkp_human_get_type' ) ? esc_html( hmbkp_human_get_type( $file, $schedule ) ) : esc_html( HM\BackUpWordPress\human_get_type( $file, $schedule ) ); ?></td>
|
||||
|
||||
<td>
|
||||
|
||||
<?php
|
||||
if ( function_exists('hmbkp_is_path_accessible') ) {
|
||||
if ( function_exists( 'hmbkp_is_path_accessible' ) ) {
|
||||
if ( hmbkp_is_path_accessible( hmbkp_path() ) ) {
|
||||
?>
|
||||
<a href="#"
|
||||
onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);"
|
||||
class="download-action"><?php esc_html_e( 'Download', 'backupwordpress' ); ?></a> |
|
||||
class="download-action"><?php esc_html_e( 'Download', 'mainwp-child' ); ?></a> |
|
||||
<?php
|
||||
};
|
||||
} elseif ( function_exists('HM\BackUpWordPress\is_path_accessible') ) {
|
||||
if ( HM\BackUpWordPress\is_path_accessible(HM\BackUpWordPress\Path::get_path()) ) {
|
||||
} elseif ( function_exists( 'HM\BackUpWordPress\is_path_accessible' ) ) {
|
||||
if ( HM\BackUpWordPress\is_path_accessible( HM\BackUpWordPress\Path::get_path() ) ) {
|
||||
?>
|
||||
<a href="#"
|
||||
onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);"
|
||||
class="download-action"><?php esc_html_e( 'Download', 'backupwordpress' ); ?></a> |
|
||||
class="download-action"><?php esc_html_e( 'Download', 'maiwnp-child' ); ?></a> |
|
||||
<?php
|
||||
};
|
||||
}
|
||||
|
@ -553,7 +548,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
<a href="#"
|
||||
onclick="event.preventDefault(); mainwp_backupwp_delete_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);"
|
||||
class="delete-action"><?php esc_html_e( 'Delete', 'backupwordpress' ); ?></a>
|
||||
class="delete-action"><?php esc_html_e( 'Delete', 'mainwp-child' ); ?></a>
|
||||
|
||||
</td>
|
||||
|
||||
|
@ -565,10 +560,10 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
function get_excluded( $browse_dir = null ) {
|
||||
|
||||
$schedule_id = $this->check_schedule();
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) );
|
||||
|
||||
$new_version = true;
|
||||
if ( method_exists($schedule, 'get_running_backup_filename' ) ) {
|
||||
if ( method_exists( $schedule, 'get_running_backup_filename' ) ) {
|
||||
$new_version = false;
|
||||
$user_excludes = array_diff( $schedule->get_excludes(), $schedule->backup->default_excludes() );
|
||||
$root_dir = $schedule->backup->get_root();
|
||||
|
@ -584,45 +579,23 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
?>
|
||||
<div class="hmbkp-exclude-settings">
|
||||
|
||||
<?php // if ( $schedule->get_excludes() ) : ?>
|
||||
|
||||
<h3>
|
||||
<?php esc_html_e( 'Currently Excluded', 'backupwordpress' ); ?>
|
||||
</h3>
|
||||
|
||||
<p><?php esc_html_e( 'We automatically detect and ignore common <abbr title="Version Control Systems">VCS</abbr> folders and other backup plugin folders.', 'backupwordpress' ); ?></p>
|
||||
|
||||
<h3><?php esc_html_e( 'Currently Excluded', 'mainwp-child' ); ?></h3>
|
||||
<p><?php esc_html_e( 'We automatically detect and ignore common <abbr title="Version Control Systems">VCS</abbr> folders and other backup plugin folders.', 'mainwp-child' ); ?></p>
|
||||
<table class="widefat">
|
||||
|
||||
<tbody>
|
||||
<?php foreach ( $user_excludes as $key => $exclude ) : ?>
|
||||
|
||||
<?php $exclude_path = new SplFileInfo( trailingslashit( $root_dir ) . ltrim( str_ireplace( $root_dir, '', $exclude ), '/' ) ); ?>
|
||||
|
||||
<tr>
|
||||
|
||||
<th scope="row">
|
||||
|
||||
<?php if ( $exclude_path->isFile() ) { ?>
|
||||
|
||||
<div class="dashicons dashicons-media-default"></div>
|
||||
|
||||
<?php } elseif ( $exclude_path->isDir() ) { ?>
|
||||
|
||||
<div class="dashicons dashicons-portfolio"></div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</th>
|
||||
|
||||
<td>
|
||||
<code>
|
||||
<?php echo esc_html( str_ireplace( $root_dir, '', $exclude ) ); ?>
|
||||
</code>
|
||||
|
||||
<code><?php echo esc_html( str_ireplace( $root_dir, '', $exclude ) ); ?></code>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
if ( $new_version ) {
|
||||
|
@ -630,191 +603,123 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
} else {
|
||||
$is_default_rule = ( in_array( $exclude, $schedule->backup->default_excludes() ) ) || ( hmbkp_path() === untrailingslashit( $exclude ) );
|
||||
}
|
||||
|
||||
if ( $is_default_rule ) :
|
||||
?>
|
||||
<?php esc_html_e( 'Default rule', 'backupwordpress' ); ?>
|
||||
|
||||
<?php esc_html_e( 'Default rule', 'mainwp-child' ); ?>
|
||||
<?php elseif ( defined( 'HMBKP_EXCLUDE' ) && false !== strpos( HMBKP_EXCLUDE, $exclude ) ) : ?>
|
||||
|
||||
<?php esc_html_e( 'Defined in wp-config.php', 'backupwordpress' ); ?>
|
||||
|
||||
<?php esc_html_e( 'Defined in wp-config.php', 'mainwp-child' ); ?>
|
||||
<?php else : ?>
|
||||
|
||||
<a href="#"
|
||||
onclick="event.preventDefault(); mainwp_backupwp_remove_exclude_rule('<?php esc_attr_e( $exclude ); ?>', this);"
|
||||
class="delete-action"><?php esc_html_e( 'Stop excluding', 'backupwordpress' ); ?></a>
|
||||
|
||||
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_remove_exclude_rule('<?php esc_attr_e( $exclude ); ?>', this);" class="delete-action"><?php esc_html_e( 'Stop excluding', 'mainwp-child' ); ?></a>
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
<?php // endif; ?>
|
||||
|
||||
<h3 id="directory-listing"><?php esc_html_e( 'Your Site', 'backupwordpress' ); ?></h3>
|
||||
|
||||
<p><?php esc_html_e( 'Here\'s a directory listing of all files on your site, you can browse through and exclude files or folders that you don\'t want included in your backup.', 'backupwordpress' ); ?></p>
|
||||
|
||||
<h3 id="directory-listing"><?php esc_html_e( 'Your Site', 'mainwp-child' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Here\'s a directory listing of all files on your site, you can browse through and exclude files or folders that you don\'t want included in your backup.', 'mainwp-child' ); ?></p>
|
||||
<?php
|
||||
// The directory to display
|
||||
$directory = $root_dir;
|
||||
|
||||
if ( isset( $browse_dir ) ) {
|
||||
|
||||
$untrusted_directory = urldecode( $browse_dir );
|
||||
$untrusted_directory = rawurldecode( $browse_dir );
|
||||
|
||||
// Only allow real sub directories of the site root to be browsed
|
||||
// Only allow real sub directories of the site root to be browsed.
|
||||
if ( false !== strpos( $untrusted_directory, $root_dir ) && is_dir( $untrusted_directory ) ) {
|
||||
$directory = $untrusted_directory;
|
||||
}
|
||||
}
|
||||
|
||||
// Kick off a recursive filesize scan
|
||||
// Kick off a recursive filesize scan.
|
||||
if ( $new_version ) {
|
||||
|
||||
$site_size = new HM\BackUpWordPress\Site_Size();
|
||||
|
||||
$exclude_string = implode( '|', $excludes->get_excludes_for_regex() );
|
||||
|
||||
if ( function_exists('HM\BackUpWordPress\list_directory_by_total_filesize') ) {
|
||||
if ( function_exists( 'HM\BackUpWordPress\list_directory_by_total_filesize' ) ) {
|
||||
$files = HM\BackUpWordPress\list_directory_by_total_filesize( $directory, $excludes );
|
||||
}
|
||||
} else {
|
||||
$files = $schedule->list_directory_by_total_filesize( $directory );
|
||||
$exclude_string = $schedule->backup->exclude_string( 'regex' );
|
||||
}
|
||||
|
||||
if ( $files ) {
|
||||
?>
|
||||
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th scope="col"><?php esc_html_e( 'Name', 'backupwordpress' ); ?></th>
|
||||
<th scope="col" class="column-format"><?php esc_html_e( 'Size', 'backupwordpress' ); ?></th>
|
||||
<th scope="col"><?php esc_html_e( 'Name', 'mainwp-child' ); ?></th>
|
||||
<th scope="col" class="column-format"><?php esc_html_e( 'Size', 'mainwp-child' ); ?></th>
|
||||
<th scope="col"
|
||||
class="column-format"><?php esc_html_e( 'Permissions', 'backupwordpress' ); ?></th>
|
||||
<th scope="col" class="column-format"><?php esc_html_e( 'Type', 'backupwordpress' ); ?></th>
|
||||
<th scope="col" class="column-format"><?php esc_html_e( 'Status', 'backupwordpress' ); ?></th>
|
||||
class="column-format"><?php esc_html_e( 'Permissions', 'mainwp-child' ); ?></th>
|
||||
<th scope="col" class="column-format"><?php esc_html_e( 'Type', 'mainwp-child' ); ?></th>
|
||||
<th scope="col" class="column-format"><?php esc_html_e( 'Status', 'mainwp-child' ); ?></th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<th scope="row">
|
||||
<div class="dashicons dashicons-admin-home"></div>
|
||||
</th>
|
||||
|
||||
<th scope="col">
|
||||
|
||||
<?php
|
||||
if ( $root_dir !== $directory ) {
|
||||
// echo esc_url( remove_query_arg( 'hmbkp_directory_browse' ) );
|
||||
?>
|
||||
<a href="#"
|
||||
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('', this)"><?php echo esc_html( $root_dir ); ?></a>
|
||||
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse( '', this )"><?php echo esc_html( $root_dir ); ?></a>
|
||||
<code>/</code>
|
||||
|
||||
<?php
|
||||
$parents = array_filter( explode( '/', str_replace( trailingslashit( $root_dir ), '', trailingslashit( dirname( $directory ) ) ) ) );
|
||||
|
||||
foreach ( $parents as $directory_basename ) {
|
||||
?>
|
||||
|
||||
<a href="#"
|
||||
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ); ?>', this)"><?php echo esc_html( $directory_basename ); ?></a>
|
||||
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo rawurlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ); ?>', this)"><?php echo esc_html( $directory_basename ); ?></a>
|
||||
<code>/</code>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php echo esc_html( basename( $directory ) ); ?>
|
||||
|
||||
<?php } else { ?>
|
||||
|
||||
<?php echo esc_html( $root_dir ); ?>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</th>
|
||||
|
||||
<td class="column-filesize">
|
||||
|
||||
<?php if ( $is_size_calculated ) : ?>
|
||||
|
||||
<span class="spinner "></span>
|
||||
|
||||
<span class="spinner"></span>
|
||||
<?php
|
||||
else :
|
||||
|
||||
$root = new SplFileInfo( $root_dir );
|
||||
|
||||
if ( $new_version ) {
|
||||
$size = $site_size->filesize( $root );
|
||||
} else {
|
||||
$size = $schedule->filesize( $root, true );
|
||||
}
|
||||
|
||||
if ( false !== $size ) {
|
||||
|
||||
$size = size_format( $size );
|
||||
|
||||
if ( ! $size ) {
|
||||
$size = '0 B';
|
||||
}
|
||||
?>
|
||||
|
||||
<code>
|
||||
|
||||
<?php echo esc_html( $size ); ?>
|
||||
|
||||
<a class="dashicons dashicons-update"
|
||||
href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( $root_dir ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'backupwordpress' ); ?></span></a>
|
||||
|
||||
<a class="dashicons dashicons-update" href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', rawurlencode( $root_dir ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'mainwp-child' ); ?></span></a>
|
||||
</code>
|
||||
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<td>
|
||||
<?php echo esc_html( substr( sprintf( '%o', fileperms( $root_dir ) ), - 4 ) ); ?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
<?php
|
||||
if ( is_link( $root_dir ) ) {
|
||||
esc_html_e( 'Symlink', 'backupwordpress' );
|
||||
esc_html_e( 'Symlink', 'mainwp-child' );
|
||||
} elseif ( is_dir( $root_dir ) ) {
|
||||
esc_html_e( 'Folder', 'backupwordpress' );
|
||||
esc_html_e( 'Folder', 'mainwp-child' );
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
|
||||
<td></td>
|
||||
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ( $files as $size => $file ) {
|
||||
|
||||
$is_excluded = $is_unreadable = false;
|
||||
|
||||
// Check if the file is excluded
|
||||
// Check if the file is excluded.
|
||||
if ( $new_version ) {
|
||||
if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', wp_normalize_path( $file->getPathname() ) ) ) ) {
|
||||
$is_excluded = true;
|
||||
|
@ -824,88 +729,51 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
$is_excluded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip unreadable files
|
||||
// Skip unreadable files.
|
||||
if ( ! @realpath( $file->getPathname() ) || ! $file->isReadable() ) {
|
||||
$is_unreadable = true;
|
||||
}
|
||||
?>
|
||||
|
||||
<tr>
|
||||
|
||||
<td>
|
||||
|
||||
<?php if ( $is_unreadable ) { ?>
|
||||
|
||||
<div class="dashicons dashicons-dismiss"></div>
|
||||
|
||||
<?php } elseif ( $file->isFile() ) { ?>
|
||||
|
||||
<div class="dashicons dashicons-media-default"></div>
|
||||
|
||||
<?php } elseif ( $file->isDir() ) { ?>
|
||||
|
||||
<div class="dashicons dashicons-portfolio"></div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
if ( $new_version ) {
|
||||
if ( $is_unreadable ) {
|
||||
?>
|
||||
|
||||
<code class="strikethrough"
|
||||
title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
||||
|
||||
<code class="strikethrough" title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
||||
<?php } elseif ( $file->isFile() ) { ?>
|
||||
|
||||
<code
|
||||
title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
||||
|
||||
<code title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
||||
<?php } elseif ( $file->isDir() ) { ?>
|
||||
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a
|
||||
href="#"
|
||||
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( wp_normalize_path( $file->getPathname()) ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
|
||||
|
||||
|
||||
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo rawurlencode( wp_normalize_path( $file->getPathname() ) ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
if ( $is_unreadable ) {
|
||||
?>
|
||||
|
||||
<code class="strikethrough"
|
||||
title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
||||
|
||||
<code class="strikethrough" title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
||||
<?php } elseif ( $file->isFile() ) { ?>
|
||||
|
||||
<code
|
||||
title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
||||
|
||||
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
|
||||
<?php
|
||||
} elseif ( $file->isDir() ) {
|
||||
// echo add_query_arg( 'hmbkp_directory_browse', urlencode( $file->getPathname() ) );
|
||||
?>
|
||||
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a
|
||||
href="#"
|
||||
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( $file->getPathname() ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
|
||||
|
||||
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a href="#" onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo rawurlencode( $file->getPathname() ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
|
||||
<td class="column-format column-filesize">
|
||||
|
||||
<?php if ( $file->isDir() && $is_size_calculated ) : ?>
|
||||
|
||||
<span class="spinner"></span>
|
||||
|
||||
<?php
|
||||
else :
|
||||
if ( $new_version ) {
|
||||
|
@ -913,113 +781,65 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
} else {
|
||||
$size = $schedule->filesize( $file );
|
||||
}
|
||||
|
||||
if ( false !== $size ) {
|
||||
|
||||
$size = size_format( $size );
|
||||
|
||||
if ( ! $size ) {
|
||||
$size = '0 B';
|
||||
}
|
||||
?>
|
||||
|
||||
<code>
|
||||
|
||||
<?php echo esc_html( $size ); ?>
|
||||
|
||||
<?php if ( $file->isDir() ) { ?>
|
||||
|
||||
<a title="<?php esc_attr_e( 'Recalculate the size of this directory', 'backupwordpress' ); ?>"
|
||||
class="dashicons dashicons-update"
|
||||
href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', urlencode( wp_normalize_path( $file->getPathname() ) ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'backupwordpress' ); ?></span></a>
|
||||
|
||||
<a title="<?php esc_attr_e( 'Recalculate the size of this directory', 'maiwnp-child' ); ?>" class="dashicons dashicons-update" href="<?php echo esc_attr( wp_nonce_url( add_query_arg( 'hmbkp_recalculate_directory_filesize', rawurlencode( wp_normalize_path( $file->getPathname() ) ) ), 'hmbkp-recalculate_directory_filesize' ) ); ?>"><span><?php esc_html_e( 'Refresh', 'mainwp-child' ); ?></span></a>
|
||||
<?php } ?>
|
||||
|
||||
</code>
|
||||
|
||||
|
||||
<?php } else { ?>
|
||||
|
||||
<code>--</code>
|
||||
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
?>
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php echo esc_html( substr( sprintf( '%o', $file->getPerms() ), - 4 ) ); ?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
<?php if ( $file->isLink() ) : ?>
|
||||
|
||||
<span
|
||||
title="<?php echo esc_attr( wp_normalize_path( $file->GetRealPath() ) ); ?>"><?php esc_html_e( 'Symlink', 'backupwordpress' ); ?></span>
|
||||
|
||||
<span title="<?php echo esc_attr( wp_normalize_path( $file->GetRealPath() ) ); ?>"><?php esc_html_e( 'Symlink', 'mainwp-child' ); ?></span>
|
||||
<?php
|
||||
elseif ( $file->isDir() ) :
|
||||
|
||||
esc_html_e( 'Folder', 'backupwordpress' );
|
||||
|
||||
esc_html_e( 'Folder', 'mainwp-child' );
|
||||
else :
|
||||
|
||||
esc_html_e( 'File', 'backupwordpress' );
|
||||
|
||||
esc_html_e( 'File', 'mainwp-child' );
|
||||
endif;
|
||||
?>
|
||||
|
||||
</td>
|
||||
|
||||
<td class="column-format">
|
||||
|
||||
<?php if ( $is_unreadable ) : ?>
|
||||
|
||||
<strong
|
||||
title="<?php esc_attr_e( 'Unreadable files won\'t be backed up.', 'backupwordpress' ); ?>"><?php esc_html_e( 'Unreadable', 'backupwordpress' ); ?></strong>
|
||||
|
||||
<strong title="<?php esc_attr_e( 'Unreadable files won\'t be backed up.', 'mainwp-child' ); ?>"><?php esc_html_e( 'Unreadable', 'mainwp-child' ); ?></strong>
|
||||
<?php elseif ( $is_excluded ) : ?>
|
||||
|
||||
<strong><?php esc_html_e( 'Excluded', 'backupwordpress' ); ?></strong>
|
||||
|
||||
<strong><?php esc_html_e( 'Excluded', 'mainwp-child' ); ?></strong>
|
||||
<?php
|
||||
else :
|
||||
|
||||
$exclude_path = $file->getPathname();
|
||||
|
||||
// Excluded directories need to be trailingslashed
|
||||
// Excluded directories need to be trailingslashed.
|
||||
if ( $file->isDir() ) {
|
||||
$exclude_path = trailingslashit( wp_normalize_path( $file->getPathname() ) );
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<a href="#"
|
||||
onclick="event.preventDefault(); mainwp_backupwp_exclude_add_rule('<?php echo urlencode( $exclude_path ); ?>', this)"
|
||||
class="button-secondary"><?php esc_html_e( 'Exclude →', 'backupwordpress' ); ?></a>
|
||||
|
||||
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_exclude_add_rule('<?php echo rawurlencode( $exclude_path ); ?>', this)" class="button-secondary"><?php esc_html_e( 'Exclude →', 'mainwp-child' ); ?></a>
|
||||
<?php endif; ?>
|
||||
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<p class="submit">
|
||||
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_edit_exclude_done()"
|
||||
class="button-primary"><?php esc_html_e( 'Done', 'backupwordpress' ); ?></a>
|
||||
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_edit_exclude_done()" class="button-primary"><?php esc_html_e( 'Done', 'mainwp-child' ); ?></a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$output = ob_get_clean();
|
||||
$information['e'] = $output;
|
||||
|
@ -1040,19 +860,19 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
function hmbkp_add_exclude_rule() {
|
||||
|
||||
if ( ! isset( $_POST['exclude_pathname'] ) || empty( $_POST['exclude_pathname'] ) ) {
|
||||
return array( 'error' => __( 'Error: Empty exclude directory path.' ) );
|
||||
return array( 'error' => __( 'Empty exclude directory path.', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
$schedule_id = $this->check_schedule();
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) );
|
||||
|
||||
$exclude_rule = urldecode( $_POST['exclude_pathname'] );
|
||||
$exclude_rule = rawurldecode( $_POST['exclude_pathname'] );
|
||||
|
||||
$schedule->set_excludes( $exclude_rule, true );
|
||||
|
||||
$schedule->save();
|
||||
|
||||
$current_path = urldecode( $_POST['browse_dir'] );
|
||||
$current_path = rawurldecode( $_POST['browse_dir'] );
|
||||
|
||||
if ( empty( $current_path ) ) {
|
||||
$current_path = null;
|
||||
|
@ -1068,7 +888,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
function hmbkp_remove_exclude_rule() {
|
||||
|
||||
if ( ! isset( $_POST['remove_rule'] ) || empty( $_POST['remove_rule'] ) ) {
|
||||
return array( 'error' => __( 'Error: Empty exclude directory path.' ) );
|
||||
return array( 'error' => __( 'Empty exclude directory path.', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
$schedule_id = $this->check_schedule();
|
||||
|
@ -1077,7 +897,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
$excludes = $schedule->get_excludes();
|
||||
$exclude_rule_to_remove = stripslashes( sanitize_text_field( $_POST['remove_rule'] ) );
|
||||
|
||||
if ( method_exists($excludes, 'get_user_excludes') ) {
|
||||
if ( method_exists( $excludes, 'get_user_excludes' ) ) {
|
||||
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
|
||||
} else {
|
||||
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
|
||||
|
@ -1085,7 +905,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
$schedule->save();
|
||||
|
||||
$current_path = urldecode( $_POST['browse_dir'] );
|
||||
$current_path = rawurldecode( $_POST['browse_dir'] );
|
||||
|
||||
if ( empty( $current_path ) ) {
|
||||
$current_path = null;
|
||||
|
@ -1105,41 +925,40 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
$sch_id = $this->check_schedule();
|
||||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
||||
|
||||
$exclude_paths = urldecode( $_POST['exclude_paths'] );
|
||||
$exclude_paths = rawurldecode( $_POST['exclude_paths'] );
|
||||
$exclude_paths = explode("\n", $exclude_paths);
|
||||
if ( is_array($exclude_paths) && count($exclude_paths) > 0 ) {
|
||||
if ( is_array( $exclude_paths ) && count( $exclude_paths ) > 0 ) {
|
||||
foreach ( $exclude_paths as $excl_rule ) {
|
||||
$excl_rule = trim($excl_rule);
|
||||
$excl_rule = trim($excl_rule, '/');
|
||||
$excl_rule = trim( $excl_rule );
|
||||
$excl_rule = trim( $excl_rule, '/' );
|
||||
|
||||
if ( empty($excl_rule) ) {
|
||||
if ( empty( $excl_rule ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$exclude_rule = ABSPATH . $excl_rule;
|
||||
$path = realpath($exclude_rule);
|
||||
// If it exist
|
||||
if ( $path !== false ) {
|
||||
$path = realpath( $exclude_rule );
|
||||
if ( false !== $path ) {
|
||||
$schedule->set_excludes( $exclude_rule, true );
|
||||
$schedule->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$un_exclude_paths = urldecode( $_POST['un_exclude_paths'] );
|
||||
$un_exclude_paths = explode("\n", $un_exclude_paths);
|
||||
$un_exclude_paths = rawurldecode( $_POST['un_exclude_paths'] );
|
||||
$un_exclude_paths = explode( "\n", $un_exclude_paths );
|
||||
|
||||
if ( is_array($un_exclude_paths) && count(get_user_excludes) > 0 ) {
|
||||
if ( is_array( $un_exclude_paths ) && count( get_user_excludes ) > 0 ) {
|
||||
foreach ( $un_exclude_paths as $exclude_rule_to_remove ) {
|
||||
$exclude_rule_to_remove = trim($exclude_rule_to_remove);
|
||||
$exclude_rule_to_remove = trim($exclude_rule_to_remove, '/');
|
||||
$exclude_rule_to_remove = trim( $exclude_rule_to_remove );
|
||||
$exclude_rule_to_remove = trim( $exclude_rule_to_remove, '/' );
|
||||
|
||||
if ( empty($exclude_rule_to_remove) ) {
|
||||
if ( empty( $exclude_rule_to_remove ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$excludes = $schedule->get_excludes();
|
||||
if ( method_exists($excludes, 'get_user_excludes') ) {
|
||||
if ( method_exists( $excludes, 'get_user_excludes' ) ) {
|
||||
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
|
||||
} else {
|
||||
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
|
||||
|
@ -1154,19 +973,13 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
|
||||
function update_schedule() {
|
||||
$sch_id = isset( $_POST['schedule_id'] ) ? $_POST['schedule_id'] : 0;
|
||||
$sch_id = sanitize_text_field( urldecode( $sch_id ) );
|
||||
$options = isset( $_POST['options'] ) ? maybe_unserialize( base64_decode( $_POST['options'] ) ) : false;
|
||||
$sch_id = sanitize_text_field( rawurldecode( $sch_id ) );
|
||||
$options = isset( $_POST['options'] ) ? maybe_unserialize( base64_decode( $_POST['options'] ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
|
||||
|
||||
if ( ! is_array( $options ) || empty( $options ) || empty( $sch_id ) ) {
|
||||
return array( 'error' => 'Error: Schedule data' );
|
||||
return array( 'error' => __( 'Schedule data', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
// $current_value = get_option( 'hmbkp_schedule_' . $sch_id );
|
||||
// if ( is_array( $current_value ) && isset( $current_value['excludes'] ) ) {
|
||||
// do not update 'excludes' value
|
||||
// $options['excludes'] = $current_value['excludes'];
|
||||
// }
|
||||
|
||||
$filter_opts = array(
|
||||
'type',
|
||||
'email',
|
||||
|
@ -1196,7 +1009,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
||||
|
||||
if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) {
|
||||
// Calculate the start time depending on the recurrence
|
||||
// Calculate the start time depending on the recurrence.
|
||||
$start_time = $options['schedule_start_time'];
|
||||
if ( $start_time ) {
|
||||
$schedule->set_schedule_start_time( $start_time );
|
||||
|
@ -1212,15 +1025,15 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
}
|
||||
|
||||
public function save_all_schedules() {
|
||||
$schedules = isset( $_POST['all_schedules'] ) ? maybe_unserialize( base64_decode( $_POST['all_schedules'] ) ) : false;
|
||||
$schedules = isset( $_POST['all_schedules'] ) ? maybe_unserialize( base64_decode( $_POST['all_schedules'] ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
|
||||
|
||||
if ( ! is_array( $schedules ) || empty( $schedules ) ) {
|
||||
return array( 'error' => 'Error: Schedule data' );
|
||||
return array( 'error' => __( 'Schedule data', 'mainwp-child' ) );
|
||||
}
|
||||
|
||||
$out = array();
|
||||
foreach ( $schedules as $sch_id => $sch ) {
|
||||
if ( empty($sch_id) || ! isset( $sch['options'] ) || ! is_array( $sch['options'] ) ) {
|
||||
if ( empty( $sch_id ) || ! isset( $sch['options'] ) || ! is_array( $sch['options'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$options = $sch['options'];
|
||||
|
@ -1246,7 +1059,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
|
||||
|
||||
if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) {
|
||||
// Calculate the start time depending on the recurrence
|
||||
// Calculate the start time depending on the recurrence.
|
||||
$start_time = $options['schedule_start_time'];
|
||||
if ( $start_time ) {
|
||||
$schedule->set_schedule_start_time( $start_time );
|
||||
|
@ -1258,7 +1071,7 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
}
|
||||
$out['result'] = 'SUCCESS';
|
||||
}
|
||||
delete_transient( 'hmbkp_schedules' );
|
||||
delete_transient( 'hmbkp_schedules' );
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
@ -1300,4 +1113,3 @@ class MainWP_Child_Back_Up_Wordpress {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue