This commit is contained in:
2024-03-05 22:58:01 -06:00
parent f2edb49d22
commit 58806aba64
262 changed files with 31855 additions and 3 deletions

View File

@ -0,0 +1,46 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Archive {
public static function execute( $params ) {
// Set progress
Ai1wm_Status::info( __( 'Creating an empty archive...', AI1WM_PLUGIN_NAME ) );
// Create empty archive file
$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
$archive->close();
// Set progress
Ai1wm_Status::info( __( 'Done creating an empty archive.', AI1WM_PLUGIN_NAME ) );
return $params;
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Clean {
public static function execute( $params ) {
// Delete storage files
Ai1wm_Directory::delete( ai1wm_storage_path( $params ) );
// Exit in console
if ( defined( 'WP_CLI' ) ) {
return $params;
}
exit;
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Compatibility {
public static function execute( $params ) {
// Set progress
Ai1wm_Status::info( __( 'Checking extensions compatibility...', AI1WM_PLUGIN_NAME ) );
// Get messages
$messages = Ai1wm_Compatibility::get( $params );
// Set messages
if ( empty( $messages ) ) {
return $params;
}
// Error message
throw new Ai1wm_Compatibility_Exception( implode( $messages ) );
}
}

View File

@ -0,0 +1,119 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Config_File {
public static function execute( $params ) {
$package_bytes_written = 0;
// Set archive bytes offset
if ( isset( $params['archive_bytes_offset'] ) ) {
$archive_bytes_offset = (int) $params['archive_bytes_offset'];
} else {
$archive_bytes_offset = ai1wm_archive_bytes( $params );
}
// Set package bytes offset
if ( isset( $params['package_bytes_offset'] ) ) {
$package_bytes_offset = (int) $params['package_bytes_offset'];
} else {
$package_bytes_offset = 0;
}
// Get total package size
if ( isset( $params['total_package_size'] ) ) {
$total_package_size = (int) $params['total_package_size'];
} else {
$total_package_size = ai1wm_package_bytes( $params );
}
// What percent of package have we processed?
$progress = (int) min( ( $package_bytes_offset / $total_package_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving configuration file...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $progress ) );
// Open the archive file for writing
$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
// Set the file pointer to the one that we have saved
$archive->set_file_pointer( $archive_bytes_offset );
// Add package.json to archive
if ( $archive->add_file( ai1wm_package_path( $params ), AI1WM_PACKAGE_NAME, $package_bytes_written, $package_bytes_offset ) ) {
// Set progress
Ai1wm_Status::info( __( 'Done archiving configuration file.', AI1WM_PLUGIN_NAME ) );
// Unset archive bytes offset
unset( $params['archive_bytes_offset'] );
// Unset package bytes offset
unset( $params['package_bytes_offset'] );
// Unset total package size
unset( $params['total_package_size'] );
// Unset completed flag
unset( $params['completed'] );
} else {
// Get archive bytes offset
$archive_bytes_offset = $archive->get_file_pointer();
// What percent of package have we processed?
$progress = (int) min( ( $package_bytes_offset / $total_package_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving configuration file...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $progress ) );
// Set archive bytes offset
$params['archive_bytes_offset'] = $archive_bytes_offset;
// Set package bytes offset
$params['package_bytes_offset'] = $package_bytes_offset;
// Set total package size
$params['total_package_size'] = $total_package_size;
// Set completed flag
$params['completed'] = false;
}
// Truncate the archive file
$archive->truncate();
// Close the archive file
$archive->close();
return $params;
}
}

View File

@ -0,0 +1,184 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Config {
public static function execute( $params ) {
global $table_prefix, $wp_version;
// Set progress
Ai1wm_Status::info( __( 'Preparing configuration file...', AI1WM_PLUGIN_NAME ) );
// Get options
$options = wp_load_alloptions();
// Get database client
$mysql = Ai1wm_Database_Utility::create_client();
$config = array();
// Set site URL
$config['SiteURL'] = site_url();
// Set home URL
$config['HomeURL'] = home_url();
// Set internal site URL
if ( isset( $options['siteurl'] ) ) {
$config['InternalSiteURL'] = $options['siteurl'];
}
// Set internal home URL
if ( isset( $options['home'] ) ) {
$config['InternalHomeURL'] = $options['home'];
}
// Set replace old and new values
if ( isset( $params['options']['replace'] ) && ( $replace = $params['options']['replace'] ) ) {
for ( $i = 0; $i < count( $replace['old_value'] ); $i++ ) {
if ( ! empty( $replace['old_value'][ $i ] ) && ! empty( $replace['new_value'][ $i ] ) ) {
$config['Replace']['OldValues'][] = $replace['old_value'][ $i ];
$config['Replace']['NewValues'][] = $replace['new_value'][ $i ];
}
}
}
// Set no spam comments
if ( isset( $params['options']['no_spam_comments'] ) ) {
$config['NoSpamComments'] = true;
}
// Set no post revisions
if ( isset( $params['options']['no_post_revisions'] ) ) {
$config['NoPostRevisions'] = true;
}
// Set no media
if ( isset( $params['options']['no_media'] ) ) {
$config['NoMedia'] = true;
}
// Set no themes
if ( isset( $params['options']['no_themes'] ) ) {
$config['NoThemes'] = true;
}
// Set no inactive themes
if ( isset( $params['options']['no_inactive_themes'] ) ) {
$config['NoInactiveThemes'] = true;
}
// Set no must-use plugins
if ( isset( $params['options']['no_muplugins'] ) ) {
$config['NoMustUsePlugins'] = true;
}
// Set no plugins
if ( isset( $params['options']['no_plugins'] ) ) {
$config['NoPlugins'] = true;
}
// Set no inactive plugins
if ( isset( $params['options']['no_inactive_plugins'] ) ) {
$config['NoInactivePlugins'] = true;
}
// Set no cache
if ( isset( $params['options']['no_cache'] ) ) {
$config['NoCache'] = true;
}
// Set no database
if ( isset( $params['options']['no_database'] ) ) {
$config['NoDatabase'] = true;
}
// Set no email replace
if ( isset( $params['options']['no_email_replace'] ) ) {
$config['NoEmailReplace'] = true;
}
// Set plugin version
$config['Plugin'] = array( 'Version' => AI1WM_VERSION );
// Set WordPress version and content
$config['WordPress'] = array( 'Version' => $wp_version, 'Content' => WP_CONTENT_DIR, 'Plugins' => ai1wm_get_plugins_dir(), 'Themes' => ai1wm_get_themes_dirs(), 'Uploads' => ai1wm_get_uploads_dir(), 'UploadsURL' => ai1wm_get_uploads_url() );
// Set database version
$config['Database'] = array(
'Version' => $mysql->version(),
'Charset' => defined( 'DB_CHARSET' ) ? DB_CHARSET : 'undefined',
'Collate' => defined( 'DB_COLLATE' ) ? DB_COLLATE : 'undefined',
'Prefix' => $table_prefix,
);
// Exclude selected db tables
if ( isset( $params['options']['exclude_db_tables'], $params['excluded_db_tables'] ) ) {
if ( ( $excluded_db_tables = explode( ',', $params['excluded_db_tables'] ) ) ) {
$config['Database']['ExcludedTables'] = $excluded_db_tables;
}
}
// Set PHP version
$config['PHP'] = array( 'Version' => PHP_VERSION, 'System' => PHP_OS, 'Integer' => PHP_INT_SIZE );
// Set active plugins
$config['Plugins'] = array_values( array_diff( ai1wm_active_plugins(), ai1wm_active_servmask_plugins() ) );
// Set active template
$config['Template'] = ai1wm_active_template();
// Set active stylesheet
$config['Stylesheet'] = ai1wm_active_stylesheet();
// Set upload path
$config['Uploads'] = get_option( 'upload_path' );
// Set upload URL path
$config['UploadsURL'] = get_option( 'upload_url_path' );
// Set server info
$config['Server'] = array( '.htaccess' => base64_encode( ai1wm_get_htaccess() ), 'web.config' => base64_encode( ai1wm_get_webconfig() ) );
if ( isset( $params['options']['encrypt_backups'] ) ) {
$config['Encrypted'] = true;
$config['EncryptedSignature'] = base64_encode( ai1wm_encrypt_string( AI1WM_SIGN_TEXT, $params['options']['encrypt_password'] ) );
}
// Save package.json file
$handle = ai1wm_open( ai1wm_package_path( $params ), 'w' );
ai1wm_write( $handle, json_encode( $config ) );
ai1wm_close( $handle );
// Set progress
Ai1wm_Status::info( __( 'Done preparing configuration file.', AI1WM_PLUGIN_NAME ) );
return $params;
}
}

View File

@ -0,0 +1,193 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Content {
public static function execute( $params ) {
// Set archive bytes offset
if ( isset( $params['archive_bytes_offset'] ) ) {
$archive_bytes_offset = (int) $params['archive_bytes_offset'];
} else {
$archive_bytes_offset = ai1wm_archive_bytes( $params );
}
// Set file bytes offset
if ( isset( $params['file_bytes_offset'] ) ) {
$file_bytes_offset = (int) $params['file_bytes_offset'];
} else {
$file_bytes_offset = 0;
}
// Set content bytes offset
if ( isset( $params['content_bytes_offset'] ) ) {
$content_bytes_offset = (int) $params['content_bytes_offset'];
} else {
$content_bytes_offset = 0;
}
// Get processed files size
if ( isset( $params['processed_files_size'] ) ) {
$processed_files_size = (int) $params['processed_files_size'];
} else {
$processed_files_size = 0;
}
// Get total content files size
if ( isset( $params['total_content_files_size'] ) ) {
$total_content_files_size = (int) $params['total_content_files_size'];
} else {
$total_content_files_size = 1;
}
// Get total content files count
if ( isset( $params['total_content_files_count'] ) ) {
$total_content_files_count = (int) $params['total_content_files_count'];
} else {
$total_content_files_count = 1;
}
// What percent of files have we processed?
$progress = (int) min( ( $processed_files_size / $total_content_files_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving %d content files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_content_files_count, $progress ) );
// Flag to hold if file data has been processed
$completed = true;
// Start time
$start = microtime( true );
// Get content list file
$content_list = ai1wm_open( ai1wm_content_list_path( $params ), 'r' );
// Set the file pointer at the current index
if ( fseek( $content_list, $content_bytes_offset ) !== -1 ) {
// Open the archive file for writing
$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
// Set the file pointer to the one that we have saved
$archive->set_file_pointer( $archive_bytes_offset );
// Loop over files
while ( list( $file_abspath, $file_relpath, $file_size, $file_mtime ) = fgetcsv( $content_list ) ) {
$file_bytes_written = 0;
// Add file to archive
if ( ( $completed = $archive->add_file( $file_abspath, $file_relpath, $file_bytes_written, $file_bytes_offset ) ) ) {
$file_bytes_offset = 0;
// Get content bytes offset
$content_bytes_offset = ftell( $content_list );
}
// Increment processed files size
$processed_files_size += $file_bytes_written;
// What percent of files have we processed?
$progress = (int) min( ( $processed_files_size / $total_content_files_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving %d content files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_content_files_count, $progress ) );
// More than 10 seconds have passed, break and do another request
if ( ( $timeout = apply_filters( 'ai1wm_completed_timeout', 10 ) ) ) {
if ( ( microtime( true ) - $start ) > $timeout ) {
$completed = false;
break;
}
}
}
// Get archive bytes offset
$archive_bytes_offset = $archive->get_file_pointer();
// Truncate the archive file
$archive->truncate();
// Close the archive file
$archive->close();
}
// End of the content list?
if ( feof( $content_list ) ) {
// Unset archive bytes offset
unset( $params['archive_bytes_offset'] );
// Unset file bytes offset
unset( $params['file_bytes_offset'] );
// Unset content bytes offset
unset( $params['content_bytes_offset'] );
// Unset processed files size
unset( $params['processed_files_size'] );
// Unset total content files size
unset( $params['total_content_files_size'] );
// Unset total content files count
unset( $params['total_content_files_count'] );
// Unset completed flag
unset( $params['completed'] );
} else {
// Set archive bytes offset
$params['archive_bytes_offset'] = $archive_bytes_offset;
// Set file bytes offset
$params['file_bytes_offset'] = $file_bytes_offset;
// Set content bytes offset
$params['content_bytes_offset'] = $content_bytes_offset;
// Set processed files size
$params['processed_files_size'] = $processed_files_size;
// Set total content files size
$params['total_content_files_size'] = $total_content_files_size;
// Set total content files count
$params['total_content_files_count'] = $total_content_files_count;
// Set completed flag
$params['completed'] = $completed;
}
// Close the content list file
ai1wm_close( $content_list );
return $params;
}
}

View File

@ -0,0 +1,124 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Database_File {
public static function execute( $params ) {
// Set exclude database
if ( isset( $params['options']['no_database'] ) ) {
return $params;
}
$database_bytes_written = 0;
// Set archive bytes offset
if ( isset( $params['archive_bytes_offset'] ) ) {
$archive_bytes_offset = (int) $params['archive_bytes_offset'];
} else {
$archive_bytes_offset = ai1wm_archive_bytes( $params );
}
// Set database bytes offset
if ( isset( $params['database_bytes_offset'] ) ) {
$database_bytes_offset = (int) $params['database_bytes_offset'];
} else {
$database_bytes_offset = 0;
}
// Get total database size
if ( isset( $params['total_database_size'] ) ) {
$total_database_size = (int) $params['total_database_size'];
} else {
$total_database_size = ai1wm_database_bytes( $params );
}
// What percent of database have we processed?
$progress = (int) min( ( $database_bytes_offset / $total_database_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving database...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $progress ) );
// Open the archive file for writing
$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
// Set the file pointer to the one that we have saved
$archive->set_file_pointer( $archive_bytes_offset );
// Add database.sql to archive
if ( $archive->add_file( ai1wm_database_path( $params ), AI1WM_DATABASE_NAME, $database_bytes_written, $database_bytes_offset ) ) {
// Set progress
Ai1wm_Status::info( __( 'Done archiving database.', AI1WM_PLUGIN_NAME ) );
// Unset archive bytes offset
unset( $params['archive_bytes_offset'] );
// Unset database bytes offset
unset( $params['database_bytes_offset'] );
// Unset total database size
unset( $params['total_database_size'] );
// Unset completed flag
unset( $params['completed'] );
} else {
// Get archive bytes offset
$archive_bytes_offset = $archive->get_file_pointer();
// What percent of database have we processed?
$progress = (int) min( ( $database_bytes_offset / $total_database_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving database...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $progress ) );
// Set archive bytes offset
$params['archive_bytes_offset'] = $archive_bytes_offset;
// Set database bytes offset
$params['database_bytes_offset'] = $database_bytes_offset;
// Set total database size
$params['total_database_size'] = $total_database_size;
// Set completed flag
$params['completed'] = false;
}
// Truncate the archive file
$archive->truncate();
// Close the archive file
$archive->close();
return $params;
}
}

View File

@ -0,0 +1,208 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Database {
public static function execute( $params ) {
// Set exclude database
if ( isset( $params['options']['no_database'] ) ) {
return $params;
}
// Set query offset
if ( isset( $params['query_offset'] ) ) {
$query_offset = (int) $params['query_offset'];
} else {
$query_offset = 0;
}
// Set table index
if ( isset( $params['table_index'] ) ) {
$table_index = (int) $params['table_index'];
} else {
$table_index = 0;
}
// Set table offset
if ( isset( $params['table_offset'] ) ) {
$table_offset = (int) $params['table_offset'];
} else {
$table_offset = 0;
}
// Set table rows
if ( isset( $params['table_rows'] ) ) {
$table_rows = (int) $params['table_rows'];
} else {
$table_rows = 0;
}
// Set total tables count
if ( isset( $params['total_tables_count'] ) ) {
$total_tables_count = (int) $params['total_tables_count'];
} else {
$total_tables_count = 1;
}
// What percent of tables have we processed?
$progress = (int) ( ( $table_index / $total_tables_count ) * 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Exporting database...<br />%d%% complete<br />%s records saved', AI1WM_PLUGIN_NAME ), $progress, number_format_i18n( $table_rows ) ) );
// Get tables list file
$tables_list = ai1wm_open( ai1wm_tables_list_path( $params ), 'r' );
// Loop over tables
$tables = array();
while ( list( $table_name ) = fgetcsv( $tables_list ) ) {
$tables[] = $table_name;
}
// Close the tables list file
ai1wm_close( $tables_list );
// Get database client
$mysql = Ai1wm_Database_Utility::create_client();
// Exclude spam comments
if ( isset( $params['options']['no_spam_comments'] ) ) {
$mysql->set_table_where_query( ai1wm_table_prefix() . 'comments', "`comment_approved` != 'spam'" )
->set_table_where_query( ai1wm_table_prefix() . 'commentmeta', sprintf( "`comment_ID` IN ( SELECT `comment_ID` FROM `%s` WHERE `comment_approved` != 'spam' )", ai1wm_table_prefix() . 'comments' ) );
}
// Exclude post revisions
if ( isset( $params['options']['no_post_revisions'] ) ) {
$mysql->set_table_where_query( ai1wm_table_prefix() . 'posts', "`post_type` != 'revision'" );
}
$old_table_prefixes = $old_column_prefixes = array();
$new_table_prefixes = $new_column_prefixes = array();
// Set table prefixes
if ( ai1wm_table_prefix() ) {
$old_table_prefixes[] = ai1wm_table_prefix();
$new_table_prefixes[] = ai1wm_servmask_prefix();
} else {
foreach ( $tables as $table_name ) {
$old_table_prefixes[] = $table_name;
$new_table_prefixes[] = ai1wm_servmask_prefix() . $table_name;
}
}
// Set column prefixes
if ( strlen( ai1wm_table_prefix() ) > 1 ) {
$old_column_prefixes[] = ai1wm_table_prefix();
$new_column_prefixes[] = ai1wm_servmask_prefix();
} else {
foreach ( array( 'user_roles', 'capabilities', 'user_level', 'dashboard_quick_press_last_post_id', 'user-settings', 'user-settings-time' ) as $column_prefix ) {
$old_column_prefixes[] = ai1wm_table_prefix() . $column_prefix;
$new_column_prefixes[] = ai1wm_servmask_prefix() . $column_prefix;
}
}
$mysql->set_tables( $tables )
->set_old_table_prefixes( $old_table_prefixes )
->set_new_table_prefixes( $new_table_prefixes )
->set_old_column_prefixes( $old_column_prefixes )
->set_new_column_prefixes( $new_column_prefixes );
// Exclude column prefixes
$mysql->set_reserved_column_prefixes( array( 'wp_force_deactivated_plugins', 'wp_page_for_privacy_policy' ) );
// Exclude site options
$mysql->set_table_where_query( ai1wm_table_prefix() . 'options', sprintf( "`option_name` NOT IN ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", AI1WM_STATUS, AI1WM_SECRET_KEY, AI1WM_AUTH_USER, AI1WM_AUTH_PASSWORD, AI1WM_AUTH_HEADER, AI1WM_BACKUPS_LABELS, AI1WM_SITES_LINKS ) );
// Set table select columns
if ( ( $column_names = $mysql->get_column_names( ai1wm_table_prefix() . 'options' ) ) ) {
if ( isset( $column_names['option_name'], $column_names['option_value'] ) ) {
$column_names['option_value'] = sprintf( "(CASE WHEN option_name = '%s' THEN 'a:0:{}' WHEN (option_name = '%s' OR option_name = '%s') THEN '' ELSE option_value END) AS option_value", AI1WM_ACTIVE_PLUGINS, AI1WM_ACTIVE_TEMPLATE, AI1WM_ACTIVE_STYLESHEET );
}
$mysql->set_table_select_columns( ai1wm_table_prefix() . 'options', $column_names );
}
// Set table prefix columns
$mysql->set_table_prefix_columns( ai1wm_table_prefix() . 'options', array( 'option_name' ) )
->set_table_prefix_columns( ai1wm_table_prefix() . 'usermeta', array( 'meta_key' ) );
// Export database
if ( $mysql->export( ai1wm_database_path( $params ), $query_offset, $table_index, $table_offset, $table_rows ) ) {
// Set progress
Ai1wm_Status::info( __( 'Done exporting database.', AI1WM_PLUGIN_NAME ) );
// Unset query offset
unset( $params['query_offset'] );
// Unset table index
unset( $params['table_index'] );
// Unset table offset
unset( $params['table_offset'] );
// Unset table rows
unset( $params['table_rows'] );
// Unset total tables count
unset( $params['total_tables_count'] );
// Unset completed flag
unset( $params['completed'] );
} else {
// What percent of tables have we processed?
$progress = (int) ( ( $table_index / $total_tables_count ) * 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Exporting database...<br />%d%% complete<br />%s records saved', AI1WM_PLUGIN_NAME ), $progress, number_format_i18n( $table_rows ) ) );
// Set query offset
$params['query_offset'] = $query_offset;
// Set table index
$params['table_index'] = $table_index;
// Set table offset
$params['table_offset'] = $table_offset;
// Set table rows
$params['table_rows'] = $table_rows;
// Set total tables count
$params['total_tables_count'] = $total_tables_count;
// Set completed flag
$params['completed'] = false;
}
return $params;
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Download {
public static function execute( $params ) {
// Set progress
Ai1wm_Status::info( __( 'Renaming exported file...', AI1WM_PLUGIN_NAME ) );
// Open the archive file for writing
$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
// Append EOF block
$archive->close( true );
// Rename archive file
if ( rename( ai1wm_archive_path( $params ), ai1wm_backup_path( $params ) ) ) {
$blog_id = null;
// Get subsite Blog ID
if ( isset( $params['options']['sites'] ) && ( $sites = $params['options']['sites'] ) ) {
if ( count( $sites ) === 1 ) {
$blog_id = array_shift( $sites );
}
}
// Set archive details
$file = ai1wm_archive_name( $params );
$link = ai1wm_backup_url( $params );
$size = ai1wm_backup_size( $params );
$name = ai1wm_site_name( $blog_id );
// Set progress
Ai1wm_Status::download(
sprintf(
__(
'<a href="%s" class="ai1wm-button-green ai1wm-emphasize ai1wm-button-download" title="%s" download="%s">' .
'<span>Download %s</span>' .
'<em>Size: %s</em>' .
'</a>',
AI1WM_PLUGIN_NAME
),
$link,
$name,
$file,
$name,
$size
)
);
}
do_action( 'ai1wm_status_export_done', $params );
return $params;
}
}

View File

@ -0,0 +1,119 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Enumerate_Content {
public static function execute( $params ) {
$exclude_filters = array_merge( array( ai1wm_get_uploads_dir(), ai1wm_get_plugins_dir() ), ai1wm_get_themes_dirs() );
// Get total content files count
if ( isset( $params['total_content_files_count'] ) ) {
$total_content_files_count = (int) $params['total_content_files_count'];
} else {
$total_content_files_count = 1;
}
// Get total content files size
if ( isset( $params['total_content_files_size'] ) ) {
$total_content_files_size = (int) $params['total_content_files_size'];
} else {
$total_content_files_size = 1;
}
// Set progress
Ai1wm_Status::info( __( 'Retrieving a list of WordPress content files...', AI1WM_PLUGIN_NAME ) );
// Exclude cache
if ( isset( $params['options']['no_cache'] ) ) {
$exclude_filters[] = 'cache';
}
// Exclude must-use plugins
if ( isset( $params['options']['no_muplugins'] ) ) {
$exclude_filters[] = 'mu-plugins';
}
// Exclude media
if ( isset( $params['options']['no_media'] ) ) {
$exclude_filters[] = 'blogs.dir';
}
// Exclude selected files
if ( isset( $params['options']['exclude_files'], $params['excluded_files'] ) ) {
if ( ( $excluded_files = explode( ',', $params['excluded_files'] ) ) ) {
foreach ( $excluded_files as $excluded_path ) {
$exclude_filters[] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . untrailingslashit( $excluded_path );
}
}
}
// Create content list file
$content_list = ai1wm_open( ai1wm_content_list_path( $params ), 'w' );
// Enumerate over content directory
if ( isset( $params['options']['no_themes'], $params['options']['no_muplugins'], $params['options']['no_plugins'] ) === false ) {
// Iterate over content directory
$iterator = new Ai1wm_Recursive_Directory_Iterator( WP_CONTENT_DIR );
// Exclude content files
$iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, apply_filters( 'ai1wm_exclude_content_from_export', ai1wm_content_filters( $exclude_filters ) ) );
// Recursively iterate over content directory
$iterator = new Ai1wm_Recursive_Iterator_Iterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD );
// Write path line
foreach ( $iterator as $item ) {
if ( $item->isFile() ) {
if ( ai1wm_putcsv( $content_list, array( $iterator->getPathname(), $iterator->getSubPathname(), $iterator->getSize(), $iterator->getMTime() ) ) ) {
$total_content_files_count++;
// Add current file size
$total_content_files_size += $iterator->getSize();
}
}
}
}
// Set progress
Ai1wm_Status::info( __( 'Done retrieving a list of WordPress content files.', AI1WM_PLUGIN_NAME ) );
// Set total content files count
$params['total_content_files_count'] = $total_content_files_count;
// Set total content files size
$params['total_content_files_size'] = $total_content_files_size;
// Close the content list file
ai1wm_close( $content_list );
return $params;
}
}

View File

@ -0,0 +1,106 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Enumerate_Media {
public static function execute( $params ) {
$exclude_filters = array();
// Get total media files count
if ( isset( $params['total_media_files_count'] ) ) {
$total_media_files_count = (int) $params['total_media_files_count'];
} else {
$total_media_files_count = 1;
}
// Get total media files size
if ( isset( $params['total_media_files_size'] ) ) {
$total_media_files_size = (int) $params['total_media_files_size'];
} else {
$total_media_files_size = 1;
}
// Set progress
Ai1wm_Status::info( __( 'Retrieving a list of WordPress media files...', AI1WM_PLUGIN_NAME ) );
// Exclude selected files
if ( isset( $params['options']['exclude_files'], $params['excluded_files'] ) ) {
if ( ( $excluded_files = explode( ',', $params['excluded_files'] ) ) ) {
foreach ( $excluded_files as $excluded_path ) {
$exclude_filters[] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . untrailingslashit( $excluded_path );
}
}
}
// Create media list file
$media_list = ai1wm_open( ai1wm_media_list_path( $params ), 'w' );
// Enumerate over media directory
if ( isset( $params['options']['no_media'] ) === false ) {
if ( is_dir( ai1wm_get_uploads_dir() ) ) {
// Iterate over media directory
$iterator = new Ai1wm_Recursive_Directory_Iterator( ai1wm_get_uploads_dir() );
// Exclude media files
$iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, apply_filters( 'ai1wm_exclude_media_from_export', ai1wm_media_filters( $exclude_filters ) ) );
// Recursively iterate over content directory
$iterator = new Ai1wm_Recursive_Iterator_Iterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD );
// Write path line
foreach ( $iterator as $item ) {
if ( $item->isFile() ) {
if ( ai1wm_putcsv( $media_list, array( $iterator->getPathname(), $iterator->getSubPathname(), $iterator->getSize(), $iterator->getMTime() ) ) ) {
$total_media_files_count++;
// Add current file size
$total_media_files_size += $iterator->getSize();
}
}
}
}
}
// Set progress
Ai1wm_Status::info( __( 'Done retrieving a list of WordPress media files.', AI1WM_PLUGIN_NAME ) );
// Set total media files count
$params['total_media_files_count'] = $total_media_files_count;
// Set total media files size
$params['total_media_files_size'] = $total_media_files_size;
// Close the media list file
ai1wm_close( $media_list );
return $params;
}
}

View File

@ -0,0 +1,113 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Enumerate_Plugins {
public static function execute( $params ) {
$exclude_filters = array();
// Get total plugins files count
if ( isset( $params['total_plugins_files_count'] ) ) {
$total_plugins_files_count = (int) $params['total_plugins_files_count'];
} else {
$total_plugins_files_count = 1;
}
// Get total plugins files size
if ( isset( $params['total_plugins_files_size'] ) ) {
$total_plugins_files_size = (int) $params['total_plugins_files_size'];
} else {
$total_plugins_files_size = 1;
}
// Set progress
Ai1wm_Status::info( __( 'Retrieving a list of WordPress plugin files...', AI1WM_PLUGIN_NAME ) );
// Exclude inactive plugins
if ( isset( $params['options']['no_inactive_plugins'] ) ) {
foreach ( get_plugins() as $plugin_name => $plugin_info ) {
if ( is_plugin_inactive( $plugin_name ) ) {
$exclude_filters[] = ( dirname( $plugin_name ) === '.' ? basename( $plugin_name ) : dirname( $plugin_name ) );
}
}
}
// Exclude selected files
if ( isset( $params['options']['exclude_files'], $params['excluded_files'] ) ) {
if ( ( $excluded_files = explode( ',', $params['excluded_files'] ) ) ) {
foreach ( $excluded_files as $excluded_path ) {
$exclude_filters[] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . untrailingslashit( $excluded_path );
}
}
}
// Create plugins list file
$plugins_list = ai1wm_open( ai1wm_plugins_list_path( $params ), 'w' );
// Enumerate over plugins directory
if ( isset( $params['options']['no_plugins'] ) === false ) {
// Iterate over plugins directory
$iterator = new Ai1wm_Recursive_Directory_Iterator( ai1wm_get_plugins_dir() );
// Exclude plugins files
$iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, apply_filters( 'ai1wm_exclude_plugins_from_export', ai1wm_plugin_filters( $exclude_filters ) ) );
// Recursively iterate over plugins directory
$iterator = new Ai1wm_Recursive_Iterator_Iterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD );
// Write path line
foreach ( $iterator as $item ) {
if ( $item->isFile() ) {
if ( ai1wm_putcsv( $plugins_list, array( $iterator->getPathname(), $iterator->getSubPathname(), $iterator->getSize(), $iterator->getMTime() ) ) ) {
$total_plugins_files_count++;
// Add current file size
$total_plugins_files_size += $iterator->getSize();
}
}
}
}
// Set progress
Ai1wm_Status::info( __( 'Done retrieving a list of WordPress plugin files.', AI1WM_PLUGIN_NAME ) );
// Set total plugins files count
$params['total_plugins_files_count'] = $total_plugins_files_count;
// Set total plugins files size
$params['total_plugins_files_size'] = $total_plugins_files_size;
// Close the plugins list file
ai1wm_close( $plugins_list );
return $params;
}
}

View File

@ -0,0 +1,90 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Enumerate_Tables {
public static function execute( $params, Ai1wm_Database $mysql = null ) {
// Set exclude database
if ( isset( $params['options']['no_database'] ) ) {
return $params;
}
// Get total tables count
if ( isset( $params['total_tables_count'] ) ) {
$total_tables_count = (int) $params['total_tables_count'];
} else {
$total_tables_count = 1;
}
// Set progress
Ai1wm_Status::info( __( 'Retrieving a list of WordPress database tables...', AI1WM_PLUGIN_NAME ) );
// Get database client
if ( is_null( $mysql ) ) {
$mysql = Ai1wm_Database_Utility::create_client();
}
// Include table prefixes
if ( ai1wm_table_prefix() ) {
$mysql->add_table_prefix_filter( ai1wm_table_prefix() );
// Include table prefixes (Webba Booking)
foreach ( array( 'wbk_services', 'wbk_days_on_off', 'wbk_locked_time_slots', 'wbk_appointments', 'wbk_cancelled_appointments', 'wbk_email_templates', 'wbk_service_categories', 'wbk_gg_calendars', 'wbk_coupons' ) as $table_name ) {
$mysql->add_table_prefix_filter( $table_name );
}
}
// Create tables list file
$tables_list = ai1wm_open( ai1wm_tables_list_path( $params ), 'w' );
// Exclude selected db tables
$excluded_db_tables = array();
if ( isset( $params['options']['exclude_db_tables'], $params['excluded_db_tables'] ) ) {
$excluded_db_tables = explode( ',', $params['excluded_db_tables'] );
}
// Write table line
foreach ( $mysql->get_tables() as $table_name ) {
if ( ! in_array( $table_name, $excluded_db_tables ) && ai1wm_putcsv( $tables_list, array( $table_name ) ) ) {
$total_tables_count++;
}
}
// Set progress
Ai1wm_Status::info( __( 'Done retrieving a list of WordPress database tables.', AI1WM_PLUGIN_NAME ) );
// Set total tables count
$params['total_tables_count'] = $total_tables_count;
// Close the tables list file
ai1wm_close( $tables_list );
return $params;
}
}

View File

@ -0,0 +1,119 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Enumerate_Themes {
public static function execute( $params ) {
$exclude_filters = array();
// Get total themes files count
if ( isset( $params['total_themes_files_count'] ) ) {
$total_themes_files_count = (int) $params['total_themes_files_count'];
} else {
$total_themes_files_count = 1;
}
// Get total themes files size
if ( isset( $params['total_themes_files_size'] ) ) {
$total_themes_files_size = (int) $params['total_themes_files_size'];
} else {
$total_themes_files_size = 1;
}
// Set progress
Ai1wm_Status::info( __( 'Retrieving a list of WordPress theme files...', AI1WM_PLUGIN_NAME ) );
// Exclude inactive themes
if ( isset( $params['options']['no_inactive_themes'] ) ) {
foreach ( search_theme_directories() as $theme_name => $theme_info ) {
if ( ! in_array( $theme_name, array( get_template(), get_stylesheet() ) ) ) {
if ( isset( $theme_info['theme_root'] ) ) {
$exclude_filters[] = $theme_info['theme_root'] . DIRECTORY_SEPARATOR . $theme_name;
}
}
}
}
// Exclude selected files
if ( isset( $params['options']['exclude_files'], $params['excluded_files'] ) ) {
if ( ( $excluded_files = explode( ',', $params['excluded_files'] ) ) ) {
foreach ( $excluded_files as $excluded_path ) {
$exclude_filters[] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . untrailingslashit( $excluded_path );
}
}
}
// Create themes list file
$themes_list = ai1wm_open( ai1wm_themes_list_path( $params ), 'w' );
// Enumerate over themes directory
if ( isset( $params['options']['no_themes'] ) === false ) {
foreach ( ai1wm_get_themes_dirs() as $theme_dir ) {
if ( is_dir( $theme_dir ) ) {
// Iterate over themes directory
$iterator = new Ai1wm_Recursive_Directory_Iterator( $theme_dir );
// Exclude themes files
$iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, apply_filters( 'ai1wm_exclude_themes_from_export', ai1wm_theme_filters( $exclude_filters ) ) );
// Recursively iterate over themes directory
$iterator = new Ai1wm_Recursive_Iterator_Iterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD );
// Write path line
foreach ( $iterator as $item ) {
if ( $item->isFile() ) {
if ( ai1wm_putcsv( $themes_list, array( $iterator->getPathname(), $iterator->getSubPathname(), $iterator->getSize(), $iterator->getMTime() ) ) ) {
$total_themes_files_count++;
// Add current file size
$total_themes_files_size += $iterator->getSize();
}
}
}
}
}
}
// Set progress
Ai1wm_Status::info( __( 'Done retrieving a list of WordPress theme files.', AI1WM_PLUGIN_NAME ) );
// Set total themes files count
$params['total_themes_files_count'] = $total_themes_files_count;
// Set total themes files size
$params['total_themes_files_size'] = $total_themes_files_size;
// Close the themes list file
ai1wm_close( $themes_list );
return $params;
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Init {
public static function execute( $params ) {
$blog_id = null;
// Get subsite Blog ID
if ( isset( $params['options']['sites'] ) && ( $sites = $params['options']['sites'] ) ) {
if ( count( $sites ) === 1 ) {
$blog_id = array_shift( $sites );
}
}
// Set progress
Ai1wm_Status::info( __( 'Preparing to export...', AI1WM_PLUGIN_NAME ) );
// Set archive
if ( empty( $params['archive'] ) ) {
$params['archive'] = ai1wm_archive_file( $blog_id );
}
// Set storage
if ( empty( $params['storage'] ) ) {
$params['storage'] = ai1wm_storage_folder();
}
return $params;
}
}

View File

@ -0,0 +1,193 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Media {
public static function execute( $params ) {
// Set archive bytes offset
if ( isset( $params['archive_bytes_offset'] ) ) {
$archive_bytes_offset = (int) $params['archive_bytes_offset'];
} else {
$archive_bytes_offset = ai1wm_archive_bytes( $params );
}
// Set file bytes offset
if ( isset( $params['file_bytes_offset'] ) ) {
$file_bytes_offset = (int) $params['file_bytes_offset'];
} else {
$file_bytes_offset = 0;
}
// Set media bytes offset
if ( isset( $params['media_bytes_offset'] ) ) {
$media_bytes_offset = (int) $params['media_bytes_offset'];
} else {
$media_bytes_offset = 0;
}
// Get processed files size
if ( isset( $params['processed_files_size'] ) ) {
$processed_files_size = (int) $params['processed_files_size'];
} else {
$processed_files_size = 0;
}
// Get total media files size
if ( isset( $params['total_media_files_size'] ) ) {
$total_media_files_size = (int) $params['total_media_files_size'];
} else {
$total_media_files_size = 1;
}
// Get total media files count
if ( isset( $params['total_media_files_count'] ) ) {
$total_media_files_count = (int) $params['total_media_files_count'];
} else {
$total_media_files_count = 1;
}
// What percent of files have we processed?
$progress = (int) min( ( $processed_files_size / $total_media_files_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving %d media files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_media_files_count, $progress ) );
// Flag to hold if file data has been processed
$completed = true;
// Start time
$start = microtime( true );
// Get media list file
$media_list = ai1wm_open( ai1wm_media_list_path( $params ), 'r' );
// Set the file pointer at the current index
if ( fseek( $media_list, $media_bytes_offset ) !== -1 ) {
// Open the archive file for writing
$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
// Set the file pointer to the one that we have saved
$archive->set_file_pointer( $archive_bytes_offset );
// Loop over files
while ( list( $file_abspath, $file_relpath, $file_size, $file_mtime ) = fgetcsv( $media_list ) ) {
$file_bytes_written = 0;
// Add file to archive
if ( ( $completed = $archive->add_file( $file_abspath, 'uploads' . DIRECTORY_SEPARATOR . $file_relpath, $file_bytes_written, $file_bytes_offset ) ) ) {
$file_bytes_offset = 0;
// Get media bytes offset
$media_bytes_offset = ftell( $media_list );
}
// Increment processed files size
$processed_files_size += $file_bytes_written;
// What percent of files have we processed?
$progress = (int) min( ( $processed_files_size / $total_media_files_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving %d media files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_media_files_count, $progress ) );
// More than 10 seconds have passed, break and do another request
if ( ( $timeout = apply_filters( 'ai1wm_completed_timeout', 10 ) ) ) {
if ( ( microtime( true ) - $start ) > $timeout ) {
$completed = false;
break;
}
}
}
// Get archive bytes offset
$archive_bytes_offset = $archive->get_file_pointer();
// Truncate the archive file
$archive->truncate();
// Close the archive file
$archive->close();
}
// End of the media list?
if ( feof( $media_list ) ) {
// Unset archive bytes offset
unset( $params['archive_bytes_offset'] );
// Unset file bytes offset
unset( $params['file_bytes_offset'] );
// Unset media bytes offset
unset( $params['media_bytes_offset'] );
// Unset processed files size
unset( $params['processed_files_size'] );
// Unset total media files size
unset( $params['total_media_files_size'] );
// Unset total media files count
unset( $params['total_media_files_count'] );
// Unset completed flag
unset( $params['completed'] );
} else {
// Set archive bytes offset
$params['archive_bytes_offset'] = $archive_bytes_offset;
// Set file bytes offset
$params['file_bytes_offset'] = $file_bytes_offset;
// Set media bytes offset
$params['media_bytes_offset'] = $media_bytes_offset;
// Set processed files size
$params['processed_files_size'] = $processed_files_size;
// Set total media files size
$params['total_media_files_size'] = $total_media_files_size;
// Set total media files count
$params['total_media_files_count'] = $total_media_files_count;
// Set completed flag
$params['completed'] = $completed;
}
// Close the media list file
ai1wm_close( $media_list );
return $params;
}
}

View File

@ -0,0 +1,193 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Plugins {
public static function execute( $params ) {
// Set archive bytes offset
if ( isset( $params['archive_bytes_offset'] ) ) {
$archive_bytes_offset = (int) $params['archive_bytes_offset'];
} else {
$archive_bytes_offset = ai1wm_archive_bytes( $params );
}
// Set file bytes offset
if ( isset( $params['file_bytes_offset'] ) ) {
$file_bytes_offset = (int) $params['file_bytes_offset'];
} else {
$file_bytes_offset = 0;
}
// Set plugins bytes offset
if ( isset( $params['plugins_bytes_offset'] ) ) {
$plugins_bytes_offset = (int) $params['plugins_bytes_offset'];
} else {
$plugins_bytes_offset = 0;
}
// Get processed files size
if ( isset( $params['processed_files_size'] ) ) {
$processed_files_size = (int) $params['processed_files_size'];
} else {
$processed_files_size = 0;
}
// Get total plugins files size
if ( isset( $params['total_plugins_files_size'] ) ) {
$total_plugins_files_size = (int) $params['total_plugins_files_size'];
} else {
$total_plugins_files_size = 1;
}
// Get total plugins files count
if ( isset( $params['total_plugins_files_count'] ) ) {
$total_plugins_files_count = (int) $params['total_plugins_files_count'];
} else {
$total_plugins_files_count = 1;
}
// What percent of files have we processed?
$progress = (int) min( ( $processed_files_size / $total_plugins_files_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving %d plugin files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_plugins_files_count, $progress ) );
// Flag to hold if file data has been processed
$completed = true;
// Start time
$start = microtime( true );
// Get plugins list file
$plugins_list = ai1wm_open( ai1wm_plugins_list_path( $params ), 'r' );
// Set the file pointer at the current index
if ( fseek( $plugins_list, $plugins_bytes_offset ) !== -1 ) {
// Open the archive file for writing
$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
// Set the file pointer to the one that we have saved
$archive->set_file_pointer( $archive_bytes_offset );
// Loop over files
while ( list( $file_abspath, $file_relpath, $file_size, $file_mtime ) = fgetcsv( $plugins_list ) ) {
$file_bytes_written = 0;
// Add file to archive
if ( ( $completed = $archive->add_file( $file_abspath, 'plugins' . DIRECTORY_SEPARATOR . $file_relpath, $file_bytes_written, $file_bytes_offset ) ) ) {
$file_bytes_offset = 0;
// Get plugins bytes offset
$plugins_bytes_offset = ftell( $plugins_list );
}
// Increment processed files size
$processed_files_size += $file_bytes_written;
// What percent of files have we processed?
$progress = (int) min( ( $processed_files_size / $total_plugins_files_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving %d plugin files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_plugins_files_count, $progress ) );
// More than 10 seconds have passed, break and do another request
if ( ( $timeout = apply_filters( 'ai1wm_completed_timeout', 10 ) ) ) {
if ( ( microtime( true ) - $start ) > $timeout ) {
$completed = false;
break;
}
}
}
// Get archive bytes offset
$archive_bytes_offset = $archive->get_file_pointer();
// Truncate the archive file
$archive->truncate();
// Close the archive file
$archive->close();
}
// End of the plugins list?
if ( feof( $plugins_list ) ) {
// Unset archive bytes offset
unset( $params['archive_bytes_offset'] );
// Unset file bytes offset
unset( $params['file_bytes_offset'] );
// Unset plugins bytes offset
unset( $params['plugins_bytes_offset'] );
// Unset processed files size
unset( $params['processed_files_size'] );
// Unset total plugins files size
unset( $params['total_plugins_files_size'] );
// Unset total plugins files count
unset( $params['total_plugins_files_count'] );
// Unset completed flag
unset( $params['completed'] );
} else {
// Set archive bytes offset
$params['archive_bytes_offset'] = $archive_bytes_offset;
// Set file bytes offset
$params['file_bytes_offset'] = $file_bytes_offset;
// Set plugins bytes offset
$params['plugins_bytes_offset'] = $plugins_bytes_offset;
// Set processed files size
$params['processed_files_size'] = $processed_files_size;
// Set total plugins files size
$params['total_plugins_files_size'] = $total_plugins_files_size;
// Set total plugins files count
$params['total_plugins_files_count'] = $total_plugins_files_count;
// Set completed flag
$params['completed'] = $completed;
}
// Close the plugins list file
ai1wm_close( $plugins_list );
return $params;
}
}

View File

@ -0,0 +1,193 @@
<?php
/**
* Copyright (C) 2014-2023 ServMask Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Kangaroos cannot jump here' );
}
class Ai1wm_Export_Themes {
public static function execute( $params ) {
// Set archive bytes offset
if ( isset( $params['archive_bytes_offset'] ) ) {
$archive_bytes_offset = (int) $params['archive_bytes_offset'];
} else {
$archive_bytes_offset = ai1wm_archive_bytes( $params );
}
// Set file bytes offset
if ( isset( $params['file_bytes_offset'] ) ) {
$file_bytes_offset = (int) $params['file_bytes_offset'];
} else {
$file_bytes_offset = 0;
}
// Set themes bytes offset
if ( isset( $params['themes_bytes_offset'] ) ) {
$themes_bytes_offset = (int) $params['themes_bytes_offset'];
} else {
$themes_bytes_offset = 0;
}
// Get processed files size
if ( isset( $params['processed_files_size'] ) ) {
$processed_files_size = (int) $params['processed_files_size'];
} else {
$processed_files_size = 0;
}
// Get total themes files size
if ( isset( $params['total_themes_files_size'] ) ) {
$total_themes_files_size = (int) $params['total_themes_files_size'];
} else {
$total_themes_files_size = 1;
}
// Get total themes files count
if ( isset( $params['total_themes_files_count'] ) ) {
$total_themes_files_count = (int) $params['total_themes_files_count'];
} else {
$total_themes_files_count = 1;
}
// What percent of files have we processed?
$progress = (int) min( ( $processed_files_size / $total_themes_files_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving %d theme files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_themes_files_count, $progress ) );
// Flag to hold if file data has been processed
$completed = true;
// Start time
$start = microtime( true );
// Get themes list file
$themes_list = ai1wm_open( ai1wm_themes_list_path( $params ), 'r' );
// Set the file pointer at the current index
if ( fseek( $themes_list, $themes_bytes_offset ) !== -1 ) {
// Open the archive file for writing
$archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
// Set the file pointer to the one that we have saved
$archive->set_file_pointer( $archive_bytes_offset );
// Loop over files
while ( list( $file_abspath, $file_relpath, $file_size, $file_mtime ) = fgetcsv( $themes_list ) ) {
$file_bytes_written = 0;
// Add file to archive
if ( ( $completed = $archive->add_file( $file_abspath, 'themes' . DIRECTORY_SEPARATOR . $file_relpath, $file_bytes_written, $file_bytes_offset ) ) ) {
$file_bytes_offset = 0;
// Get themes bytes offset
$themes_bytes_offset = ftell( $themes_list );
}
// Increment processed files size
$processed_files_size += $file_bytes_written;
// What percent of files have we processed?
$progress = (int) min( ( $processed_files_size / $total_themes_files_size ) * 100, 100 );
// Set progress
Ai1wm_Status::info( sprintf( __( 'Archiving %d theme files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_themes_files_count, $progress ) );
// More than 10 seconds have passed, break and do another request
if ( ( $timeout = apply_filters( 'ai1wm_completed_timeout', 10 ) ) ) {
if ( ( microtime( true ) - $start ) > $timeout ) {
$completed = false;
break;
}
}
}
// Get archive bytes offset
$archive_bytes_offset = $archive->get_file_pointer();
// Truncate the archive file
$archive->truncate();
// Close the archive file
$archive->close();
}
// End of the themes list?
if ( feof( $themes_list ) ) {
// Unset archive bytes offset
unset( $params['archive_bytes_offset'] );
// Unset file bytes offset
unset( $params['file_bytes_offset'] );
// Unset themes bytes offset
unset( $params['themes_bytes_offset'] );
// Unset processed files size
unset( $params['processed_files_size'] );
// Unset total themes files size
unset( $params['total_themes_files_size'] );
// Unset total themes files count
unset( $params['total_themes_files_count'] );
// Unset completed flag
unset( $params['completed'] );
} else {
// Set archive bytes offset
$params['archive_bytes_offset'] = $archive_bytes_offset;
// Set file bytes offset
$params['file_bytes_offset'] = $file_bytes_offset;
// Set themes bytes offset
$params['themes_bytes_offset'] = $themes_bytes_offset;
// Set processed files size
$params['processed_files_size'] = $processed_files_size;
// Set total themes files size
$params['total_themes_files_size'] = $total_themes_files_size;
// Set total themes files count
$params['total_themes_files_count'] = $total_themes_files_count;
// Set completed flag
$params['completed'] = $completed;
}
// Close the themes list file
ai1wm_close( $themes_list );
return $params;
}
}