Refactoring

This commit is contained in:
thanghv 2020-05-19 01:15:36 +07:00
parent bfea2ad02f
commit 9d8ed1259c
7 changed files with 813 additions and 802 deletions

View file

@ -268,68 +268,7 @@ class MainWP_Backup {
}
if ( $addConfig ) {
global $wpdb;
$plugins = array();
$dir = WP_CONTENT_DIR . '/plugins/';
// phpcs:disable
$fh = opendir( $dir );
while ( $entry = readdir( $fh ) ) {
if ( ! is_dir( $dir . $entry ) ) {
continue;
}
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
continue;
}
$plugins[] = $entry;
}
closedir( $fh );
// phpcs:enable
$themes = array();
$dir = WP_CONTENT_DIR . '/themes/';
// phpcs:disable
$fh = opendir( $dir );
while ( $entry = readdir( $fh ) ) {
if ( ! is_dir( $dir . $entry ) ) {
continue;
}
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
continue;
}
$themes[] = $entry;
}
closedir( $fh );
// phpcs:enable
if ( defined( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG ) {
$string = wp_json_encode(
array(
'siteurl' => get_option( 'siteurl' ),
'home' => get_option( 'home' ),
'abspath' => ABSPATH,
'prefix' => $wpdb->prefix,
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
'plugins' => $plugins,
'themes' => $themes,
)
);
} else {
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- safe.
serialize( // phpcs:ignore -- safe
array(
'siteurl' => get_option( 'siteurl' ),
'home' => get_option( 'home' ),
'abspath' => ABSPATH,
'prefix' => $wpdb->prefix,
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
'plugins' => $plugins,
'themes' => $themes,
)
)
);
}
$this->add_file_from_string_to_zip( 'clone/config.txt', $string );
$this->add_config();
}
$return = $this->zip->close();
@ -343,6 +282,71 @@ class MainWP_Backup {
return false;
}
public function add_config(){
global $wpdb;
$plugins = array();
$dir = WP_CONTENT_DIR . '/plugins/';
// phpcs:disable
$fh = opendir( $dir );
while ( $entry = readdir( $fh ) ) {
if ( ! is_dir( $dir . $entry ) ) {
continue;
}
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
continue;
}
$plugins[] = $entry;
}
closedir( $fh );
// phpcs:enable
$themes = array();
$dir = WP_CONTENT_DIR . '/themes/';
// phpcs:disable
$fh = opendir( $dir );
while ( $entry = readdir( $fh ) ) {
if ( ! is_dir( $dir . $entry ) ) {
continue;
}
if ( ( '.' == $entry ) || ( '..' == $entry ) ) {
continue;
}
$themes[] = $entry;
}
closedir( $fh );
// phpcs:enable
if ( defined( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG ) {
$string = wp_json_encode(
array(
'siteurl' => get_option( 'siteurl' ),
'home' => get_option( 'home' ),
'abspath' => ABSPATH,
'prefix' => $wpdb->prefix,
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
'plugins' => $plugins,
'themes' => $themes,
)
);
} else {
$string = base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- safe.
serialize( // phpcs:ignore -- safe
array(
'siteurl' => get_option( 'siteurl' ),
'home' => get_option( 'home' ),
'abspath' => ABSPATH,
'prefix' => $wpdb->prefix,
'lang' => defined( 'WPLANG' ) ? WPLANG : '',
'plugins' => $plugins,
'themes' => $themes,
)
)
);
}
$this->add_file_from_string_to_zip( 'clone/config.txt', $string );
}
public function copy_dir( $nodes, $excludes, $backupfolder, $excludenonwp, $root ) {
if ( ! is_array( $nodes ) ) {
return;

View file

@ -81,7 +81,6 @@ class MainWP_Child_Back_Up_WordPress {
$information['error'] = 'NO_BACKUPWORDPRESS';
mainwp_child_helper()->write( $information );
}
if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) {
case 'set_showhide':
@ -547,41 +546,9 @@ class MainWP_Child_Back_Up_WordPress {
<div class="hmbkp-exclude-settings">
<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>
</td>
<td>
<?php
if ( $new_version ) {
$is_default_rule = ( in_array( $exclude, $excludes->get_default_excludes() ) ) || ( HM\BackUpWordPress\Path::get_path() === trailingslashit( HM\BackUpWordPress\Path::get_root() ) . untrailingslashit( $exclude ) );
} 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', 'mainwp-child' ); ?>
<?php elseif ( defined( 'HMBKP_EXCLUDE' ) && false !== strpos( HMBKP_EXCLUDE, $exclude ) ) : ?>
<?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', 'mainwp-child' ); ?></a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
$this->render_table_excluded( $root_dir, $schedule, $excludes, $user_excludes, $new_version )
?>
<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
@ -609,200 +576,9 @@ class MainWP_Child_Back_Up_WordPress {
$exclude_string = $schedule->backup->exclude_string( 'regex' );
}
if ( $files ) {
?>
<table class="widefat">
<thead>
<tr>
<th></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', '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 ) {
?>
<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 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', 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', 'mainwp-child' );
} elseif ( is_dir( $root_dir ) ) {
esc_html_e( 'Folder', 'mainwp-child' );
}
?>
</td>
<td></td>
</tr>
</thead>
<tbody>
<?php
foreach ( $files as $size => $file ) {
$is_excluded = false;
$is_unreadable = false;
// 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;
}
} else {
if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', HM\BackUpWordPress\Backup::conform_dir( $file->getPathname() ) ) ) ) {
$is_excluded = true;
}
}
// 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>
<?php } elseif ( $file->isFile() ) { ?>
<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 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>
<?php } elseif ( $file->isFile() ) { ?>
<code title="<?php echo esc_attr( $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 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 ) {
$size = $site_size->filesize( $file );
} 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', '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', 'mainwp-child' ); ?></span>
<?php
elseif ( $file->isDir() ) :
esc_html_e( 'Folder', 'mainwp-child' );
else :
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.', 'mainwp-child' ); ?>"><?php esc_html_e( 'Unreadable', 'mainwp-child' ); ?></strong>
<?php elseif ( $is_excluded ) : ?>
<strong><?php esc_html_e( 'Excluded', 'mainwp-child' ); ?></strong>
<?php
else :
$exclude_path = $file->getPathname();
// 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 rawurlencode( $exclude_path ); ?>', this)" class="button-secondary"><?php esc_html_e( 'Exclude &rarr;', 'mainwp-child' ); ?></a>
<?php endif; ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
$this->render_table_files( $files, $schedule, $directory, $root_dir, $new_version, $site_size, $is_size_calculated );
}
?>
<p class="submit">
<a href="#" onclick="event.preventDefault(); mainwp_backupwp_edit_exclude_done()" class="button-primary"><?php esc_html_e( 'Done', 'mainwp-child' ); ?></a>
</p>
@ -814,6 +590,257 @@ class MainWP_Child_Back_Up_WordPress {
return $information;
}
private function render_table_excluded( $root_dir, $schedule, $excludes, $user_excludes, $new_version ){
?>
<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>
</td>
<td>
<?php
if ( $new_version ) {
$is_default_rule = ( in_array( $exclude, $excludes->get_default_excludes() ) ) || ( HM\BackUpWordPress\Path::get_path() === trailingslashit( HM\BackUpWordPress\Path::get_root() ) . untrailingslashit( $exclude ) );
} 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', 'mainwp-child' ); ?>
<?php elseif ( defined( 'HMBKP_EXCLUDE' ) && false !== strpos( HMBKP_EXCLUDE, $exclude ) ) : ?>
<?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', 'mainwp-child' ); ?></a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}
private function render_table_files( $files, $schedule, $directory, $root_dir, $new_version, $site_size, $is_size_calculated ){
?>
<table class="widefat">
<thead>
<?php
$this->render_table_header_files( $root_dir, $directory, $schedule, $new_version, $site_size, $is_size_calculated );
?>
</thead>
<tbody>
<?php
$this->render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated );
?>
</tbody>
</table>
<?php
}
private function render_table_header_files( $root_dir, $directory, $schedule, $new_version, $site_size, $is_size_calculated ){
?>
<tr>
<th></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', '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 ) {
?>
<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 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', 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', 'mainwp-child' );
} elseif ( is_dir( $root_dir ) ) {
esc_html_e( 'Folder', 'mainwp-child' );
}
?>
</td>
<td></td>
</tr>
<?php
}
private function render_table_body_files( $files, $schedule, $root_dir, $new_version, $site_size, $is_size_calculated ){
foreach ( $files as $size => $file ) {
$is_excluded = false;
$is_unreadable = false;
// 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;
}
} else {
if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', HM\BackUpWordPress\Backup::conform_dir( $file->getPathname() ) ) ) ) {
$is_excluded = true;
}
}
// 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>
<?php } elseif ( $file->isFile() ) { ?>
<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 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>
<?php } elseif ( $file->isFile() ) { ?>
<code title="<?php echo esc_attr( $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 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 ) {
$size = $site_size->filesize( $file );
} 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', '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', 'mainwp-child' ); ?></span>
<?php
elseif ( $file->isDir() ) :
esc_html_e( 'Folder', 'mainwp-child' );
else :
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.', 'mainwp-child' ); ?>"><?php esc_html_e( 'Unreadable', 'mainwp-child' ); ?></strong>
<?php elseif ( $is_excluded ) : ?>
<strong><?php esc_html_e( 'Excluded', 'mainwp-child' ); ?></strong>
<?php
else :
$exclude_path = $file->getPathname();
// 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 rawurlencode( $exclude_path ); ?>', this)" class="button-secondary"><?php esc_html_e( 'Exclude &rarr;', 'mainwp-child' ); ?></a>
<?php endif; ?>
</td>
</tr>
<?php }
}
public function directory_browse() {
$browse_dir = $_POST['browse_dir'];
$out = array();

View file

@ -695,8 +695,6 @@ class MainWP_Child_Posts {
$post_author = ! empty( $post_author ) ? $post_author : $current_uid;
$new_post['post_author'] = $post_author;
unset( $new_post['_ezin_post_category'] );
// post plus extension process.
$is_post_plus = isset( $post_custom['_mainwp_post_plus'] ) ? true : false;
@ -777,10 +775,23 @@ class MainWP_Child_Posts {
);
}
$permalink = get_permalink( $new_post_id );
$this->update_post_data( $new_post_id, $post_custom, $post_category, $post_featured_image, $check_image_existed, $is_post_plus );
// unlock if edit post.
if ( $edit_post_id ) {
update_post_meta( $edit_post_id, '_edit_lock', '' );
}
$permalink = get_permalink( $new_post_id );
$ret['success'] = true;
$ret['link'] = $permalink;
$ret['added_id'] = $new_post_id;
return $ret;
}
private function update_post_data( $new_post_id, $post_custom, $post_category, $post_featured_image, $check_image_existed, $is_post_plus ){
$seo_ext_activated = false;
if ( class_exists( 'WPSEO_Meta' ) && class_exists( 'WPSEO_Admin' ) ) {
$seo_ext_activated = true;
}
@ -813,20 +824,8 @@ class MainWP_Child_Posts {
)
);
}
// unlock if edit post.
if ( $edit_post_id ) {
update_post_meta( $edit_post_id, '_edit_lock', '' );
}
$ret['success'] = true;
$ret['link'] = $permalink;
$ret['added_id'] = $new_post_id;
return $ret;
}
private function create_wp_rocket( &$post_custom ) {
// Options fields.
$wprocket_fields = array(
@ -1078,14 +1077,7 @@ class MainWP_Child_Posts {
'_bulkpost_do_not_del',
'_mainwp_spin_me',
);
$not_allowed[] = '_mainwp_boilerplate_sites_posts';
$not_allowed[] = '_ezine_post_keyword';
$not_allowed[] = '_ezine_post_display_sig';
$not_allowed[] = '_ezine_post_remove_link';
$not_allowed[] = '_ezine_post_grab_image';
$not_allowed[] = '_ezine_post_grab_image_placement';
$not_allowed[] = '_ezine_post_template_id';
$not_allowed[] = '_mainwp_boilerplate_sites_posts';
$not_allowed[] = '_mainwp_post_plus';
$not_allowed[] = '_saved_as_draft';
$not_allowed[] = '_saved_draft_categories';

View file

@ -947,133 +947,138 @@ class MainWP_Child_Timecapsule {
$is_general = $_POST['is_general'];
$saved = false;
$config = WPTC_Factory::get( 'config' );
if ( 'backup' == $tabName ) {
$config->set_option( 'user_excluded_extenstions', $data['user_excluded_extenstions'] );
$config->set_option( 'user_excluded_files_more_than_size_settings', $data['user_excluded_files_more_than_size_settings'] );
if ( ! empty( $data['backup_slot'] ) ) {
$config->set_option( 'old_backup_slot', $config->get_option( 'backup_slot' ) );
$config->set_option( 'backup_slot', $data['backup_slot'] );
}
$config->set_option( 'backup_db_query_limit', $data['backup_db_query_limit'] );
$config->set_option( 'database_encrypt_settings', $data['database_encrypt_settings'] );
$config->set_option( 'wptc_timezone', $data['wptc_timezone'] );
$config->set_option( 'schedule_time_str', $data['schedule_time_str'] );
if ( ! empty( $data['schedule_time_str'] ) && ! empty( $data['wptc_timezone'] ) ) {
if ( function_exists( 'wptc_modify_schedule_backup' ) ) {
wptc_modify_schedule_backup();
}
}
$notice = apply_filters( 'check_requirements_auto_backup_wptc', '' );
if ( ! empty( $data['revision_limit'] ) && ! $notice ) {
$notice = apply_filters( 'save_settings_revision_limit_wptc', $data['revision_limit'] );
}
$this->save_settings_backup_tab( $config, $data );
$saved = true;
} elseif ( 'backup_auto' == $tabName ) {
$config->set_option( 'backup_before_update_setting', $data['backup_before_update_setting'] );
$current = $config->get_option( 'wptc_auto_update_settings' );
$current = unserialize( $current ); // phpcs:ignore -- third party credit.
$new = unserialize( $data['wptc_auto_update_settings'] ); // phpcs:ignore -- third party credit.
$current['update_settings']['status'] = $new['update_settings']['status'];
$current['update_settings']['schedule']['enabled'] = $new['update_settings']['schedule']['enabled'];
$current['update_settings']['schedule']['time'] = $new['update_settings']['schedule']['time'];
$current['update_settings']['core']['major']['status'] = $new['update_settings']['core']['major']['status'];
$current['update_settings']['core']['minor']['status'] = $new['update_settings']['core']['minor']['status'];
$current['update_settings']['themes']['status'] = $new['update_settings']['themes']['status'];
$current['update_settings']['plugins']['status'] = $new['update_settings']['plugins']['status'];
if ( ! $is_general ) {
if ( isset( $new['update_settings']['plugins']['included'] ) ) {
$current['update_settings']['plugins']['included'] = $new['update_settings']['plugins']['included'];
} else {
$current['update_settings']['plugins']['included'] = array();
}
if ( isset( $new['update_settings']['themes']['included'] ) ) {
$current['update_settings']['themes']['included'] = $new['update_settings']['themes']['included'];
} else {
$current['update_settings']['themes']['included'] = array();
}
}
$config->set_option( 'wptc_auto_update_settings', serialize( $current ) ); // phpcs:ignore -- third party credit.
$this->save_settings_backup_auto_tab( $config, $data, $is_general );
$saved = true;
} elseif ( 'vulns_update' == $tabName ) {
$current = $config->get_option( 'vulns_settings' );
$current = unserialize( $current ); // phpcs:ignore -- third party credit.
$new = unserialize( $data['vulns_settings'] ); // phpcs:ignore -- third party credit.
$current['status'] = $new['status'];
$current['core']['status'] = $new['core']['status'];
$current['themes']['status'] = $new['themes']['status'];
$current['plugins']['status'] = $new['plugins']['status'];
if ( ! $is_general ) {
$vulns_plugins_included = ! empty( $new['plugins']['vulns_plugins_included'] ) ? $new['plugins']['vulns_plugins_included'] : array();
$plugin_include_array = array();
if ( ! empty( $vulns_plugins_included ) ) {
$plugin_include_array = explode( ',', $vulns_plugins_included );
$plugin_include_array = ! empty( $plugin_include_array ) ? $plugin_include_array : array();
}
wptc_log( $plugin_include_array, '--------$plugin_include_array--------' );
$included_plugins = $this->filter_plugins( $plugin_include_array );
wptc_log( $included_plugins, '--------$included_plugins--------' );
$current['plugins']['excluded'] = serialize( $included_plugins ); // phpcs:ignore -- third party credit.
$vulns_themes_included = ! empty( $new['themes']['vulns_themes_included'] ) ? $new['themes']['vulns_themes_included'] : array();
$themes_include_array = array();
if ( ! empty( $vulns_themes_included ) ) {
$themes_include_array = explode( ',', $vulns_themes_included );
}
$included_themes = $this->filter_themes( $themes_include_array );
$current['themes']['excluded'] = serialize( $included_themes ); // phpcs:ignore -- third party credit.
}
$config->set_option( 'vulns_settings', serialize( $current ) ); // phpcs:ignore -- third party credit.
$this->save_settings_vulns_update_tab( $config, $data, $is_general );
$saved = true;
} elseif ( 'staging_opts' == $tabName ) {
$config->set_option( 'user_excluded_extenstions_staging', $data['user_excluded_extenstions_staging'] );
$config->set_option( 'internal_staging_db_rows_copy_limit', $data['internal_staging_db_rows_copy_limit'] );
$config->set_option( 'internal_staging_file_copy_limit', $data['internal_staging_file_copy_limit'] );
$config->set_option( 'internal_staging_deep_link_limit', $data['internal_staging_deep_link_limit'] );
$config->set_option( 'internal_staging_enable_admin_login', $data['internal_staging_enable_admin_login'] );
$config->set_option( 'staging_is_reset_permalink', $data['staging_is_reset_permalink'] );
if ( ! $is_general ) {
$config->set_option( 'staging_login_custom_link', $data['staging_login_custom_link'] );
}
$this->save_settings_staging_opts_tab( $config, $data, $is_general );
$saved = true;
}
if ( ! $saved ) {
return array( 'error' => 'Error: Not saved settings' );
}
return array( 'result' => 'ok' );
}
private function save_settings_backup_tab( $config, $data ){
$config->set_option( 'user_excluded_extenstions', $data['user_excluded_extenstions'] );
$config->set_option( 'user_excluded_files_more_than_size_settings', $data['user_excluded_files_more_than_size_settings'] );
if ( ! empty( $data['backup_slot'] ) ) {
$config->set_option( 'old_backup_slot', $config->get_option( 'backup_slot' ) );
$config->set_option( 'backup_slot', $data['backup_slot'] );
}
$config->set_option( 'backup_db_query_limit', $data['backup_db_query_limit'] );
$config->set_option( 'database_encrypt_settings', $data['database_encrypt_settings'] );
$config->set_option( 'wptc_timezone', $data['wptc_timezone'] );
$config->set_option( 'schedule_time_str', $data['schedule_time_str'] );
if ( ! empty( $data['schedule_time_str'] ) && ! empty( $data['wptc_timezone'] ) ) {
if ( function_exists( 'wptc_modify_schedule_backup' ) ) {
wptc_modify_schedule_backup();
}
}
$notice = apply_filters( 'check_requirements_auto_backup_wptc', '' );
if ( ! empty( $data['revision_limit'] ) && ! $notice ) {
$notice = apply_filters( 'save_settings_revision_limit_wptc', $data['revision_limit'] );
}
}
private function save_settings_backup_auto_tab( $config, $data, $is_general ) {
$config->set_option( 'backup_before_update_setting', $data['backup_before_update_setting'] );
$current = $config->get_option( 'wptc_auto_update_settings' );
$current = unserialize( $current ); // phpcs:ignore -- third party credit.
$new = unserialize( $data['wptc_auto_update_settings'] ); // phpcs:ignore -- third party credit.
$current['update_settings']['status'] = $new['update_settings']['status'];
$current['update_settings']['schedule']['enabled'] = $new['update_settings']['schedule']['enabled'];
$current['update_settings']['schedule']['time'] = $new['update_settings']['schedule']['time'];
$current['update_settings']['core']['major']['status'] = $new['update_settings']['core']['major']['status'];
$current['update_settings']['core']['minor']['status'] = $new['update_settings']['core']['minor']['status'];
$current['update_settings']['themes']['status'] = $new['update_settings']['themes']['status'];
$current['update_settings']['plugins']['status'] = $new['update_settings']['plugins']['status'];
if ( ! $is_general ) {
if ( isset( $new['update_settings']['plugins']['included'] ) ) {
$current['update_settings']['plugins']['included'] = $new['update_settings']['plugins']['included'];
} else {
$current['update_settings']['plugins']['included'] = array();
}
if ( isset( $new['update_settings']['themes']['included'] ) ) {
$current['update_settings']['themes']['included'] = $new['update_settings']['themes']['included'];
} else {
$current['update_settings']['themes']['included'] = array();
}
}
$config->set_option( 'wptc_auto_update_settings', serialize( $current ) ); // phpcs:ignore -- third party credit.
}
private function save_settings_vulns_update_tab( $config, $data, $is_general ){
$current = $config->get_option( 'vulns_settings' );
$current = unserialize( $current ); // phpcs:ignore -- third party credit.
$new = unserialize( $data['vulns_settings'] ); // phpcs:ignore -- third party credit.
$current['status'] = $new['status'];
$current['core']['status'] = $new['core']['status'];
$current['themes']['status'] = $new['themes']['status'];
$current['plugins']['status'] = $new['plugins']['status'];
if ( ! $is_general ) {
$vulns_plugins_included = ! empty( $new['plugins']['vulns_plugins_included'] ) ? $new['plugins']['vulns_plugins_included'] : array();
$plugin_include_array = array();
if ( ! empty( $vulns_plugins_included ) ) {
$plugin_include_array = explode( ',', $vulns_plugins_included );
$plugin_include_array = ! empty( $plugin_include_array ) ? $plugin_include_array : array();
}
wptc_log( $plugin_include_array, '--------$plugin_include_array--------' );
$included_plugins = $this->filter_plugins( $plugin_include_array );
wptc_log( $included_plugins, '--------$included_plugins--------' );
$current['plugins']['excluded'] = serialize( $included_plugins ); // phpcs:ignore -- third party credit.
$vulns_themes_included = ! empty( $new['themes']['vulns_themes_included'] ) ? $new['themes']['vulns_themes_included'] : array();
$themes_include_array = array();
if ( ! empty( $vulns_themes_included ) ) {
$themes_include_array = explode( ',', $vulns_themes_included );
}
$included_themes = $this->filter_themes( $themes_include_array );
$current['themes']['excluded'] = serialize( $included_themes ); // phpcs:ignore -- third party credit.
}
$config->set_option( 'vulns_settings', serialize( $current ) ); // phpcs:ignore -- third party credit.
}
private function save_settings_staging_opts_tab( $config, $data, $is_general ){
$config->set_option( 'user_excluded_extenstions_staging', $data['user_excluded_extenstions_staging'] );
$config->set_option( 'internal_staging_db_rows_copy_limit', $data['internal_staging_db_rows_copy_limit'] );
$config->set_option( 'internal_staging_file_copy_limit', $data['internal_staging_file_copy_limit'] );
$config->set_option( 'internal_staging_deep_link_limit', $data['internal_staging_deep_link_limit'] );
$config->set_option( 'internal_staging_enable_admin_login', $data['internal_staging_enable_admin_login'] );
$config->set_option( 'staging_is_reset_permalink', $data['staging_is_reset_permalink'] );
if ( ! $is_general ) {
$config->set_option( 'staging_login_custom_link', $data['staging_login_custom_link'] );
}
}
private function filter_plugins( $included_plugins ) {
$app_functions = WPTC_Base_Factory::get( 'Wptc_App_Functions' );
$specific = true;

View file

@ -270,66 +270,8 @@ class MainWP_Client_Report {
unset( $args[ $arg ] );
}
}
$exclude_connector_posts = true;
if ( isset( $sections['body'] ) && isset( $sections['body']['section_token'] ) && is_array( $sections['body']['section_token'] ) ) {
foreach ( $sections['body']['section_token'] as $sec ) {
if ( false !== strpos( $sec, '[section.posts' ) || false !== strpos( $sec, '[section.pages' ) ) {
$exclude_connector_posts = false;
break;
}
}
}
if ( $exclude_connector_posts ) {
if ( isset( $sections['header'] ) && isset( $sections['header']['section_token'] ) && is_array( $sections['header']['section_token'] ) ) {
foreach ( $sections['header']['section_token'] as $sec ) {
if ( false !== strpos( $sec, '[section.posts' ) || false !== strpos( $sec, '[section.pages' ) ) {
$exclude_connector_posts = false;
break;
}
}
}
}
if ( $exclude_connector_posts ) {
if ( isset( $sections['footer'] ) && isset( $sections['footer']['section_token'] ) && is_array( $sections['footer']['section_token'] ) ) {
foreach ( $sections['footer']['section_token'] as $sec ) {
if ( false !== strpos( $sec, '[section.posts' ) || false !== strpos( $sec, '[section.pages' ) ) {
$exclude_connector_posts = false;
break;
}
}
}
}
if ( $exclude_connector_posts ) {
if ( isset( $other_tokens['body'] ) && is_array( $other_tokens['body'] ) ) {
foreach ( $other_tokens['body'] as $sec ) {
if ( false !== strpos( $sec, '[post.' ) || false !== strpos( $sec, '[page.' ) ) {
$exclude_connector_posts = false;
break;
}
}
}
}
if ( $exclude_connector_posts ) {
if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) {
foreach ( $other_tokens['header'] as $sec ) {
if ( false !== strpos( $sec, '[post.' ) || false !== strpos( $sec, '[page.' ) ) {
$exclude_connector_posts = false;
break;
}
}
}
}
if ( $exclude_connector_posts ) {
if ( isset( $other_tokens['footer'] ) && is_array( $other_tokens['footer'] ) ) {
foreach ( $other_tokens['footer'] as $sec ) {
if ( false !== strpos( $sec, '[post.' ) || false !== strpos( $sec, '[page.' ) ) {
$exclude_connector_posts = false;
break;
}
}
}
}
$exclude_connector_posts = $this->get_stream_get_not_in_params( $sections, $other_tokens );
if ( $exclude_connector_posts ) {
$args['connector__not_in'] = array( 'posts' );
}
@ -355,6 +297,41 @@ class MainWP_Client_Report {
return $args;
}
private function get_stream_get_not_in_params( $sections, $other_tokens ){
$exclude_connector_posts = true;
$parts = array( 'header', 'body', 'footer' );
foreach( $parts as $part) {
if ( isset( $sections[ $part ] ) && isset( $sections[ $part ]['section_token'] ) && is_array( $sections[ $part ]['section_token'] ) ) {
foreach ( $sections[ $part ]['section_token'] as $sec ) {
if ( false !== strpos( $sec, '[section.posts' ) || false !== strpos( $sec, '[section.pages' ) ) {
$exclude_connector_posts = false;
break;
}
}
}
if ( ! $exclude_connector_posts )
break;
}
if ( $exclude_connector_posts ) {
foreach( $parts as $part) {
if ( isset( $other_tokens[ $part ] ) && is_array( $other_tokens[ $part ] ) ) {
foreach ( $other_tokens[ $part ] as $sec ) {
if ( false !== strpos( $sec, '[post.' ) || false !== strpos( $sec, '[page.' ) ) {
$exclude_connector_posts = false;
break;
}
}
}
if ( ! $exclude_connector_posts )
break;
}
}
return $exclude_connector_posts;
}
private function get_stream_others_tokens( $records, $other_tokens, $skip_records ) {
$other_tokens_data = array();
$parts = array( 'header', 'body', 'footer' );
@ -443,15 +420,13 @@ class MainWP_Client_Report {
}
$backups_created_time_to_fix = array();
foreach ( $tokens as $token ) {
if ( isset( $token_values[ $token ] ) ) {
continue;
}
$str_tmp = str_replace( array( '[', ']' ), '', $token );
$array_tmp = explode( '.', $str_tmp );
if ( is_array( $array_tmp ) ) {
$context = '';
$action = '';
@ -461,116 +436,20 @@ class MainWP_Client_Report {
} elseif ( 3 === count( $array_tmp ) ) {
list( $context, $action, $data ) = $array_tmp;
}
$context = $this->get_compatible_context( $context );
// to compatible with new version of child report.
// to check condition for grabbing report data.
$connector = $this->get_connector_by_compatible_context( $context );
$action = $this->get_compatible_action( $action, $context );
// custom values.
if ( 'profiles' == $context ) {
if ( 'created' == $action || 'deleted' == $action ) {
$context = 'users'; // see class-connector-user.php.
}
}
switch ( $data ) {
case 'count':
$count = 0;
foreach ( $records as $record ) {
// check connector.
if ( 'editor' == $record->connector ) {
if ( ! in_array( $context, array( 'plugins', 'themes' ) ) || 'updated' !== $action ) {
continue;
}
} elseif ( $connector !== $record->connector ) {
continue;
}
$valid_context = false;
// check context.
if ( 'comments' == $context ) { // multi values.
$comment_contexts = array( 'post', 'page' );
if ( ! in_array( $record->context, $comment_contexts ) ) {
continue;
}
$valid_context = true;
} elseif ( 'post' === $context && 'created' === $action ) {
if ( in_array( $record->ID, $skip_records ) ) {
continue;
}
$valid_context = true;
} elseif ( 'menus' == $context ) {
$valid_context = true; // ok, pass, don't check context.
} elseif ( 'editor' == $record->connector ) {
$valid_context = true; // ok, pass, checked above.
} elseif ( 'media' == $connector && 'media' == $record->connector ) {
$valid_context = true; // ok, pass, do not check context.
} elseif ( 'widgets' == $connector && 'widgets' == $record->connector ) {
$valid_context = true; // ok, pass, don't check context.
}
if ( ! $valid_context || strtolower( $record->context ) !== $context ) {
continue;
}
// custom action value.
if ( 'widgets' == $connector ) {
if ( 'deleted' == $action ) {
$action = 'removed'; // action saved in database.
}
}
// check action.
if ( 'backups' === $context ) {
if ( ! $this->is_backup_action( $record->action ) ) {
continue;
}
$created = strtotime( $record->created );
if ( in_array( $created, $backups_created_time_to_fix ) ) {
if ( ! in_array( $record->ID, $skip_records ) ) {
$skip_records[] = $record->ID;
}
continue;
} else {
$backups_created_time_to_fix[] = $created;
}
} else {
if ( $action !== $record->action ) {
continue;
}
if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
$new_status = $this->get_stream_meta_data( $record, 'new_status' );
if ( 'draft' === $new_status ) {
continue;
}
} elseif ( 'updated' === $action && ( 'themes' === $context || 'plugins' === $context ) ) {
$name = $this->get_stream_meta_data( $record, 'name' );
if ( empty( $name ) ) {
if ( ! in_array( $record->ID, $skip_records ) ) {
$skip_records[] = $record->ID;
}
continue;
} else {
$old_version = $this->get_stream_meta_data( $record, 'old_version' );
$version = $this->get_stream_meta_data( $record, 'version' );
if ( version_compare( $version, $old_version, '<=' ) ) {
if ( ! in_array( $record->ID, $skip_records ) ) {
$skip_records[] = $record->ID;
}
continue;
}
}
}
}
$count ++;
}
$token_values[ $token ] = $count;
case 'count':
$token_values[ $token ] = $this->get_other_tokens_count( $records, $connector, $context, $action, $skip_records, $backups_created_time_to_fix );
break;
}
}
@ -579,6 +458,101 @@ class MainWP_Client_Report {
return $token_values;
}
private function get_other_tokens_count( $records, $connector, $context, $action, &$skip_records, &$backups_created_time_to_fix ){
$count = 0;
foreach ( $records as $record ) {
// check connector.
if ( 'editor' == $record->connector ) {
if ( ! in_array( $context, array( 'plugins', 'themes' ) ) || 'updated' !== $action ) {
continue;
}
} elseif ( $connector !== $record->connector ) {
continue;
}
$valid_context = false;
// check context.
if ( 'comments' == $context ) { // multi values.
$comment_contexts = array( 'post', 'page' );
if ( ! in_array( $record->context, $comment_contexts ) ) {
continue;
}
$valid_context = true;
} elseif ( 'post' === $context && 'created' === $action ) {
if ( in_array( $record->ID, $skip_records ) ) {
continue;
}
$valid_context = true;
} elseif ( 'menus' == $context ) {
$valid_context = true; // ok, pass, don't check context.
} elseif ( 'editor' == $record->connector ) {
$valid_context = true; // ok, pass, checked above.
} elseif ( 'media' == $connector && 'media' == $record->connector ) {
$valid_context = true; // ok, pass, do not check context.
} elseif ( 'widgets' == $connector && 'widgets' == $record->connector ) {
$valid_context = true; // ok, pass, don't check context.
}
if ( ! $valid_context || strtolower( $record->context ) !== $context ) {
continue;
}
// custom action value.
if ( 'widgets' == $connector ) {
if ( 'deleted' == $action ) {
$action = 'removed'; // action saved in database.
}
}
// check action.
if ( 'backups' === $context ) {
if ( ! $this->is_backup_action( $record->action ) ) {
continue;
}
$created = strtotime( $record->created );
if ( in_array( $created, $backups_created_time_to_fix ) ) {
if ( ! in_array( $record->ID, $skip_records ) ) {
$skip_records[] = $record->ID;
}
continue;
} else {
$backups_created_time_to_fix[] = $created;
}
} else {
if ( $action !== $record->action ) {
continue;
}
if ( 'updated' === $action && ( 'post' === $context || 'page' === $context ) ) {
$new_status = $this->get_stream_meta_data( $record, 'new_status' );
if ( 'draft' === $new_status ) {
continue;
}
} elseif ( 'updated' === $action && ( 'themes' === $context || 'plugins' === $context ) ) {
$name = $this->get_stream_meta_data( $record, 'name' );
if ( empty( $name ) ) {
if ( ! in_array( $record->ID, $skip_records ) ) {
$skip_records[] = $record->ID;
}
continue;
} else {
$old_version = $this->get_stream_meta_data( $record, 'old_version' );
$version = $this->get_stream_meta_data( $record, 'version' );
if ( version_compare( $version, $old_version, '<=' ) ) {
if ( ! in_array( $record->ID, $skip_records ) ) {
$skip_records[] = $record->ID;
}
continue;
}
}
}
}
$count ++;
}
return $count;
}
public function get_section_loop_data( $records, $tokens, $section, $skip_records = array() ) {
$context = '';
@ -671,50 +645,8 @@ class MainWP_Client_Report {
if ( 'draft' === $new_status ) { // avoid auto save post!
continue;
}
}
$token_values = array();
foreach ( $tokens as $token ) {
$data = '';
$token_name = str_replace( array( '[', ']' ), '', $token );
$array_tmp = explode( '.', $token_name );
if ( 'user.name' === $token_name ) {
$data = 'display_name';
} else {
if ( 1 === count( $array_tmp ) ) {
list( $data ) = $array_tmp;
} elseif ( 2 === count( $array_tmp ) ) {
list( $str1, $data ) = $array_tmp;
} elseif ( 3 === count( $array_tmp ) ) {
list( $str1, $str2, $data ) = $array_tmp;
}
if ( 'version' === $data ) {
if ( 'old' === $str2 ) {
$data = 'old_version';
} elseif ( 'current' === $str2 && 'WordPress' === $str1 ) {
$data = 'new_version';
}
}
}
if ( 'role' === $data ) {
$data = 'roles';
}
$tok_value = $this->get_section_loop_token_value( $record, $data, $context, $token );
$token_values[ $token ] = $tok_value;
if ( empty( $tok_value ) ) {
$msg = 'MainWP Child Report:: skip empty value :: token :: ' . $token . ' :: record :: ' . print_r( $record, true ); // phpcs:ignore -- debug mode only.
MainWP_Helper::log_debug( $msg );
}
}
}
$token_values = $this->get_section_loop_token_values( $record, $context, $tokens );
if ( ! empty( $token_values ) ) {
$loops[ $loop_count ] = $token_values;
$loop_count ++;
@ -723,10 +655,52 @@ class MainWP_Client_Report {
return $loops;
}
private function get_section_loop_token_values( $record, $context, $tokens ){
$token_values = array();
foreach ( $tokens as $token ) {
$data = '';
$token_name = str_replace( array( '[', ']' ), '', $token );
$array_tmp = explode( '.', $token_name );
if ( 'user.name' === $token_name ) {
$data = 'display_name';
} else {
if ( 1 === count( $array_tmp ) ) {
list( $data ) = $array_tmp;
} elseif ( 2 === count( $array_tmp ) ) {
list( $str1, $data ) = $array_tmp;
} elseif ( 3 === count( $array_tmp ) ) {
list( $str1, $str2, $data ) = $array_tmp;
}
if ( 'version' === $data ) {
if ( 'old' === $str2 ) {
$data = 'old_version';
} elseif ( 'current' === $str2 && 'WordPress' === $str1 ) {
$data = 'new_version';
}
}
}
if ( 'role' === $data ) {
$data = 'roles';
}
$tok_value = $this->get_section_loop_token_value( $record, $data, $context, $token );
$token_values[ $token ] = $tok_value;
if ( empty( $tok_value ) ) {
$msg = 'MainWP Child Report:: skip empty value :: token :: ' . $token . ' :: record :: ' . print_r( $record, true ); // phpcs:ignore -- debug mode only.
MainWP_Helper::log_debug( $msg );
}
}
return $token_values;
}
public function get_section_loop_token_value( $record, $data, $context, $token ) {
$tok_value = '';
switch ( $data ) {
case 'ID':
$tok_value = $record->ID;
@ -752,7 +726,7 @@ class MainWP_Client_Report {
$data = 'display_name';
}
}
$tok_value = $this->get_stream_meta_data( $record, $data );
$tok_value = $this->get_stream_meta_data( $record, $data );
break;
case 'title':
if ( 'comments' === $context ) {
@ -766,53 +740,20 @@ class MainWP_Client_Report {
$tok_value = $this->get_stream_meta_data( $record, $data );
}
break;
case 'author':
if ( 'comment' == $connector ) {
$data = 'user_name';
} else {
$data = 'user_meta';
}
$value = $this->get_stream_meta_data( $record, $data );
if ( empty( $value ) && 'comments' === $context ) {
$value = __( 'Guest', 'mainwp-child' );
}
// check compatibility with old meta data.
if ( empty( $value ) ) {
$value = $this->get_stream_meta_data( $record, 'author_meta' );
}
$tok_value = $value;
case 'author':
$tok_value = $this->get_author_data_token_value( $record, $connector, $context, $data );;
break;
case 'status':
case 'webtrust':
$value = '';
if ( 'sucuri_scan' === $context ) {
$tok_value = $this->get_sucuri_scan_token_value( $record, $data );
} else {
$tok_value = $value;
$value = $this->get_sucuri_scan_token_value( $record, $data );
}
$tok_value = $value;
break;
case 'details':
case 'result':
if ( 'mainwp_maintenance' === $context && 'details' == $data ) {
$tok_value = $this->get_mainwp_maintenance_token_value( $record, $data );
} elseif ( 'wordfence_scan' === $context || 'mainwp_maintenance' === $context ) {
$meta_value = $this->get_stream_meta_data( $record, $data );
if ( 'wordfence_scan' === $context && 'result' == $data ) {
// SUM_FINAL:Scan complete. You have xxx new issues to fix. See below.
// SUM_FINAL:Scan complete. Congratulations, no new problems found.
if ( stripos( $meta_value, 'Congratulations' ) ) {
$meta_value = 'No issues detected';
} elseif ( stripos( $meta_value, 'You have' ) ) {
$meta_value = 'Issues Detected';
} else {
$meta_value = '';
}
}
$tok_value = $meta_value;
}
$tok_value = $this->get_result_data_token_value( $record, $context, $data );
break;
case 'type':
if ( 'backups' === $context ) {
@ -825,7 +766,6 @@ class MainWP_Client_Report {
$tok_value = 'N/A';
break;
}
return $tok_value;
}
@ -867,8 +807,50 @@ class MainWP_Client_Report {
return $value;
}
private function get_author_data_token_value( $record, $connector, $context, $data ){
if ( 'comment' == $connector ) {
$data = 'user_name';
} else {
$data = 'user_meta';
}
$value = $this->get_stream_meta_data( $record, $data );
if ( empty( $value ) && 'comments' === $context ) {
$value = __( 'Guest', 'mainwp-child' );
}
// check compatibility with old meta data.
if ( empty( $value ) ) {
$value = $this->get_stream_meta_data( $record, 'author_meta' );
}
return $value;
}
private function get_result_data_token_value( $record, $context, $data ){
if ( 'mainwp_maintenance' === $context && 'details' == $data ) {
$tok_value = $this->get_mainwp_maintenance_token_value( $record, $data );
} elseif ( 'wordfence_scan' === $context || 'mainwp_maintenance' === $context ) {
$meta_value = $this->get_stream_meta_data( $record, $data );
if ( 'wordfence_scan' === $context && 'result' == $data ) {
// SUM_FINAL:Scan complete. You have xxx new issues to fix. See below.
// SUM_FINAL:Scan complete. Congratulations, no new problems found.
if ( stripos( $meta_value, 'Congratulations' ) ) {
$meta_value = 'No issues detected';
} elseif ( stripos( $meta_value, 'You have' ) ) {
$meta_value = 'Issues Detected';
} else {
$meta_value = '';
}
}
$tok_value = $meta_value;
}
return $tok_value;
}
private function get_sucuri_scan_token_value( $record, $data ) {
$scan_data = $this->get_stream_meta_data( $record, 'scan_data' );
$tok_value = '';
$scan_data = $this->get_stream_meta_data( $record, 'scan_data' );
if ( ! empty( $scan_data ) ) {
$scan_data = maybe_unserialize( base64_decode( $scan_data ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
if ( is_array( $scan_data ) ) {

View file

@ -647,84 +647,85 @@ class MainWP_Clone_Install {
mainwp_child_helper()->write( array( 'size' => filesize( $archiveFile ) ) );
} elseif ( 'createCloneBackup' === $_POST['cloneFunc'] ) {
MainWP_Helper::end_session();
$files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' );
foreach ( $files as $file ) {
unlink( $file );
}
if ( file_exists( ABSPATH . 'clone/config.txt' ) ) {
unlink( ABSPATH . 'clone/config.txt' );
}
if ( MainWP_Helper::is_dir_empty( ABSPATH . 'clone' ) ) {
rmdir( ABSPATH . 'clone' );
}
$wpversion = $_POST['wpversion'];
global $wp_version;
$includeCoreFiles = ( $wpversion !== $wp_version );
$excludes = ( isset( $_POST['exclude'] ) ? explode( ',', $_POST['exclude'] ) : array() );
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/mainwp';
$uploadDir = MainWP_Helper::get_mainwp_dir();
$uploadDir = $uploadDir[0];
$excludes[] = str_replace( ABSPATH, '', $uploadDir );
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/object-cache.php';
if ( version_compare( phpversion(), '5.3.0' ) >= 0 || ! ini_get( 'safe_mode' ) ) {
set_time_limit( 6000 );
}
$newExcludes = array();
foreach ( $excludes as $exclude ) {
$newExcludes[] = rtrim( $exclude, '/' );
}
$method = ( ! isset( $_POST['zipmethod'] ) ? 'tar.gz' : $_POST['zipmethod'] );
if ( 'tar.gz' === $method && ! function_exists( 'gzopen' ) ) {
$method = 'zip';
}
$res = MainWP_Backup::get()->create_full_backup( $newExcludes, ( isset( $_POST['f'] ) ? $_POST['f'] : $_POST['file'] ), true, $includeCoreFiles, 0, false, false, false, false, $method );
if ( ! $res ) {
$information['backup'] = false;
} else {
$information['backup'] = $res['file'];
$information['size'] = $res['filesize'];
}
$plugins = array();
$dir = WP_CONTENT_DIR . '/plugins/';
$fh = opendir( $dir );
$entry = readdir( $fh );
while ( $entry ) {
if ( ! is_dir( $dir . $entry ) ) {
continue;
}
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
continue;
}
$plugins[] = $entry;
}
closedir( $fh );
$information['plugins'] = $plugins;
$themes = array();
$dir = WP_CONTENT_DIR . '/themes/';
$fh = opendir( $dir );
while ( $entry = readdir( $fh ) ) {
if ( ! is_dir( $dir . $entry ) ) {
continue;
}
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
continue;
}
$themes[] = $entry;
}
closedir( $fh );
$information['themes'] = $themes;
mainwp_child_helper()->write( $information );
$this->create_clone_backup();
}
return true;
return true;
}
private function create_clone_backup(){
MainWP_Helper::end_session();
$files = glob( WP_CONTENT_DIR . '/dbBackup*.sql' );
foreach ( $files as $file ) {
unlink( $file );
}
if ( file_exists( ABSPATH . 'clone/config.txt' ) ) {
unlink( ABSPATH . 'clone/config.txt' );
}
if ( MainWP_Helper::is_dir_empty( ABSPATH . 'clone' ) ) {
rmdir( ABSPATH . 'clone' );
}
$wpversion = $_POST['wpversion'];
global $wp_version;
$includeCoreFiles = ( $wpversion !== $wp_version );
$excludes = ( isset( $_POST['exclude'] ) ? explode( ',', $_POST['exclude'] ) : array() );
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/uploads/mainwp';
$uploadDir = MainWP_Helper::get_mainwp_dir();
$uploadDir = $uploadDir[0];
$excludes[] = str_replace( ABSPATH, '', $uploadDir );
$excludes[] = str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '/object-cache.php';
if ( version_compare( phpversion(), '5.3.0' ) >= 0 || ! ini_get( 'safe_mode' ) ) {
set_time_limit( 6000 );
}
$newExcludes = array();
foreach ( $excludes as $exclude ) {
$newExcludes[] = rtrim( $exclude, '/' );
}
$method = ( ! isset( $_POST['zipmethod'] ) ? 'tar.gz' : $_POST['zipmethod'] );
if ( 'tar.gz' === $method && ! function_exists( 'gzopen' ) ) {
$method = 'zip';
}
$res = MainWP_Backup::get()->create_full_backup( $newExcludes, ( isset( $_POST['f'] ) ? $_POST['f'] : $_POST['file'] ), true, $includeCoreFiles, 0, false, false, false, false, $method );
if ( ! $res ) {
$information['backup'] = false;
} else {
$information['backup'] = $res['file'];
$information['size'] = $res['filesize'];
}
$plugins = array();
$dir = WP_CONTENT_DIR . '/plugins/';
$fh = opendir( $dir );
$entry = readdir( $fh );
while ( $entry ) {
if ( ! is_dir( $dir . $entry ) ) {
continue;
}
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
continue;
}
$plugins[] = $entry;
}
closedir( $fh );
$information['plugins'] = $plugins;
$themes = array();
$dir = WP_CONTENT_DIR . '/themes/';
$fh = opendir( $dir );
while ( $entry = readdir( $fh ) ) {
if ( ! is_dir( $dir . $entry ) ) {
continue;
}
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
continue;
}
$themes[] = $entry;
}
closedir( $fh );
$information['themes'] = $themes;
mainwp_child_helper()->write( $information );
}
}

View file

@ -814,55 +814,7 @@ class Tar_Archiver {
}
} elseif ( 0 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
$previousFtell = ftell( $this->archive );
$bytes = $file['stat'][7] + ( 512 == ( 512 - $file['stat'][7] % 512 ) ? 0 : ( 512 - $file['stat'][7] % 512 ) );
fseek( $this->archive, ftell( $this->archive ) + $bytes );
$ftell = ftell( $this->archive );
if ( 'tar.gz' == $this->type ) {
if ( ( false === $ftell ) || ( -1 == $ftell ) ) {
fseek( $this->archive, $previousFtell );
$bytesRead = 0;
$bytesToRead = $file['stat'][7];
while ( $bytesToRead > 0 ) {
$readNow = $bytesToRead > 1024 ? 1024 : $bytesToRead;
$bytesCurrentlyRead = strlen( fread( $this->archive, $readNow ) );
if ( 0 == $bytesCurrentlyRead ) {
break;
}
$bytesRead += $bytesCurrentlyRead;
$bytesToRead -= $bytesCurrentlyRead;
}
if ( 0 == $bytesToRead ) {
$toRead = ( 512 - $file['stat'][7] % 512 ) == 512 ? 0 : ( 512 - $file['stat'][7] % 512 );
if ( $toRead > 0 ) {
$read = strlen( fread( $this->archive, $toRead ) );
$bytesRead += $read;
}
}
$rslt['bytesRead'] = $bytesRead;
$rslt['readOffset'] = $previousFtell;
$this->log( 'Will append this: ' . print_r( $rslt, 1 ) ); // phpcs:ignore -- debug feature.
return $rslt;
}
} elseif ( ( 'tar' == $this->type ) && ( ( false === $ftell ) || ( -1 == $ftell ) ) ) {
$this->log( 'Will append this: ' . print_r( $rslt, 1 ) ); // phpcs:ignore -- debug feature.
return $rslt;
}
$this->log( 'Skipping file [' . $file['name'] . ']' );
return true;
return $this->read_next_bytes( $file );
} else {
$this->log( 'Unexpected file [' . $file['name'] . ']' );
throw new \Exception( 'Unexpected file' );
@ -877,6 +829,54 @@ class Tar_Archiver {
}
}
private function read_next_bytes( $file ){
$previousFtell = ftell( $this->archive );
$bytes = $file['stat'][7] + ( 512 == ( 512 - $file['stat'][7] % 512 ) ? 0 : ( 512 - $file['stat'][7] % 512 ) );
fseek( $this->archive, ftell( $this->archive ) + $bytes );
$ftell = ftell( $this->archive );
if ( 'tar.gz' == $this->type ) {
if ( ( false === $ftell ) || ( -1 == $ftell ) ) {
fseek( $this->archive, $previousFtell );
$bytesRead = 0;
$bytesToRead = $file['stat'][7];
while ( $bytesToRead > 0 ) {
$readNow = $bytesToRead > 1024 ? 1024 : $bytesToRead;
$bytesCurrentlyRead = strlen( fread( $this->archive, $readNow ) );
if ( 0 == $bytesCurrentlyRead ) {
break;
}
$bytesRead += $bytesCurrentlyRead;
$bytesToRead -= $bytesCurrentlyRead;
}
if ( 0 == $bytesToRead ) {
$toRead = ( 512 - $file['stat'][7] % 512 ) == 512 ? 0 : ( 512 - $file['stat'][7] % 512 );
if ( $toRead > 0 ) {
$read = strlen( fread( $this->archive, $toRead ) );
$bytesRead += $read;
}
}
$rslt['bytesRead'] = $bytesRead;
$rslt['readOffset'] = $previousFtell;
$this->log( 'Will append this: ' . print_r( $rslt, 1 ) ); // phpcs:ignore -- debug feature.
return $rslt;
}
} elseif ( ( 'tar' == $this->type ) && ( ( false === $ftell ) || ( -1 == $ftell ) ) ) {
$this->log( 'Will append this: ' . print_r( $rslt, 1 ) ); // phpcs:ignore -- debug feature.
return $rslt;
}
$this->log( 'Skipping file [' . $file['name'] . ']' );
return true;
}
public function log( $text ) {
if ( $this->logHandle ) {
fwrite( $this->logHandle, $text . "\n" );