Fixed: CodeFactor issues

This commit is contained in:
Bogdan Rapaić 2020-04-23 19:53:22 +02:00 committed by GitHub
parent 87598c8c19
commit 049dab6b55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 223 additions and 223 deletions

View file

@ -87,9 +87,9 @@ class MainWP_Backup {
$this->timeout = 20 * 60 * 60; $this->timeout = 20 * 60 * 60;
$mem = '512M'; $mem = '512M';
// phpcs:disable // phpcs:disable
@ini_set( 'memory_limit', $mem ); ini_set( 'memory_limit', $mem );
@set_time_limit( $this->timeout ); set_time_limit( $this->timeout );
@ini_set( 'max_execution_time', $this->timeout ); ini_set( 'max_execution_time', $this->timeout );
// phpcs:enable // phpcs:enable
if ( null !== $this->archiver ) { if ( null !== $this->archiver ) {
@ -113,9 +113,9 @@ class MainWP_Backup {
$this->timeout = 20 * 60 * 60; $this->timeout = 20 * 60 * 60;
$mem = '512M'; $mem = '512M';
// phpcs:disable // phpcs:disable
@ini_set( 'memory_limit', $mem ); ini_set( 'memory_limit', $mem );
@set_time_limit( $this->timeout ); set_time_limit( $this->timeout );
@ini_set( 'max_execution_time', $this->timeout ); ini_set( 'max_execution_time', $this->timeout );
// phpcs:enable // phpcs:enable
if ( ! is_array( $files ) ) { if ( ! is_array( $files ) ) {
@ -276,9 +276,9 @@ class MainWP_Backup {
$plugins = array(); $plugins = array();
$dir = WP_CONTENT_DIR . '/plugins/'; $dir = WP_CONTENT_DIR . '/plugins/';
// phpcs:disable // phpcs:disable
$fh = @opendir( $dir ); $fh = opendir( $dir );
while ( $entry = @readdir( $fh ) ) { while ( $entry = readdir( $fh ) ) {
if ( ! @is_dir( $dir . $entry ) ) { if ( ! is_dir( $dir . $entry ) ) {
continue; continue;
} }
if ( ( '.' == $entry ) || ( '..' == $entry ) ) { if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
@ -286,15 +286,15 @@ class MainWP_Backup {
} }
$plugins[] = $entry; $plugins[] = $entry;
} }
@closedir( $fh ); closedir( $fh );
// phpcs:enable // phpcs:enable
$themes = array(); $themes = array();
$dir = WP_CONTENT_DIR . '/themes/'; $dir = WP_CONTENT_DIR . '/themes/';
// phpcs:disable // phpcs:disable
$fh = @opendir( $dir ); $fh = opendir( $dir );
while ( $entry = @readdir( $fh ) ) { while ( $entry = readdir( $fh ) ) {
if ( ! @is_dir( $dir . $entry ) ) { if ( ! is_dir( $dir . $entry ) ) {
continue; continue;
} }
if ( ( '.' == $entry ) || ( '..' == $entry ) ) { if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
@ -302,7 +302,7 @@ class MainWP_Backup {
} }
$themes[] = $entry; $themes[] = $entry;
} }
@closedir( $fh ); closedir( $fh );
// phpcs:enable // phpcs:enable
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. $string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
@ -324,7 +324,7 @@ class MainWP_Backup {
$return = $this->zip->close(); $return = $this->zip->close();
foreach ( $db_files as $db_file ) { foreach ( $db_files as $db_file ) {
@unlink( $db_file ); unlink( $db_file );
} }
return true; return true;
@ -394,7 +394,7 @@ class MainWP_Backup {
} }
foreach ( $db_files as $db_file ) { foreach ( $db_files as $db_file ) {
@unlink( $db_file ); unlink( $db_file );
} }
if ( ! $error ) { if ( ! $error ) {
foreach ( $nodes as $node ) { foreach ( $nodes as $node ) {
@ -433,7 +433,7 @@ class MainWP_Backup {
} }
if ( $error ) { if ( $error ) {
@unlink( $filepath ); // phpcs:ignore unlink( $filepath ); // phpcs:ignore
return false; return false;
} }
@ -456,7 +456,7 @@ class MainWP_Backup {
if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) { if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
if ( is_dir( $node ) ) { if ( is_dir( $node ) ) {
if ( ! file_exists( str_replace( ABSPATH, $backupfolder, $node ) ) ) { if ( ! file_exists( str_replace( ABSPATH, $backupfolder, $node ) ) ) {
@mkdir( str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore mkdir( str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore
} }
$newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' ); $newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' );
@ -467,7 +467,7 @@ class MainWP_Backup {
continue; continue;
} }
@copy( $node, str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore copy( $node, str_replace( ABSPATH, $backupfolder, $node ) ); // phpcs:ignore
} }
} }
} }
@ -477,7 +477,7 @@ class MainWP_Backup {
// Create backup folder. // Create backup folder.
$backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR; $backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR;
@mkdir( $backupFolder ); // phpcs:ignore mkdir( $backupFolder ); // phpcs:ignore
// Create DB backup. // Create DB backup.
$db_files = $this->createBackupDB( $backupFolder . 'dbBackup' ); $db_files = $this->createBackupDB( $backupFolder . 'dbBackup' );
@ -526,8 +526,8 @@ class MainWP_Backup {
$this->copy_dir( $nodes, $excludes, $backupFolder, $excludenonwp, true ); $this->copy_dir( $nodes, $excludes, $backupFolder, $excludenonwp, true );
foreach ( $db_files as $db_file ) { foreach ( $db_files as $db_file ) {
@copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); // phpcs:ignore copy( $db_file, $backupFolder . basename( WP_CONTENT_DIR ) . '/' . basename( $db_file ) ); // phpcs:ignore
@unlink( $db_file ); // phpcs:ignore unlink( $db_file ); // phpcs:ignore
} }
unset( $nodes ); unset( $nodes );
@ -649,7 +649,7 @@ class MainWP_Backup {
public function addFileToZip( $path, $zipEntryName ) { public function addFileToZip( $path, $zipEntryName ) {
if ( time() - $this->lastRun > 20 ) { if ( time() - $this->lastRun > 20 ) {
@set_time_limit( $this->timeout ); // phpcs:ignore set_time_limit( $this->timeout ); // phpcs:ignore
$this->lastRun = time(); $this->lastRun = time();
} }
@ -675,10 +675,10 @@ class MainWP_Backup {
if ( $this->gcCnt > 20 ) { if ( $this->gcCnt > 20 ) {
if ( function_exists( 'gc_enable' ) ) { if ( function_exists( 'gc_enable' ) ) {
@gc_enable(); // phpcs:ignore gc_enable();
} }
if ( function_exists( 'gc_collect_cycles' ) ) { if ( function_exists( 'gc_collect_cycles' ) ) {
@gc_collect_cycles(); // phpcs:ignore gc_collect_cycles();
} }
$this->gcCnt = 0; $this->gcCnt = 0;
} }
@ -688,10 +688,10 @@ class MainWP_Backup {
$this->zip = null; $this->zip = null;
unset( $this->zip ); unset( $this->zip );
if ( function_exists( 'gc_enable' ) ) { if ( function_exists( 'gc_enable' ) ) {
@gc_enable(); // phpcs:ignore gc_enable();
} }
if ( function_exists( 'gc_collect_cycles' ) ) { if ( function_exists( 'gc_collect_cycles' ) ) {
@gc_collect_cycles(); // phpcs:ignore gc_collect_cycles();
} }
$this->zip = new ZipArchive(); $this->zip = new ZipArchive();
$this->zip->open( $this->zipArchiveFileName ); $this->zip->open( $this->zipArchiveFileName );
@ -708,10 +708,10 @@ class MainWP_Backup {
public function createBackupDB( $filepath_prefix, $archiveExt = false, &$archiver = null ) { public function createBackupDB( $filepath_prefix, $archiveExt = false, &$archiver = null ) {
$timeout = 20 * 60 * 60; $timeout = 20 * 60 * 60;
@set_time_limit( $timeout ); // phpcs:ignore set_time_limit( $timeout );
@ini_set( 'max_execution_time', $timeout ); // phpcs:ignore ini_set( 'max_execution_time', $timeout );
$mem = '512M'; $mem = '512M';
@ini_set( 'memory_limit', $mem ); // phpcs:ignore ini_set( 'memory_limit', $mem );
/** @var $wpdb wpdb */ /** @var $wpdb wpdb */
global $wpdb; global $wpdb;
@ -736,7 +736,7 @@ class MainWP_Backup {
$table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); $table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N );
fwrite( $fh, "\n" . $table_create[1] . ";\n\n" ); fwrite( $fh, "\n" . $table_create[1] . ";\n\n" );
$rows = @MainWP_Child_DB::_query( 'SELECT * FROM ' . $table, $wpdb->dbh ); // phpcs:ignore $rows = MainWP_Child_DB::_query( 'SELECT * FROM ' . $table, $wpdb->dbh );
if ( $rows ) { if ( $rows ) {
$i = 0; $i = 0;
@ -788,7 +788,7 @@ class MainWP_Backup {
if ( $this->zipFile( $db_files, $archivefilePath ) && file_exists( $archivefilePath ) ) { if ( $this->zipFile( $db_files, $archivefilePath ) && file_exists( $archivefilePath ) ) {
foreach ( $db_files as $db_file ) { foreach ( $db_files as $db_file ) {
@unlink( $db_file ); unlink( $db_file );
} }
} else { } else {
// todo: throw exception! // todo: throw exception!

View file

@ -709,7 +709,7 @@ class MainWP_Child_Back_Up_Buddy {
$deleted_files = array(); $deleted_files = array();
foreach ( $item_ids as $item ) { foreach ( $item_ids as $item ) {
if ( file_exists( backupbuddy_core::getBackupDirectory() . $item ) ) { if ( file_exists( backupbuddy_core::getBackupDirectory() . $item ) ) {
if ( @unlink( backupbuddy_core::getBackupDirectory() . $item ) === true ) { if ( unlink( backupbuddy_core::getBackupDirectory() . $item ) === true ) {
$deleted_files[] = $item; $deleted_files[] = $item;
// Cleanup any related fileoptions files. // Cleanup any related fileoptions files.
@ -723,10 +723,10 @@ class MainWP_Child_Back_Up_Buddy {
$this_serial = backupbuddy_core::get_serial_from_file( $item ); $this_serial = backupbuddy_core::get_serial_from_file( $item );
$fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $this_serial . '.txt'; $fileoptions_file = backupbuddy_core::getLogDirectory() . 'fileoptions/' . $this_serial . '.txt';
if ( file_exists( $fileoptions_file ) ) { if ( file_exists( $fileoptions_file ) ) {
@unlink( $fileoptions_file ); unlink( $fileoptions_file );
} }
if ( file_exists( $fileoptions_file . '.lock' ) ) { if ( file_exists( $fileoptions_file . '.lock' ) ) {
@unlink( $fileoptions_file . '.lock' ); unlink( $fileoptions_file . '.lock' );
} }
$needs_save = true; $needs_save = true;
} }
@ -1784,7 +1784,7 @@ class MainWP_Child_Back_Up_Buddy {
if ( '1' == pb_backupbuddy::$options['lock_archives_directory'] ) { if ( '1' == pb_backupbuddy::$options['lock_archives_directory'] ) {
if ( file_exists( backupbuddy_core::getBackupDirectory() . '.htaccess' ) ) { if ( file_exists( backupbuddy_core::getBackupDirectory() . '.htaccess' ) ) {
$unlink_status = @unlink( backupbuddy_core::getBackupDirectory() . '.htaccess' ); $unlink_status = unlink( backupbuddy_core::getBackupDirectory() . '.htaccess' );
if ( false === $unlink_status ) { if ( false === $unlink_status ) {
die( 'Error #844594. Unable to temporarily remove .htaccess security protection on archives directory to allow downloading. Please verify permissions of the BackupBuddy archives directory or manually download via FTP.' ); die( 'Error #844594. Unable to temporarily remove .htaccess security protection on archives directory to allow downloading. Please verify permissions of the BackupBuddy archives directory or manually download via FTP.' );
} }
@ -1795,7 +1795,7 @@ class MainWP_Child_Back_Up_Buddy {
flush(); flush();
sleep( 8 ); sleep( 8 );
$htaccess_creation_status = @file_put_contents( backupbuddy_core::getBackupDirectory() . '.htaccess', 'deny from all' ); $htaccess_creation_status = file_put_contents( backupbuddy_core::getBackupDirectory() . '.htaccess', 'deny from all' );
if ( false === $htaccess_creation_status ) { if ( false === $htaccess_creation_status ) {
die( 'Error #344894545. Security Warning! Unable to create security file (.htaccess) in backups archive directory. This file prevents unauthorized downloading of backups should someone be able to guess the backup location and filenames. This is unlikely but for best security should be in place. Please verify permissions on the backups directory.' ); die( 'Error #344894545. Security Warning! Unable to create security file (.htaccess) in backups archive directory. This file prevents unauthorized downloading of backups should someone be able to guess the backup location and filenames. This is unlikely but for best security should be in place. Please verify permissions on the backups directory.' );
} }
@ -2059,7 +2059,7 @@ class MainWP_Child_Back_Up_Buddy {
} elseif ( 'reset_log' == $other_action ) { } elseif ( 'reset_log' == $other_action ) {
$log_file = backupbuddy_core::getLogDirectory() . 'log-' . pb_backupbuddy::$options['log_serial'] . '.txt'; $log_file = backupbuddy_core::getLogDirectory() . 'log-' . pb_backupbuddy::$options['log_serial'] . '.txt';
if ( file_exists( $log_file ) ) { if ( file_exists( $log_file ) ) {
@unlink( $log_file ); unlink( $log_file );
} }
if ( file_exists( $log_file ) ) { // Didnt unlink. if ( file_exists( $log_file ) ) { // Didnt unlink.
$error = 'Unable to clear log file. Please verify permissions on file `' . $log_file . '`.'; $error = 'Unable to clear log file. Please verify permissions on file `' . $log_file . '`.';
@ -2624,7 +2624,7 @@ class MainWP_Child_Back_Up_Buddy {
if ( 'clear_log' == $action ) { if ( 'clear_log' == $action ) {
$sumLogFile = backupbuddy_core::getLogDirectory() . 'status-live_periodic_' . pb_backupbuddy::$options['log_serial'] . '.txt'; $sumLogFile = backupbuddy_core::getLogDirectory() . 'status-live_periodic_' . pb_backupbuddy::$options['log_serial'] . '.txt';
@unlink( $sumLogFile ); unlink( $sumLogFile );
if ( file_exists( $sumLogFile ) ) { if ( file_exists( $sumLogFile ) ) {
$error = 'Error #893489322: Unable to clear log file `' . $sumLogFile . '`. Check permissions or manually delete.'; $error = 'Error #893489322: Unable to clear log file `' . $sumLogFile . '`. Check permissions or manually delete.';
} else { } else {

View file

@ -222,7 +222,7 @@ class MainWP_Child_Back_Up_Wordpress {
$message = 'BackupWordpres backup ' . $backup_type . ' finished'; $message = 'BackupWordpres backup ' . $backup_type . ' finished';
$destination = 'N/A'; $destination = 'N/A';
if ( file_exists( $file ) ) { if ( file_exists( $file ) ) {
$date = @filemtime( $file ); $date = filemtime( $file );
if ( ! empty( $date ) ) { if ( ! empty( $date ) ) {
do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $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.
@ -494,10 +494,10 @@ class MainWP_Child_Back_Up_Wordpress {
?> ?>
<tr class="hmbkp_manage_backups_row"> <tr class="hmbkp_manage_backups_row">
<th scope="row"> <th scope="row">
<?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' - ' . get_option( 'time_format' ), @filemtime( $file ) + $offset ) ); ?> <?php echo esc_html( date_i18n( get_option( 'date_format' ) . ' - ' . get_option( 'time_format' ), filemtime( $file ) + $offset ) ); ?>
</th> </th>
<td class="code"> <td class="code">
<?php echo esc_html( size_format( @filesize( $file ) ) ); ?> <?php echo esc_html( size_format( filesize( $file ) ) ); ?>
</td> </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> <td>
@ -696,7 +696,7 @@ class MainWP_Child_Back_Up_Wordpress {
} }
} }
// Skip unreadable files. // Skip unreadable files.
if ( ! @realpath( $file->getPathname() ) || ! $file->isReadable() ) { if ( ! realpath( $file->getPathname() ) || ! $file->isReadable() ) {
$is_unreadable = true; $is_unreadable = true;
} }
?> ?>

View file

@ -509,7 +509,7 @@ class MainWP_Child_Back_WP_Up {
echo '<tr title="&gt;=128M"><td>' . __( 'PHP Memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( ini_get( 'memory_limit' ) ) . '</td></tr>'; echo '<tr title="&gt;=128M"><td>' . __( 'PHP Memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( ini_get( 'memory_limit' ) ) . '</td></tr>';
echo '<tr title="WP_MEMORY_LIMIT"><td>' . __( 'WP memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( WP_MEMORY_LIMIT ) . '</td></tr>'; echo '<tr title="WP_MEMORY_LIMIT"><td>' . __( 'WP memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( WP_MEMORY_LIMIT ) . '</td></tr>';
echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __( 'WP maximum memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( WP_MAX_MEMORY_LIMIT ) . '</td></tr>'; echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __( 'WP maximum memory limit', 'mainwp-child' ) . '</td><td>' . esc_html( WP_MAX_MEMORY_LIMIT ) . '</td></tr>';
echo '<tr title=""><td>' . __( 'Memory in use', 'mainwp-child' ) . '</td><td>' . esc_html( size_format( @memory_get_usage( true ), 2 ) ) . '</td></tr>'; echo '<tr title=""><td>' . __( 'Memory in use', 'mainwp-child' ) . '</td><td>' . esc_html( size_format( memory_get_usage( true ), 2 ) ) . '</td></tr>';
$disabled = ini_get( 'disable_functions' ); $disabled = ini_get( 'disable_functions' );
if ( ! empty( $disabled ) ) { if ( ! empty( $disabled ) ) {
@ -1159,7 +1159,7 @@ class MainWP_Child_Back_WP_Up {
$main_folder_name = untrailingslashit( str_replace( '\\', '/', $main_folder_name ) ); $main_folder_name = untrailingslashit( str_replace( '\\', '/', $main_folder_name ) );
$main_folder_size = '(' . size_format( BackWPup_File::get_folder_size( $main_folder_name, false ), 2 ) . ')'; $main_folder_size = '(' . size_format( BackWPup_File::get_folder_size( $main_folder_name, false ), 2 ) . ')';
$dir = @opendir( $main_folder_name ); $dir = opendir( $main_folder_name );
if ( $dir ) { if ( $dir ) {
while ( false !== ( $file = readdir( $dir ) ) ) { while ( false !== ( $file = readdir( $dir ) ) ) {
if ( ! in_array( $file, array( '.', '..' ) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) ) ) { if ( ! in_array( $file, array( '.', '..' ) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) ) ) {
@ -1172,7 +1172,7 @@ class MainWP_Child_Back_WP_Up {
} }
} }
@closedir( $dir ); closedir( $dir );
} }
$return[ $key ] = array( $return[ $key ] = array(
@ -1197,7 +1197,7 @@ class MainWP_Child_Back_WP_Up {
$settings = $_POST['settings']; $settings = $_POST['settings'];
if ( ! empty( $settings['dbhost'] ) && ! empty( $settings['dbuser'] ) ) { if ( ! empty( $settings['dbhost'] ) && ! empty( $settings['dbuser'] ) ) {
$mysqli = @new mysqli( $settings['dbhost'], $settings['dbuser'], ( isset( $settings['dbpassword'] ) ? $settings['dbpassword'] : '' ) ); $mysqli = new mysqli( $settings['dbhost'], $settings['dbuser'], ( isset( $settings['dbpassword'] ) ? $settings['dbpassword'] : '' ) );
if ( $mysqli->connect_error ) { if ( $mysqli->connect_error ) {
$return['message'] = $mysqli->connect_error; $return['message'] = $mysqli->connect_error;

View file

@ -253,7 +253,7 @@ class MainWP_Child_Branding {
if ( isset( $current_extra_setting['login_image']['path'] ) ) { if ( isset( $current_extra_setting['login_image']['path'] ) ) {
$old_file = $current_extra_setting['login_image']['path']; $old_file = $current_extra_setting['login_image']['path'];
if ( ! empty( $old_file ) && file_exists( $old_file ) ) { if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
@unlink( $old_file ); unlink( $old_file );
} }
} }
} }
@ -279,7 +279,7 @@ class MainWP_Child_Branding {
if ( isset( $current_extra_setting['favico_image']['path'] ) ) { if ( isset( $current_extra_setting['favico_image']['path'] ) ) {
$old_file = $current_extra_setting['favico_image']['path']; $old_file = $current_extra_setting['favico_image']['path'];
if ( ! empty( $old_file ) && file_exists( $old_file ) ) { if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
@unlink( $old_file ); unlink( $old_file );
} }
} }
} }
@ -325,7 +325,7 @@ class MainWP_Child_Branding {
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); $local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url );
$local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) ); $local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path ); $local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
$moved = @rename( $temporary_file, $local_img_path ); $moved = rename( $temporary_file, $local_img_path );
if ( $moved ) { if ( $moved ) {
return array( return array(
'path' => $local_img_path, 'path' => $local_img_path,

View file

@ -1097,8 +1097,8 @@ class MainWP_Child_Server_Information {
$conf = array( 'private_key_bits' => 2048 ); $conf = array( 'private_key_bits' => 2048 );
$str = ''; $str = '';
if ( function_exists( 'openssl_pkey_new' ) ) { if ( function_exists( 'openssl_pkey_new' ) ) {
$res = @openssl_pkey_new( $conf ); $res = openssl_pkey_new( $conf );
@openssl_pkey_export( $res, $privkey ); openssl_pkey_export( $res, $privkey );
$str = openssl_error_string(); $str = openssl_error_string();
} }
@ -1537,15 +1537,15 @@ class MainWP_Child_Server_Information {
<div style="padding: 1em;"> <div style="padding: 1em;">
<?php <?php
if ( file_exists( ABSPATH . 'wp-config.php' ) ) { if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
@show_source( ABSPATH . 'wp-config.php' ); show_source( ABSPATH . 'wp-config.php' );
} else { } else {
$files = @get_included_files(); $files = get_included_files();
$configFound = false; $configFound = false;
if ( is_array( $files ) ) { if ( is_array( $files ) ) {
foreach ( $files as $file ) { foreach ( $files as $file ) {
if ( stristr( $file, 'wp-config.php' ) ) { if ( stristr( $file, 'wp-config.php' ) ) {
$configFound = true; $configFound = true;
@show_source( $file ); show_source( $file );
break; break;
} }
} }
@ -1565,7 +1565,7 @@ class MainWP_Child_Server_Information {
?> ?>
<div class="postbox" id="mainwp-code-display"> <div class="postbox" id="mainwp-code-display">
<h3 class="hndle" style="padding: 8px 12px; font-size: 14px;"><span><?php _e( '.htaccess', 'mainwp-child' ); ?></span></h3> <h3 class="hndle" style="padding: 8px 12px; font-size: 14px;"><span><?php _e( '.htaccess', 'mainwp-child' ); ?></span></h3>
<div style="padding: 1em;"><?php @show_source( ABSPATH . '.htaccess' ); ?></div> <div style="padding: 1em;"><?php show_source( ABSPATH . '.htaccess' ); ?></div>
</div> </div>
<?php <?php
} }

View file

@ -341,7 +341,7 @@ class MainWP_Child_Staging {
if ( ! function_exists( 'disk_free_space' ) ) { if ( ! function_exists( 'disk_free_space' ) ) {
return null; return null;
} }
$freeSpace = @disk_free_space( ABSPATH ); $freeSpace = disk_free_space( ABSPATH );
if ( false === $freeSpace ) { if ( false === $freeSpace ) {
$data = array( $data = array(
'freespace' => false, 'freespace' => false,

View file

@ -1181,7 +1181,7 @@ class MainWP_Child_Timecapsule {
echo '<tr title="&gt;=128M"><td>' . __( 'PHP Memory limit', 'wp-time-capsule' ) . '</td><td>' . esc_html( ini_get( 'memory_limit' ) ) . '</td></tr>'; echo '<tr title="&gt;=128M"><td>' . __( 'PHP Memory limit', 'wp-time-capsule' ) . '</td><td>' . esc_html( ini_get( 'memory_limit' ) ) . '</td></tr>';
echo '<tr title="WP_MEMORY_LIMIT"><td>' . __( 'WP memory limit', 'wp-time-capsule' ) . '</td><td>' . esc_html( WP_MEMORY_LIMIT ) . '</td></tr>'; echo '<tr title="WP_MEMORY_LIMIT"><td>' . __( 'WP memory limit', 'wp-time-capsule' ) . '</td><td>' . esc_html( WP_MEMORY_LIMIT ) . '</td></tr>';
echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __( 'WP maximum memory limit', 'wp-time-capsule' ) . '</td><td>' . esc_html( WP_MAX_MEMORY_LIMIT ) . '</td></tr>'; echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __( 'WP maximum memory limit', 'wp-time-capsule' ) . '</td><td>' . esc_html( WP_MAX_MEMORY_LIMIT ) . '</td></tr>';
echo '<tr title=""><td>' . __( 'Memory in use', 'wp-time-capsule' ) . '</td><td>' . size_format( @memory_get_usage( true ), 2 ) . '</td></tr>'; echo '<tr title=""><td>' . __( 'Memory in use', 'wp-time-capsule' ) . '</td><td>' . size_format( memory_get_usage( true ), 2 ) . '</td></tr>';
// disabled PHP functions. // disabled PHP functions.
$disabled = esc_html( ini_get( 'disable_functions' ) ); $disabled = esc_html( ini_get( 'disable_functions' ) );

View file

@ -1271,7 +1271,7 @@ class MainWP_Child_Updraft_Plus_Backups {
} }
foreach ( $files as $file ) { foreach ( $files as $file ) {
if ( is_file( $updraft_dir . '/' . $file ) ) { if ( is_file( $updraft_dir . '/' . $file ) ) {
if ( @unlink( $updraft_dir . '/' . $file ) ) { if ( unlink( $updraft_dir . '/' . $file ) ) {
$local_deleted ++; $local_deleted ++;
} }
} }
@ -1379,7 +1379,7 @@ class MainWP_Child_Updraft_Plus_Backups {
public function updraft_download_backup() { public function updraft_download_backup() {
@set_time_limit( 900 ); set_time_limit( 900 );
global $updraftplus; global $updraftplus;
@ -1442,7 +1442,7 @@ class MainWP_Child_Updraft_Plus_Backups {
} }
if ( isset( $_POST['stage'] ) && 'delete' == $_POST['stage'] ) { if ( isset( $_POST['stage'] ) && 'delete' == $_POST['stage'] ) {
@unlink( $fullpath ); unlink( $fullpath );
$updraftplus->log( 'The file has been deleted' ); $updraftplus->log( 'The file has been deleted' );
return 'deleted'; return 'deleted';
@ -1502,8 +1502,8 @@ class MainWP_Child_Updraft_Plus_Backups {
$is_downloaded = true; $is_downloaded = true;
} else { } else {
clearstatcache(); clearstatcache();
if ( 0 === @filesize( $fullpath ) ) { if ( 0 === filesize( $fullpath ) ) {
@unlink( $fullpath ); unlink( $fullpath );
} }
$updraftplus->log( 'Remote fetch failed' ); $updraftplus->log( 'Remote fetch failed' );
} }
@ -1525,9 +1525,9 @@ class MainWP_Child_Updraft_Plus_Backups {
restore_error_handler(); restore_error_handler();
@fclose( $updraftplus->logfile_handle ); fclose( $updraftplus->logfile_handle );
if ( ! $debug_mode ) { if ( ! $debug_mode ) {
@unlink( $updraftplus->logfile_name ); unlink( $updraftplus->logfile_name );
} }
return array( 'result' => 'OK' ); return array( 'result' => 'OK' );
@ -1538,7 +1538,7 @@ class MainWP_Child_Updraft_Plus_Backups {
global $updraftplus; global $updraftplus;
@set_time_limit( 900 ); set_time_limit( 900 );
$updraftplus->log( "Requested file from remote service: $service: $file" ); $updraftplus->log( "Requested file from remote service: $service: $file" );
@ -1604,8 +1604,8 @@ class MainWP_Child_Updraft_Plus_Backups {
$warn = array(); $warn = array();
$err = array(); $err = array();
@set_time_limit( 900 ); set_time_limit( 900 );
$max_execution_time = (int) @ini_get( 'max_execution_time' ); $max_execution_time = (int) ini_get( 'max_execution_time' );
if ( $max_execution_time > 0 && $max_execution_time < 61 ) { if ( $max_execution_time > 0 && $max_execution_time < 61 ) {
$warn[] = sprintf( __( 'The PHP setup on this webserver allows only %s seconds for PHP to run, and does not allow this limit to be raised. If you have a lot of data to import, and if the restore operation times out, then you will need to ask your web hosting company for ways to raise this limit (or attempt the restoration piece-by-piece).', 'updraftplus' ), $max_execution_time ); $warn[] = sprintf( __( 'The PHP setup on this webserver allows only %s seconds for PHP to run, and does not allow this limit to be raised. If you have a lot of data to import, and if the restore operation times out, then you will need to ask your web hosting company for ways to raise this limit (or attempt the restoration piece-by-piece).', 'updraftplus' ), $max_execution_time );
@ -1784,7 +1784,7 @@ class MainWP_Child_Updraft_Plus_Backups {
// not used. // not used.
private function restore_backup( $timestamp ) { private function restore_backup( $timestamp ) {
@set_time_limit( 900 ); set_time_limit( 900 );
global $wp_filesystem, $updraftplus; global $wp_filesystem, $updraftplus;
$backup_history = UpdraftPlus_Backup_History::get_history(); $backup_history = UpdraftPlus_Backup_History::get_history();
@ -1963,7 +1963,7 @@ class MainWP_Child_Updraft_Plus_Backups {
if ( isset( $backup_history[ $timestamp ][ $type . $index . '-size' ] ) ) { if ( isset( $backup_history[ $timestamp ][ $type . $index . '-size' ] ) ) {
$fs = $backup_history[ $timestamp ][ $type . $index . '-size' ]; $fs = $backup_history[ $timestamp ][ $type . $index . '-size' ];
echo esc_html__( 'Archive is expected to be size:', 'updraftplus' ) . ' ' . esc_html( round( $fs / 1024, 1 ) ) . ' Kb: '; echo esc_html__( 'Archive is expected to be size:', 'updraftplus' ) . ' ' . esc_html( round( $fs / 1024, 1 ) ) . ' Kb: ';
$as = @filesize( $fullpath ); $as = filesize( $fullpath );
if ( $as === $fs ) { if ( $as === $fs ) {
echo esc_html__( 'OK', 'updraftplus' ) . '<br>'; echo esc_html__( 'OK', 'updraftplus' ) . '<br>';
} else { } else {
@ -2372,7 +2372,7 @@ class MainWP_Child_Updraft_Plus_Backups {
$migration_warning = false; $migration_warning = false;
// Don't set too high - we want a timely response returned to the browser. // Don't set too high - we want a timely response returned to the browser.
@set_time_limit( 90 ); set_time_limit( 90 );
$count_wanted_tables = count( $wanted_tables ); $count_wanted_tables = count( $wanted_tables );
@ -2466,9 +2466,9 @@ class MainWP_Child_Updraft_Plus_Backups {
} }
if ( $is_plain ) { if ( $is_plain ) {
@fclose( $dbhandle ); fclose( $dbhandle );
} else { } else {
@gzclose( $dbhandle ); gzclose( $dbhandle );
} }
$missing_tables = array(); $missing_tables = array();
@ -2583,7 +2583,7 @@ class MainWP_Child_Updraft_Plus_Backups {
$default_dbscan_timeout = ( filesize( $db_file ) < 31457280 ) ? 120 : 240; $default_dbscan_timeout = ( filesize( $db_file ) < 31457280 ) ? 120 : 240;
$dbscan_timeout = ( defined( 'UPDRAFTPLUS_DBSCAN_TIMEOUT' ) && is_numeric( UPDRAFTPLUS_DBSCAN_TIMEOUT ) ) ? UPDRAFTPLUS_DBSCAN_TIMEOUT : $default_dbscan_timeout; $dbscan_timeout = ( defined( 'UPDRAFTPLUS_DBSCAN_TIMEOUT' ) && is_numeric( UPDRAFTPLUS_DBSCAN_TIMEOUT ) ) ? UPDRAFTPLUS_DBSCAN_TIMEOUT : $default_dbscan_timeout;
@set_time_limit( $dbscan_timeout ); set_time_limit( $dbscan_timeout );
// We limit the time that we spend scanning the file for character sets. // We limit the time that we spend scanning the file for character sets.
$db_charset_collate_scan_timeout = ( defined( 'UPDRAFTPLUS_DB_CHARSET_COLLATE_SCAN_TIMEOUT' ) && is_numeric( UPDRAFTPLUS_DB_CHARSET_COLLATE_SCAN_TIMEOUT ) ) ? UPDRAFTPLUS_DB_CHARSET_COLLATE_SCAN_TIMEOUT : 10; $db_charset_collate_scan_timeout = ( defined( 'UPDRAFTPLUS_DB_CHARSET_COLLATE_SCAN_TIMEOUT' ) && is_numeric( UPDRAFTPLUS_DB_CHARSET_COLLATE_SCAN_TIMEOUT ) ) ? UPDRAFTPLUS_DB_CHARSET_COLLATE_SCAN_TIMEOUT : 10;
@ -2765,9 +2765,9 @@ class MainWP_Child_Updraft_Plus_Backups {
} }
} }
if ( $is_plain ) { if ( $is_plain ) {
@fclose( $dbhandle ); fclose( $dbhandle );
} else { } else {
@gzclose( $dbhandle ); gzclose( $dbhandle );
} }
if ( ! empty( $db_supported_character_sets ) ) { if ( ! empty( $db_supported_character_sets ) ) {
$db_charsets_found_unique = array_unique( $db_charsets_found ); $db_charsets_found_unique = array_unique( $db_charsets_found );
@ -2936,7 +2936,7 @@ class MainWP_Child_Updraft_Plus_Backups {
if ( 0 === gzseek( $dbhandle, 0 ) ) { if ( 0 === gzseek( $dbhandle, 0 ) ) {
return $dbhandle; return $dbhandle;
} else { } else {
@gzclose( $dbhandle ); gzclose( $dbhandle );
return gzopen( $file, 'r' ); return gzopen( $file, 'r' );
} }
@ -2950,15 +2950,15 @@ class MainWP_Child_Updraft_Plus_Backups {
$fnew = fopen( $file . '.tmp', 'w' ); $fnew = fopen( $file . '.tmp', 'w' );
if ( false === ( $fnew ) || ! is_resource( $fnew ) ) { if ( false === ( $fnew ) || ! is_resource( $fnew ) ) {
@gzclose( $dbhandle ); gzclose( $dbhandle );
$err_msg = __( 'The attempt to undo the double-compression failed.', 'updraftplus' ); $err_msg = __( 'The attempt to undo the double-compression failed.', 'updraftplus' );
} else { } else {
@fwrite( $fnew, $bytes ); fwrite( $fnew, $bytes );
$emptimes = 0; $emptimes = 0;
while ( ! gzeof( $dbhandle ) ) { while ( ! gzeof( $dbhandle ) ) {
$bytes = @gzread( $dbhandle, 131072 ); $bytes = gzread( $dbhandle, 131072 );
if ( empty( $bytes ) ) { if ( empty( $bytes ) ) {
global $updraftplus; global $updraftplus;
$emptimes ++; $emptimes ++;
@ -2967,7 +2967,7 @@ class MainWP_Child_Updraft_Plus_Backups {
break; break;
} }
} else { } else {
@fwrite( $fnew, $bytes ); fwrite( $fnew, $bytes );
} }
} }
@ -3406,7 +3406,7 @@ ENDHERE;
foreach ( $directories as $dir ) { foreach ( $directories as $dir ) {
if ( is_file( $dir ) ) { if ( is_file( $dir ) ) {
$size += @filesize( $dir ); $size += filesize( $dir );
} else { } else {
$suffix = ( '' !== $basedir ) ? ( ( 0 === strpos( $dir, $basedir . '/' ) ) ? substr( $dir, 1 + strlen( $basedir ) ) : '' ) : ''; $suffix = ( '' !== $basedir ) ? ( ( 0 === strpos( $dir, $basedir . '/' ) ) ? substr( $dir, 1 + strlen( $basedir ) ) : '' ) : '';
$size += $this->recursive_directory_size_raw( $basedir, $exclude, $suffix ); $size += $this->recursive_directory_size_raw( $basedir, $exclude, $suffix );

View file

@ -921,7 +921,7 @@ class MainWP_Child_Wordfence {
continue; continue;
} }
if ( 'del' === $op ) { if ( 'del' === $op ) {
if ( @unlink( $localFile ) ) { if ( unlink( $localFile ) ) {
$issues->updateIssue( $id, 'delete' ); $issues->updateIssue( $id, 'delete' );
$filesWorkedOn ++; $filesWorkedOn ++;
} else { } else {
@ -1014,7 +1014,7 @@ class MainWP_Child_Wordfence {
if ( strpos( $localFile, ABSPATH ) !== 0 ) { if ( strpos( $localFile, ABSPATH ) !== 0 ) {
return array( 'errorMsg' => 'An invalid file was requested for deletion.' ); return array( 'errorMsg' => 'An invalid file was requested for deletion.' );
} }
if ( @unlink( $localFile ) ) { if ( unlink( $localFile ) ) {
$wfIssues->updateIssue( $issueID, 'delete' ); $wfIssues->updateIssue( $issueID, 'delete' );
return array( return array(
@ -1560,7 +1560,7 @@ class MainWP_Child_Wordfence {
$res = $api->call( 'import_options', array(), array( 'token' => $token ) ); $res = $api->call( 'import_options', array(), array( 'token' => $token ) );
if ( $res['ok'] && $res['export'] ) { if ( $res['ok'] && $res['export'] ) {
$totalSet = 0; $totalSet = 0;
$import = @json_decode( $res['export'], true ); $import = json_decode( $res['export'], true );
if ( ! is_array( $import ) ) { if ( ! is_array( $import ) ) {
return array( 'errorImport' => __( 'An error occurred: Invalid options format received.', 'wordfence' ) ); return array( 'errorImport' => __( 'An error occurred: Invalid options format received.', 'wordfence' ) );
} }
@ -2118,7 +2118,7 @@ class MainWP_Child_Wordfence {
'code' => wfCache::getHtaccessCode(), 'code' => wfCache::getHtaccessCode(),
); );
} }
$fh = @fopen( $file, 'r+' ); $fh = fopen( $file, 'r+' );
if ( ! $fh ) { if ( ! $fh ) {
$err = error_get_last(); $err = error_get_last();
return array( return array(
@ -2141,7 +2141,7 @@ class MainWP_Child_Wordfence {
if ( ! $file ) { if ( ! $file ) {
return array( 'err' => 'We could not find your .htaccess file to modify it.' ); return array( 'err' => 'We could not find your .htaccess file to modify it.' );
} }
$fh = @fopen( $file, 'r+' ); $fh = fopen( $file, 'r+' );
if ( ! $fh ) { if ( ! $fh ) {
$err = error_get_last(); $err = error_get_last();
return array( 'err' => 'We found your .htaccess file but could not open it for writing: ' . $err['message'] ); return array( 'err' => 'We found your .htaccess file but could not open it for writing: ' . $err['message'] );

View file

@ -286,7 +286,7 @@ class MainWP_Child_WP_Rocket {
public function do_admin_post_rocket_purge_opcache() { public function do_admin_post_rocket_purge_opcache() {
if ( function_exists( 'opcache_reset' ) ) { if ( function_exists( 'opcache_reset' ) ) {
@opcache_reset(); opcache_reset();
} else { } else {
return array( 'error' => 'The host do not support the function reset opcache.' ); return array( 'error' => 'The host do not support the function reset opcache.' );
} }

View file

@ -150,12 +150,12 @@ class MainWP_Clone_Install {
} }
public function testDatabase() { public function testDatabase() {
$link = @MainWP_Child_DB::connect( $this->config['dbHost'], $this->config['dbUser'], $this->config['dbPass'] ); $link = MainWP_Child_DB::connect( $this->config['dbHost'], $this->config['dbUser'], $this->config['dbPass'] );
if ( ! $link ) { if ( ! $link ) {
throw new Exception( __( 'Invalid database host or user/password.', 'mainwp-child' ) ); throw new Exception( __( 'Invalid database host or user/password.', 'mainwp-child' ) );
} }
$db_selected = @MainWP_Child_DB::select_db( $this->config['dbName'], $link ); $db_selected = MainWP_Child_DB::select_db( $this->config['dbName'], $link );
if ( ! $db_selected ) { if ( ! $db_selected ) {
throw new Exception( __( 'Invalid database name.', 'mainwp-child' ) ); throw new Exception( __( 'Invalid database name.', 'mainwp-child' ) );
} }
@ -164,13 +164,13 @@ class MainWP_Clone_Install {
public function clean() { public function clean() {
$files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' ); $files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' );
foreach ( $files as $file ) { foreach ( $files as $file ) {
@unlink( $file ); unlink( $file );
} }
if ( file_exists( ABSPATH . 'clone/config.txt' ) ) { if ( file_exists( ABSPATH . 'clone/config.txt' ) ) {
@unlink( ABSPATH . 'clone/config.txt' ); unlink( ABSPATH . 'clone/config.txt' );
} }
if ( MainWP_Helper::is_dir_empty( ABSPATH . 'clone' ) ) { if ( MainWP_Helper::is_dir_empty( ABSPATH . 'clone' ) ) {
@rmdir( ABSPATH . 'clone' ); rmdir( ABSPATH . 'clone' );
} }
try { try {
@ -180,7 +180,7 @@ class MainWP_Clone_Install {
$files = glob( $backupdir . '*' ); $files = glob( $backupdir . '*' );
foreach ( $files as $file ) { foreach ( $files as $file ) {
if ( MainWP_Helper::isArchive( $file ) ) { if ( MainWP_Helper::isArchive( $file ) ) {
@unlink( $file ); unlink( $file );
} }
} }
} catch ( Exception $e ) { } catch ( Exception $e ) {
@ -225,14 +225,14 @@ class MainWP_Clone_Install {
$files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' ); $files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' );
foreach ( $files as $file ) { foreach ( $files as $file ) {
$handle = @fopen( $file, 'r' ); $handle = fopen( $file, 'r' );
$lastRun = 0; $lastRun = 0;
if ( $handle ) { if ( $handle ) {
$readline = ''; $readline = '';
while ( ( $line = fgets( $handle, 81920 ) ) !== false ) { while ( ( $line = fgets( $handle, 81920 ) ) !== false ) {
if ( time() - $lastRun > 20 ) { if ( time() - $lastRun > 20 ) {
@set_time_limit( 0 ); // reset timer.. set_time_limit( 0 ); // reset timer..
$lastRun = time(); $lastRun = time();
} }
@ -350,7 +350,7 @@ class MainWP_Clone_Install {
// Clean up! // Clean up!
$files = glob( '../dbBackup*.sql' ); $files = glob( '../dbBackup*.sql' );
foreach ( $files as $file ) { foreach ( $files as $file ) {
@unlink( $file ); unlink( $file );
} }
} }
@ -434,7 +434,7 @@ class MainWP_Clone_Install {
$zip = new ZipArchive(); $zip = new ZipArchive();
$zipRes = $zip->open( $this->file ); $zipRes = $zip->open( $this->file );
if ( $zipRes ) { if ( $zipRes ) {
@$zip->extractTo( ABSPATH ); $zip->extractTo( ABSPATH );
$zip->close(); $zip->close();
return true; return true;
@ -643,7 +643,7 @@ class MainWP_Clone_Install {
// some unseriliased data cannot be re-serialised eg. SimpleXMLElements. // some unseriliased data cannot be re-serialised eg. SimpleXMLElements.
try { try {
$unserialized = @unserialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions. $unserialized = unserialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.
if ( is_string( $data ) && is_serialized( $data ) && ! is_serialized_string( $data ) && false !== $unserialized ) { if ( is_string( $data ) && is_serialized( $data ) && ! is_serialized_string( $data ) && false !== $unserialized ) {
$data = $this->recursive_unserialize_replace( $from, $to, $unserialized, true ); $data = $this->recursive_unserialize_replace( $from, $to, $unserialized, true );
} elseif ( is_array( $data ) ) { } elseif ( is_array( $data ) ) {
@ -663,7 +663,7 @@ class MainWP_Clone_Install {
$data = $_tmp; $data = $_tmp;
unset( $_tmp ); unset( $_tmp );
} elseif ( is_serialized_string( $data ) && is_serialized( $data ) ) { } elseif ( is_serialized_string( $data ) && is_serialized( $data ) ) {
$data = @unserialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions. $data = unserialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.
if ( false !== $data ) { if ( false !== $data ) {
$data = str_replace( $from, $to, $data ); $data = str_replace( $from, $to, $data );
$data = serialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions. $data = serialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.

View file

@ -1161,7 +1161,7 @@ class MainWP_Clone {
if ( ! $result['backup'] ) { if ( ! $result['backup'] ) {
throw new Exception( __( 'Could not create backupfile on child', 'mainwp-child' ) ); throw new Exception( __( 'Could not create backupfile on child', 'mainwp-child' ) );
} }
@session_start(); session_start();
MainWP_Helper::update_option( 'mainwp_temp_clone_plugins', $result['plugins'] ); MainWP_Helper::update_option( 'mainwp_temp_clone_plugins', $result['plugins'] );
MainWP_Helper::update_option( 'mainwp_temp_clone_themes', $result['themes'] ); MainWP_Helper::update_option( 'mainwp_temp_clone_themes', $result['themes'] );
@ -1257,7 +1257,7 @@ class MainWP_Clone {
$file = readdir( $dh ); $file = readdir( $dh );
while ( false !== $file ) { while ( false !== $file ) {
if ( '.' !== $file && '..' !== $file && MainWP_Helper::isArchive( $file, 'download-' ) ) { if ( '.' !== $file && '..' !== $file && MainWP_Helper::isArchive( $file, 'download-' ) ) {
@unlink( $backupdir . $file ); unlink( $backupdir . $file );
} }
} }
closedir( $dh ); closedir( $dh );
@ -1427,8 +1427,8 @@ class MainWP_Clone {
$out = array(); $out = array();
if ( is_array( $plugins ) ) { if ( is_array( $plugins ) ) {
$dir = WP_CONTENT_DIR . '/plugins/'; $dir = WP_CONTENT_DIR . '/plugins/';
$fh = @opendir( $dir ); $fh = opendir( $dir );
while ( $entry = @readdir( $fh ) ) { while ( $entry = readdir( $fh ) ) {
if ( ! is_dir( $dir . $entry ) ) { if ( ! is_dir( $dir . $entry ) ) {
continue; continue;
} }
@ -1439,7 +1439,7 @@ class MainWP_Clone {
MainWP_Helper::delete_dir( $dir . $entry ); MainWP_Helper::delete_dir( $dir . $entry );
} }
} }
@closedir( $fh ); closedir( $fh );
} }
delete_option( 'mainwp_temp_clone_plugins' ); delete_option( 'mainwp_temp_clone_plugins' );
@ -1448,8 +1448,8 @@ class MainWP_Clone {
$out = array(); $out = array();
if ( is_array( $themes ) ) { if ( is_array( $themes ) ) {
$dir = WP_CONTENT_DIR . '/themes/'; $dir = WP_CONTENT_DIR . '/themes/';
$fh = @opendir( $dir ); $fh = opendir( $dir );
while ( $entry = @readdir( $fh ) ) { while ( $entry = readdir( $fh ) ) {
if ( ! is_dir( $dir . $entry ) ) { if ( ! is_dir( $dir . $entry ) ) {
continue; continue;
} }
@ -1460,7 +1460,7 @@ class MainWP_Clone {
MainWP_Helper::delete_dir( $dir . $entry ); MainWP_Helper::delete_dir( $dir . $entry );
} }
} }
@closedir( $fh ); closedir( $fh );
} }
delete_option( 'mainwp_temp_clone_themes' ); delete_option( 'mainwp_temp_clone_themes' );
} }
@ -1515,7 +1515,7 @@ class MainWP_Clone {
public static function renderRestore() { public static function renderRestore() {
if ( '' === session_id() ) { if ( '' === session_id() ) {
@session_start(); session_start();
} }
$file = null; $file = null;
$size = null; $size = null;

View file

@ -68,9 +68,9 @@ class MainWP_Helper {
} }
public static function safe_json_encode( $value, $options = 0, $depth = 512 ) { public static function safe_json_encode( $value, $options = 0, $depth = 512 ) {
$encoded = @json_encode( $value, $options, $depth ); $encoded = json_encode( $value, $options, $depth );
if ( false === $encoded && ! empty( $value ) && JSON_ERROR_UTF8 == json_last_error() ) { if ( false === $encoded && ! empty( $value ) && JSON_ERROR_UTF8 == json_last_error() ) {
$encoded = @json_encode( self::json_valid_check( $value ), $options, $depth ); $encoded = json_encode( self::json_valid_check( $value ), $options, $depth );
} }
return $encoded; return $encoded;
} }
@ -262,7 +262,7 @@ class MainWP_Helper {
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path ); $local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
} }
$moved = @rename( $temporary_file, $local_img_path ); $moved = rename( $temporary_file, $local_img_path );
if ( $moved ) { if ( $moved ) {
$wp_filetype = wp_check_filetype( basename( $img_url ), null ); // Get the filetype to set the mimetype. $wp_filetype = wp_check_filetype( basename( $img_url ), null ); // Get the filetype to set the mimetype.
@ -331,22 +331,22 @@ class MainWP_Helper {
); );
if ( is_wp_error( $response ) ) { if ( is_wp_error( $response ) ) {
@unlink( $full_file_name ); unlink( $full_file_name );
throw new Exception( 'Error: ' . $response->get_error_message() ); throw new Exception( 'Error: ' . $response->get_error_message() );
} }
if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
@unlink( $full_file_name ); unlink( $full_file_name );
throw new Exception( 'Error 404: ' . trim( wp_remote_retrieve_response_message( $response ) ) ); throw new Exception( 'Error 404: ' . trim( wp_remote_retrieve_response_message( $response ) ) );
} }
if ( '.phpfile.txt' === substr( $file_name, - 12 ) ) { if ( '.phpfile.txt' === substr( $file_name, - 12 ) ) {
$new_file_name = substr( $file_name, 0, - 12 ) . '.php'; $new_file_name = substr( $file_name, 0, - 12 ) . '.php';
$new_file_name = $path . DIRECTORY_SEPARATOR . $new_file_name; $new_file_name = $path . DIRECTORY_SEPARATOR . $new_file_name;
$moved = @rename( $full_file_name, $new_file_name ); $moved = rename( $full_file_name, $new_file_name );
if ( $moved ) { if ( $moved ) {
return array( 'path' => $new_file_name ); return array( 'path' => $new_file_name );
} else { } else {
@unlink( $full_file_name ); unlink( $full_file_name );
throw new Exception( 'Error: Copy file.' ); throw new Exception( 'Error: Copy file.' );
} }
} }
@ -877,7 +877,7 @@ class MainWP_Helper {
$dir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'mainwp' . DIRECTORY_SEPARATOR; $dir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'mainwp' . DIRECTORY_SEPARATOR;
self::checkDir( $dir, $dieOnError ); self::checkDir( $dir, $dieOnError );
if ( ! file_exists( $dir . 'index.php' ) ) { if ( ! file_exists( $dir . 'index.php' ) ) {
@touch( $dir . 'index.php' ); touch( $dir . 'index.php' );
} }
$url = $upload_dir['baseurl'] . '/mainwp/'; $url = $upload_dir['baseurl'] . '/mainwp/';
@ -885,14 +885,14 @@ class MainWP_Helper {
$dir .= 'backup' . DIRECTORY_SEPARATOR; $dir .= 'backup' . DIRECTORY_SEPARATOR;
self::checkDir( $dir, $dieOnError ); self::checkDir( $dir, $dieOnError );
if ( ! file_exists( $dir . 'index.php' ) ) { if ( ! file_exists( $dir . 'index.php' ) ) {
@touch( $dir . 'index.php' ); touch( $dir . 'index.php' );
} }
$another_name = '.htaccess'; $another_name = '.htaccess';
if ( ! file_exists( $dir . $another_name ) ) { if ( ! file_exists( $dir . $another_name ) ) {
$file = @fopen( $dir . $another_name, 'w+' ); $file = fopen( $dir . $another_name, 'w+' );
@fwrite( $file, 'deny from all' ); fwrite( $file, 'deny from all' );
@fclose( $file ); fclose( $file );
} }
$url .= 'backup/'; $url .= 'backup/';
} }
@ -905,7 +905,7 @@ class MainWP_Helper {
global $wp_filesystem; global $wp_filesystem;
if ( ! file_exists( $dir ) ) { if ( ! file_exists( $dir ) ) {
if ( empty( $wp_filesystem ) ) { if ( empty( $wp_filesystem ) ) {
@mkdir( $dir, $chmod, true ); mkdir( $dir, $chmod, true );
} else { } else {
if ( ( 'ftpext' === $wp_filesystem->method ) && defined( 'FTP_BASE' ) ) { if ( ( 'ftpext' === $wp_filesystem->method ) && defined( 'FTP_BASE' ) ) {
$ftpBase = FTP_BASE; $ftpBase = FTP_BASE;
@ -948,7 +948,7 @@ class MainWP_Helper {
if ( ! $done ) { if ( ! $done ) {
if ( ! file_exists( $dir ) ) { if ( ! file_exists( $dir ) ) {
@mkdirs( $dir ); mkdirs( $dir );
} }
if ( is_writable( $dir ) ) { if ( is_writable( $dir ) ) {
$done = true; $done = true;
@ -1061,8 +1061,8 @@ class MainWP_Helper {
} }
public static function endSession() { public static function endSession() {
@session_write_close(); session_write_close();
@ob_end_flush(); ob_end_flush();
} }
public static function fetchUrl( $url, $postdata ) { public static function fetchUrl( $url, $postdata ) {
@ -1151,7 +1151,7 @@ class MainWP_Helper {
$size = array( 'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ); $size = array( 'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
$factor = floor( ( strlen( $bytes ) - 1 ) / 3 ); $factor = floor( ( strlen( $bytes ) - 1 ) / 3 );
return sprintf( "%.{$decimals}f", $bytes / pow( 1024, $factor ) ) . @$size[ $factor ]; return sprintf( "%.{$decimals}f", $bytes / pow( 1024, $factor ) ) . $size[ $factor ];
} }
public static function is_dir_empty( $dir ) { public static function is_dir_empty( $dir ) {
@ -1170,11 +1170,11 @@ class MainWP_Helper {
if ( is_dir( $node ) ) { if ( is_dir( $node ) ) {
self::delete_dir( $node . DIRECTORY_SEPARATOR ); self::delete_dir( $node . DIRECTORY_SEPARATOR );
} else { } else {
@unlink( $node ); unlink( $node );
} }
} }
} }
@rmdir( $dir ); rmdir( $dir );
} }
public static function function_exists( $func ) { public static function function_exists( $func ) {
@ -1183,7 +1183,7 @@ class MainWP_Helper {
} }
if ( extension_loaded( 'suhosin' ) ) { if ( extension_loaded( 'suhosin' ) ) {
$suhosin = @ini_get( 'suhosin.executor.func.blacklist' ); $suhosin = ini_get( 'suhosin.executor.func.blacklist' );
if ( ! empty( $suhosin ) ) { if ( ! empty( $suhosin ) ) {
$suhosin = explode( ',', $suhosin ); $suhosin = explode( ',', $suhosin );
$suhosin = array_map( 'trim', $suhosin ); $suhosin = array_map( 'trim', $suhosin );

View file

@ -137,9 +137,9 @@ class MainWP_Security {
public static function remove_php_reporting( $force = false ) { public static function remove_php_reporting( $force = false ) {
if ( $force || self::get_security_option( 'php_reporting' ) ) { if ( $force || self::get_security_option( 'php_reporting' ) ) {
@error_reporting( 0 ); error_reporting( 0 );
@ini_set( 'display_errors', 'off' ); ini_set( 'display_errors', 'off' );
@ini_set( 'display_startup_errors', 0 ); ini_set( 'display_startup_errors', 0 );
} }
} }
@ -216,13 +216,13 @@ class MainWP_Security {
} }
if ( $force || self::get_security_option( 'readme' ) ) { if ( $force || self::get_security_option( 'readme' ) ) {
if ( @file_exists( ABSPATH . 'readme.html' ) ) { if ( file_exists( ABSPATH . 'readme.html' ) ) {
if ( ! @unlink( ABSPATH . 'readme.html' ) ) { if ( ! unlink( ABSPATH . 'readme.html' ) ) {
MainWP_Helper::getWPFilesystem(); MainWP_Helper::getWPFilesystem();
global $wp_filesystem; global $wp_filesystem;
if ( ! empty( $wp_filesystem ) ) { if ( ! empty( $wp_filesystem ) ) {
$wp_filesystem->delete( ABSPATH . 'readme.html' ); $wp_filesystem->delete( ABSPATH . 'readme.html' );
if ( @file_exists( ABSPATH . 'readme.html' ) ) { if ( file_exists( ABSPATH . 'readme.html' ) ) {
// prevent repeat delete. // prevent repeat delete.
self::update_security_option( 'readme', false ); self::update_security_option( 'readme', false );
} }

View file

@ -121,7 +121,7 @@ class MainWP_Wordpress_SEO {
$unzipped = unzip_file( $file, $p_path ); $unzipped = unzip_file( $file, $p_path );
if ( ! is_wp_error( $unzipped ) ) { if ( ! is_wp_error( $unzipped ) ) {
$filename = $p_path . 'settings.ini'; $filename = $p_path . 'settings.ini';
if ( @is_file( $filename ) && is_readable( $filename ) ) { if ( is_file( $filename ) && is_readable( $filename ) ) {
$options = parse_ini_file( $filename, true ); $options = parse_ini_file( $filename, true );
if ( is_array( $options ) && array() !== $options ) { if ( is_array( $options ) && array() !== $options ) {
@ -147,13 +147,13 @@ class MainWP_Wordpress_SEO {
} else { } else {
throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) ); throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) );
} }
@unlink( $filename ); unlink( $filename );
@unlink( $p_path ); unlink( $p_path );
} else { } else {
throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) . ' ' . sprintf( __( 'Unzipping failed with error "%s".', 'mainwp-child' ), $unzipped->get_error_message() ) ); throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) . ' ' . sprintf( __( 'Unzipping failed with error "%s".', 'mainwp-child' ), $unzipped->get_error_message() ) );
} }
unset( $zip, $unzipped ); unset( $zip, $unzipped );
@unlink( $file ); unlink( $file );
} else { } else {
throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) . ' ' . __( 'Upload failed.', 'mainwp-child' ) ); throw new Exception( __( 'Settings could not be imported:', 'mainwp-child' ) . ' ' . __( 'Upload failed.', 'mainwp-child' ) );
} }

View file

@ -131,7 +131,7 @@ class Tar_Archiver {
$this->archivePath = $filepath; $this->archivePath = $filepath;
if ( $append && @file_exists( $filepath ) ) { if ( $append && file_exists( $filepath ) ) {
$this->mode = self::APPEND; $this->mode = self::APPEND;
$this->prepareAppend( $filepath ); $this->prepareAppend( $filepath );
} else { } else {
@ -211,9 +211,9 @@ class Tar_Archiver {
global $wpdb; global $wpdb;
$plugins = array(); $plugins = array();
$dir = WP_CONTENT_DIR . '/plugins/'; $dir = WP_CONTENT_DIR . '/plugins/';
$fh = @opendir( $dir ); $fh = opendir( $dir );
while ( $entry = @readdir( $fh ) ) { while ( $entry = readdir( $fh ) ) {
if ( ! @is_dir( $dir . $entry ) ) { if ( ! is_dir( $dir . $entry ) ) {
continue; continue;
} }
if ( ( '.' === $entry ) || ( '..' === $entry ) ) { if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
@ -221,13 +221,13 @@ class Tar_Archiver {
} }
$plugins[] = $entry; $plugins[] = $entry;
} }
@closedir( $fh ); closedir( $fh );
$themes = array(); $themes = array();
$dir = WP_CONTENT_DIR . '/themes/'; $dir = WP_CONTENT_DIR . '/themes/';
$fh = @opendir( $dir ); $fh = opendir( $dir );
while ( $entry = @readdir( $fh ) ) { while ( $entry = readdir( $fh ) ) {
if ( ! @is_dir( $dir . $entry ) ) { if ( ! is_dir( $dir . $entry ) ) {
continue; continue;
} }
if ( ( '.' == $entry ) || ( '..' == $entry ) ) { if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
@ -235,7 +235,7 @@ class Tar_Archiver {
} }
$themes[] = $entry; $themes[] = $entry;
} }
@closedir( $fh ); closedir( $fh );
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. $string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons.
serialize( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions. serialize( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.
@ -258,7 +258,7 @@ class Tar_Archiver {
$this->addData( pack( 'a1024', '' ) ); $this->addData( pack( 'a1024', '' ) );
$this->close(); $this->close();
foreach ( $db_files as $db_file ) { foreach ( $db_files as $db_file ) {
@unlink( $db_file ); unlink( $db_file );
} }
$this->completePidFile(); $this->completePidFile();
@ -320,18 +320,18 @@ class Tar_Archiver {
} }
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
if ( false === @gzwrite( $this->archive, $data, strlen( $data ) ) ) { if ( false === gzwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
} elseif ( 'tar.bz2' == $this->type ) { } elseif ( 'tar.bz2' == $this->type ) {
if ( false === @bzwrite( $this->archive, $data, strlen( $data ) ) ) { if ( false === bzwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
} else { } else {
if ( false === @fwrite( $this->archive, $data, strlen( $data ) ) ) { if ( false === fwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
@fflush( $this->archive ); fflush( $this->archive );
} }
} }
@ -344,26 +344,26 @@ class Tar_Archiver {
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
$this->log( 'writing & flushing ' . $len ); $this->log( 'writing & flushing ' . $len );
$this->chunk = gzencode( $this->chunk ); $this->chunk = gzencode( $this->chunk );
if ( false === @fwrite( $this->archive, $this->chunk, strlen( $this->chunk ) ) ) { if ( false === fwrite( $this->archive, $this->chunk, strlen( $this->chunk ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
@fflush( $this->archive ); fflush( $this->archive );
} elseif ( 'tar.bz2' == $this->type ) { } elseif ( 'tar.bz2' == $this->type ) {
if ( false === @bzwrite( $this->archive, $this->chunk, strlen( $len ) ) ) { if ( false === bzwrite( $this->archive, $this->chunk, strlen( $len ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
} else { } else {
if ( false === @fwrite( $this->archive, $len, strlen( $len ) ) ) { if ( false === fwrite( $this->archive, $len, strlen( $len ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
@fflush( $this->archive ); fflush( $this->archive );
} }
$this->chunk = ''; $this->chunk = '';
} }
private function addEmptyDir( $path, $entryName ) { private function addEmptyDir( $path, $entryName ) {
$stat = @stat( $path ); $stat = stat( $path );
$this->addEmptyDirectory( $entryName, $stat['mode'], $stat['uid'], $stat['gid'], $stat['mtime'] ); $this->addEmptyDirectory( $entryName, $stat['mode'], $stat['uid'], $stat['gid'], $stat['mtime'] );
} }
@ -479,23 +479,23 @@ class Tar_Archiver {
} }
if ( time() - $this->lastRun > 60 ) { if ( time() - $this->lastRun > 60 ) {
@set_time_limit( 20 * 60 * 60 ); set_time_limit( 20 * 60 * 60 );
$this->lastRun = time(); $this->lastRun = time();
} }
$this->gcCnt ++; $this->gcCnt ++;
if ( $this->gcCnt > 20 ) { if ( $this->gcCnt > 20 ) {
if ( function_exists( 'gc_enable' ) ) { if ( function_exists( 'gc_enable' ) ) {
@gc_enable(); gc_enable();
} }
if ( function_exists( 'gc_collect_cycles' ) ) { if ( function_exists( 'gc_collect_cycles' ) ) {
@gc_collect_cycles(); gc_collect_cycles();
} }
$this->gcCnt = 0; $this->gcCnt = 0;
} }
$stat = @stat( $path ); $stat = stat( $path );
$fp = @fopen( $path, 'rb' ); $fp = fopen( $path, 'rb' );
if ( ! $fp ) { if ( ! $fp ) {
return; return;
} }
@ -579,7 +579,7 @@ class Tar_Archiver {
} }
if ( isset( $rslt['bytesRead'] ) ) { if ( isset( $rslt['bytesRead'] ) ) {
@fseek( $fp, $rslt['bytesRead'] ); fseek( $fp, $rslt['bytesRead'] );
$alreadyRead = ( $rslt['bytesRead'] % 512 ); $alreadyRead = ( $rslt['bytesRead'] % 512 );
$toRead = 512 - $alreadyRead; $toRead = 512 - $alreadyRead;
@ -611,7 +611,7 @@ class Tar_Archiver {
$this->updatePidFile(); $this->updatePidFile();
} }
@fclose( $fp ); fclose( $fp );
return true; return true;
} }
@ -719,8 +719,8 @@ class Tar_Archiver {
if ( is_array( $rslt ) ) { if ( is_array( $rslt ) ) {
if ( 'tar' == $this->type ) { if ( 'tar' == $this->type ) {
$startOffset = $rslt['startOffset']; $startOffset = $rslt['startOffset'];
@fseek( $this->archive, $startOffset ); fseek( $this->archive, $startOffset );
@ftruncate( $this->archive, $startOffset ); ftruncate( $this->archive, $startOffset );
} elseif ( 'tar.gz' == $this->type ) { } elseif ( 'tar.gz' == $this->type ) {
$readOffset = $rslt['readOffset']; $readOffset = $rslt['readOffset'];
$bytesRead = $rslt['bytesRead']; $bytesRead = $rslt['bytesRead'];
@ -729,11 +729,11 @@ class Tar_Archiver {
} }
} elseif ( false === $rslt ) { } elseif ( false === $rslt ) {
if ( 'tar' == $this->type ) { if ( 'tar' == $this->type ) {
@fseek( $this->archive, 0, SEEK_END ); fseek( $this->archive, 0, SEEK_END );
} }
} else { } else {
@fseek( $this->archive, $rslt ); fseek( $this->archive, $rslt );
@ftruncate( $this->archive, $rslt ); ftruncate( $this->archive, $rslt );
} }
$this->mode = self::CREATE; $this->mode = self::CREATE;
@ -754,10 +754,10 @@ class Tar_Archiver {
* @throws Exception * @throws Exception
*/ */
private function isNextFile( $entryName ) { private function isNextFile( $entryName ) {
$currentOffset = @ftell( $this->archive ); $currentOffset = ftell( $this->archive );
$rslt = array( 'startOffset' => $currentOffset ); $rslt = array( 'startOffset' => $currentOffset );
try { try {
$block = @fread( $this->archive, 512 ); $block = fread( $this->archive, 512 );
if ( false === $block || 0 == strlen( $block ) ) { if ( false === $block || 0 == strlen( $block ) ) {
return $rslt; return $rslt;
@ -769,8 +769,8 @@ class Tar_Archiver {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
if ( 'L' == $temp['type'] ) { if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) ); $fname = trim( fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 ); $block = fread( $this->archive, 512 );
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
$temp['prefix'] = ''; $temp['prefix'] = '';
$temp['name'] = $fname; $temp['name'] = $fname;
@ -799,15 +799,15 @@ class Tar_Archiver {
} }
} elseif ( 0 == $file['type'] ) { } elseif ( 0 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) { if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
$previousFtell = @ftell( $this->archive ); $previousFtell = ftell( $this->archive );
$bytes = $file['stat'][7] + ( 512 == ( 512 - $file['stat'][7] % 512 ) ? 0 : ( 512 - $file['stat'][7] % 512 ) ); $bytes = $file['stat'][7] + ( 512 == ( 512 - $file['stat'][7] % 512 ) ? 0 : ( 512 - $file['stat'][7] % 512 ) );
@fseek( $this->archive, @ftell( $this->archive ) + $bytes ); fseek( $this->archive, ftell( $this->archive ) + $bytes );
$ftell = @ftell( $this->archive ); $ftell = ftell( $this->archive );
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
if ( ( false === $ftell ) || ( -1 == $ftell ) ) { if ( ( false === $ftell ) || ( -1 == $ftell ) ) {
@fseek( $this->archive, $previousFtell ); fseek( $this->archive, $previousFtell );
$bytesRead = 0; $bytesRead = 0;
$bytesToRead = $file['stat'][7]; $bytesToRead = $file['stat'][7];
@ -864,7 +864,7 @@ class Tar_Archiver {
public function log( $text ) { public function log( $text ) {
if ( $this->logHandle ) { if ( $this->logHandle ) {
@fwrite( $this->logHandle, $text . "\n" ); fwrite( $this->logHandle, $text . "\n" );
} }
} }
@ -872,20 +872,20 @@ class Tar_Archiver {
$this->log( 'Creating ' . $filepath ); $this->log( 'Creating ' . $filepath );
if ( $this->debug ) { if ( $this->debug ) {
if ( 'tar.bz2' == $this->type ) { if ( 'tar.bz2' == $this->type ) {
$this->archive = @bzopen( $filepath, 'w' ); $this->archive = bzopen( $filepath, 'w' );
} else { } else {
$this->archive = @fopen( $filepath, 'wb+' ); $this->archive = fopen( $filepath, 'wb+' );
} }
return; return;
} }
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
$this->archive = @gzopen( $filepath, 'wb' ); $this->archive = gzopen( $filepath, 'wb' );
} elseif ( 'tar.bz2' == $this->type ) { } elseif ( 'tar.bz2' == $this->type ) {
$this->archive = @bzopen( $filepath, 'w' ); $this->archive = bzopen( $filepath, 'w' );
} else { } else {
$this->archive = @fopen( $filepath, 'wb+' ); $this->archive = fopen( $filepath, 'wb+' );
} }
} }
@ -893,20 +893,20 @@ class Tar_Archiver {
$this->log( 'Appending to ' . $filepath ); $this->log( 'Appending to ' . $filepath );
if ( $this->debug ) { if ( $this->debug ) {
if ( 'tar.bz2' == $this->type ) { if ( 'tar.bz2' == $this->type ) {
$this->archive = @bzopen( $filepath, 'a' ); $this->archive = bzopen( $filepath, 'a' );
} else { } else {
$this->archive = @fopen( $filepath, 'ab+' ); $this->archive = fopen( $filepath, 'ab+' );
} }
return; return;
} }
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
$this->archive = @gzopen( $filepath, 'ab' ); $this->archive = gzopen( $filepath, 'ab' );
} elseif ( 'tar.bz2' == $this->type ) { } elseif ( 'tar.bz2' == $this->type ) {
$this->archive = @bzopen( $filepath, 'a' ); $this->archive = bzopen( $filepath, 'a' );
} else { } else {
$this->archive = @fopen( $filepath, 'ab+' ); $this->archive = fopen( $filepath, 'ab+' );
} }
} }
@ -918,7 +918,7 @@ class Tar_Archiver {
if ( $this->debug ) { if ( $this->debug ) {
if ( 'tar.gz' == substr( $filepath, - 6 ) ) { if ( 'tar.gz' == substr( $filepath, - 6 ) ) {
$text = chr( 31 ) . chr( 139 ) . chr( 8 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ); $text = chr( 31 ) . chr( 139 ) . chr( 8 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 );
$fh = @fopen( $filepath, 'rb' ); $fh = fopen( $filepath, 'rb' );
$read = ''; $read = '';
$lastCorrect = 0; $lastCorrect = 0;
try { try {
@ -942,13 +942,13 @@ class Tar_Archiver {
throw new Exception( 'invalid!' ); throw new Exception( 'invalid!' );
} }
@fclose( $fh ); fclose( $fh );
} catch ( Exception $e ) { } catch ( Exception $e ) {
@fclose( $fh ); fclose( $fh );
$fh = @fopen( $filepath, 'ab+' ); $fh = fopen( $filepath, 'ab+' );
@fseek( $fh, $lastCorrect ); fseek( $fh, $lastCorrect );
@ftruncate( $fh, $lastCorrect ); ftruncate( $fh, $lastCorrect );
@fclose( $fh ); fclose( $fh );
} }
} }
} }
@ -962,20 +962,20 @@ class Tar_Archiver {
if ( 'tar.gz' == substr( $filepath, - 6 ) ) { if ( 'tar.gz' == substr( $filepath, - 6 ) ) {
$this->type = 'tar.gz'; $this->type = 'tar.gz';
$this->archive = @gzopen( $filepath, 'r' ); $this->archive = gzopen( $filepath, 'r' );
} elseif ( 'tar.bz2' == substr( $filepath, - 7 ) ) { } elseif ( 'tar.bz2' == substr( $filepath, - 7 ) ) {
$this->type = 'tar.bz2'; $this->type = 'tar.bz2';
$this->archive = @bzopen( $filepath, 'r' ); $this->archive = bzopen( $filepath, 'r' );
} else { } else {
$currentPos = @ftell( $this->archive ); $currentPos = ftell( $this->archive );
@fseek( $this->archive, 0, SEEK_END ); fseek( $this->archive, 0, SEEK_END );
$lastPos = @ftell( $this->archive ); $lastPos = ftell( $this->archive );
@fseek( $this->archive, $currentPos ); fseek( $this->archive, $currentPos );
$this->archiveSize = $lastPos; $this->archiveSize = $lastPos;
$this->type = 'tar'; $this->type = 'tar';
$this->archive = @fopen( $filepath, 'rb' ); $this->archive = fopen( $filepath, 'rb' );
} }
} }
@ -984,16 +984,16 @@ class Tar_Archiver {
$this->log( 'Closing archive' ); $this->log( 'Closing archive' );
if ( $closeLog && $this->logHandle ) { if ( $closeLog && $this->logHandle ) {
@fclose( $this->logHandle ); fclose( $this->logHandle );
} }
if ( $this->archive ) { if ( $this->archive ) {
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
@gzclose( $this->archive ); gzclose( $this->archive );
} elseif ( 'tar.bz2' == $this->type ) { } elseif ( 'tar.bz2' == $this->type ) {
@bzclose( $this->archive ); bzclose( $this->archive );
} else { } else {
@fclose( $this->archive ); fclose( $this->archive );
} }
} }
} }
@ -1006,12 +1006,12 @@ class Tar_Archiver {
return false; return false;
} }
$content = false; $content = false;
@fseek( $this->archive, 0 ); fseek( $this->archive, 0 );
while ( $block = @fread( $this->archive, 512 ) ) { while ( $block = fread( $this->archive, 512 ) ) {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
if ( 'L' == $temp['type'] ) { if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) ); $fname = trim( fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 ); $block = fread( $this->archive, 512 );
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
$temp['prefix'] = ''; $temp['prefix'] = '';
$temp['name'] = $fname; $temp['name'] = $fname;
@ -1052,7 +1052,7 @@ class Tar_Archiver {
break; break;
} else { } else {
$bytes = $file['stat'][7] + ( ( 512 - $file['stat'][7] % 512 ) == 512 ? 0 : ( 512 - $file['stat'][7] % 512 ) ); $bytes = $file['stat'][7] + ( ( 512 - $file['stat'][7] % 512 ) == 512 ? 0 : ( 512 - $file['stat'][7] % 512 ) );
@fseek( $this->archive, ftell( $this->archive ) + $bytes ); fseek( $this->archive, ftell( $this->archive ) + $bytes );
} }
} }
@ -1070,12 +1070,12 @@ class Tar_Archiver {
if ( empty( $entryName ) ) { if ( empty( $entryName ) ) {
return false; return false;
} }
@fseek( $this->archive, 0 ); fseek( $this->archive, 0 );
while ( $block = @fread( $this->archive, 512 ) ) { while ( $block = fread( $this->archive, 512 ) ) {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
if ( 'L' == $temp['type'] ) { if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) ); $fname = trim( fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 ); $block = fread( $this->archive, 512 );
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
$temp['prefix'] = ''; $temp['prefix'] = '';
$temp['name'] = $fname; $temp['name'] = $fname;
@ -1115,7 +1115,7 @@ class Tar_Archiver {
return true; return true;
} else { } else {
$bytes = $file['stat'][7] + ( ( 512 - $file['stat'][7] % 512 ) == 512 ? 0 : ( 512 - $file['stat'][7] % 512 ) ); $bytes = $file['stat'][7] + ( ( 512 - $file['stat'][7] % 512 ) == 512 ? 0 : ( 512 - $file['stat'][7] % 512 ) );
@fseek( $this->archive, ftell( $this->archive ) + $bytes ); fseek( $this->archive, ftell( $this->archive ) + $bytes );
} }
} }
@ -1130,12 +1130,12 @@ class Tar_Archiver {
global $wp_filesystem; global $wp_filesystem;
$to = trailingslashit( $to ); $to = trailingslashit( $to );
@fseek( $this->archive, 0 ); fseek( $this->archive, 0 );
while ( $block = fread( $this->archive, 512 ) ) { while ( $block = fread( $this->archive, 512 ) ) {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
if ( 'L' == $temp['type'] ) { if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) ); $fname = trim( fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 ); $block = fread( $this->archive, 512 );
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
$temp['prefix'] = ''; $temp['prefix'] = '';
$temp['name'] = $fname; $temp['name'] = $fname;
@ -1200,7 +1200,7 @@ class Tar_Archiver {
} }
} else { } else {
if ( 'wp-config.php' != $file['name'] ) { if ( 'wp-config.php' != $file['name'] ) {
$new = @fopen( $to . $file['name'], 'wb+' ); $new = fopen( $to . $file['name'], 'wb+' );
} else { } else {
$new = false; $new = false;
} }
@ -1231,7 +1231,7 @@ class Tar_Archiver {
} }
public function isValidBlock( $block ) { public function isValidBlock( $block ) {
$test = @gzinflate( $block ); $test = gzinflate( $block );
if ( false === $test ) { if ( false === $test ) {
return false; return false;
} }