.
*
* ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
* ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
* ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
* ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
* ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
* ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
*/
class Ai1wm_Import_Blogs {
public static function execute( $params ) {
// Set progress
Ai1wm_Status::info( __( 'Preparing blogs...', AI1WM_PLUGIN_NAME ) );
$blogs = array();
// Check multisite.json file
if ( true === is_file( ai1wm_multisite_path( $params ) ) ) {
// Read multisite.json file
$handle = ai1wm_open( ai1wm_multisite_path( $params ), 'r' );
// Parse multisite.json file
$multisite = ai1wm_read( $handle, filesize( ai1wm_multisite_path( $params ) ) );
$multisite = json_decode( $multisite, true );
// Close handle
ai1wm_close( $handle );
// Validate
if ( empty( $multisite['Network'] ) ) {
if ( isset( $multisite['Sites'] ) && ( $sites = $multisite['Sites'] ) ) {
if ( count( $sites ) === 1 && ( $subsite = current( $sites ) ) ) {
// Set internal Site URL (backward compatibility)
if ( empty( $subsite['InternalSiteURL'] ) ) {
$subsite['InternalSiteURL'] = null;
}
// Set internal Home URL (backward compatibility)
if ( empty( $subsite['InternalHomeURL'] ) ) {
$subsite['InternalHomeURL'] = null;
}
// Set active plugins (backward compatibility)
if ( empty( $subsite['Plugins'] ) ) {
$subsite['Plugins'] = array();
}
// Set active template (backward compatibility)
if ( empty( $subsite['Template'] ) ) {
$subsite['Template'] = null;
}
// Set active stylesheet (backward compatibility)
if ( empty( $subsite['Stylesheet'] ) ) {
$subsite['Stylesheet'] = null;
}
// Set blog items
$blogs[] = array(
'Old' => array(
'BlogID' => $subsite['BlogID'],
'SiteURL' => $subsite['SiteURL'],
'HomeURL' => $subsite['HomeURL'],
'InternalSiteURL' => $subsite['InternalSiteURL'],
'InternalHomeURL' => $subsite['InternalHomeURL'],
'Plugins' => $subsite['Plugins'],
'Template' => $subsite['Template'],
'Stylesheet' => $subsite['Stylesheet'],
),
'New' => array(
'BlogID' => null,
'SiteURL' => site_url(),
'HomeURL' => home_url(),
'InternalSiteURL' => site_url(),
'InternalHomeURL' => home_url(),
'Plugins' => $subsite['Plugins'],
'Template' => $subsite['Template'],
'Stylesheet' => $subsite['Stylesheet'],
),
);
} else {
throw new Ai1wm_Import_Exception(
__( 'The archive should contain Single WordPress site! Please revisit your export settings.', AI1WM_PLUGIN_NAME )
);
}
} else {
throw new Ai1wm_Import_Exception(
__( 'At least one WordPress site should be presented in the archive.', AI1WM_PLUGIN_NAME )
);
}
} else {
throw new Ai1wm_Import_Exception(
__( 'Unable to import WordPress Network into WordPress Single site.', AI1WM_PLUGIN_NAME )
);
}
}
// Write blogs.json file
$handle = ai1wm_open( ai1wm_blogs_path( $params ), 'w' );
ai1wm_write( $handle, json_encode( $blogs ) );
ai1wm_close( $handle );
// Set progress
Ai1wm_Status::info( __( 'Done preparing blogs.', AI1WM_PLUGIN_NAME ) );
return $params;
}
}