Fixed: CodeFactor issues

This commit is contained in:
Bogdan Rapaić 2020-04-16 16:10:09 +02:00 committed by GitHub
parent 3ce0b519f2
commit 1df25aa2cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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' );
@ -201,9 +197,8 @@ class MainWP_Child_Back_Up_Wordpress {
}
}
// ok
public function do_reports_log( $ext = '' ) {
if ( $ext !== 'backupwordpress' ) {
if ( 'backupwordpress' !== $ext ) {
return;
}
if ( ! $this->is_plugin_installed ) {
@ -214,7 +209,7 @@ class MainWP_Child_Back_Up_Wordpress {
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 ) {
@ -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,9 +260,9 @@ 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
// 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,7 +296,7 @@ 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' ) ) {
$information['scheduleStatus'] = $schedule->get_status();
@ -321,7 +316,7 @@ class MainWP_Child_Back_Up_Wordpress {
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();
@ -351,7 +346,7 @@ class MainWP_Child_Back_Up_Wordpress {
continue;
}
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
$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 ),
@ -378,7 +373,7 @@ 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
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,
@ -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() );
@ -451,9 +446,9 @@ 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 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 } ?>
@ -498,21 +493,21 @@ 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 ( ( '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&hellip;', 'mainwp-backupwordpress-extension' ) . '">' . __( 'calculating the size of your backup&hellip;', 'mainwp-backupwordpress-extension' ) . '</code>)' );
return sprintf( '(<code class="calculating" title="' . __( 'this shouldn\'t take long&hellip;', 'mainwp-child' ) . '">' . __( 'calculating the size of your backup&hellip;', '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;
?>
@ -537,7 +532,7 @@ class MainWP_Child_Back_Up_Wordpress {
?>
<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' ) ) {
@ -545,7 +540,7 @@ class MainWP_Child_Back_Up_Wordpress {
?>
<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,7 +560,7 @@ 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' ) ) {
@ -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,60 +603,38 @@ 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' ) ) {
$files = HM\BackUpWordPress\list_directory_by_total_filesize( $directory, $excludes );
}
@ -691,130 +642,84 @@ class MainWP_Child_Back_Up_Wordpress {
$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>
<?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>
<?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 &rarr;', '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 &rarr;', '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();
@ -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,7 +925,7 @@ 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 ) {
foreach ( $exclude_paths as $excl_rule ) {
@ -1118,15 +938,14 @@ class MainWP_Child_Back_Up_Wordpress {
$exclude_rule = ABSPATH . $excl_rule;
$path = realpath( $exclude_rule );
// If it exist
if ( $path !== false ) {
if ( false !== $path ) {
$schedule->set_excludes( $exclude_rule, true );
$schedule->save();
}
}
}
$un_exclude_paths = urldecode( $_POST['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 ) {
@ -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,10 +1025,10 @@ 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();
@ -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 );
@ -1300,4 +1113,3 @@ class MainWP_Child_Back_Up_Wordpress {
}
}
}