2015-10-15 22:52:37 +10:00
< ? php
2020-05-05 20:13:38 +07:00
namespace MainWP\Child ;
2015-10-15 22:52:37 +10:00
class MainWP_Clone {
2016-12-08 20:54:26 +01:00
protected static $instance = null ;
protected $security_nonces ;
2020-05-05 20:13:38 +07:00
/**
* Method get_class_name ()
*
* Get Class Name .
*
* @ return object
*/
public static function get_class_name () {
return __CLASS__ ;
}
2020-05-05 13:19:34 +00:00
2016-12-08 20:54:26 +01:00
public static function get () {
if ( null === self :: $instance ) {
2020-05-07 01:03:56 +07:00
self :: $instance = new self ();
2016-12-08 20:54:26 +01:00
}
return self :: $instance ;
}
2020-05-15 16:54:45 +00:00
2020-05-15 23:53:53 +07:00
public function init_ajax () {
$this -> add_action ( 'mainwp-child_clone_backupcreate' , array ( & $this , 'clone_backup_create' ) );
$this -> add_action ( 'mainwp-child_clone_backupcreatepoll' , array ( & $this , 'clone_backup_create_poll' ) );
$this -> add_action ( 'mainwp-child_clone_backupdownload' , array ( & $this , 'clone_backup_download' ) );
$this -> add_action ( 'mainwp-child_clone_backupdownloadpoll' , array ( & $this , 'clone_backup_download_poll' ) );
$this -> add_action ( 'mainwp-child_clone_backupextract' , array ( & $this , 'clone_backup_extract' ) );
}
2020-05-15 16:54:45 +00:00
2020-05-06 20:22:11 +07:00
public function add_security_nonce ( $action ) {
2016-12-08 20:54:26 +01:00
if ( ! is_array ( $this -> security_nonces ) ) {
$this -> security_nonces = array ();
}
if ( ! function_exists ( 'wp_create_nonce' ) ) {
2020-03-26 14:11:33 +00:00
include_once ABSPATH . WPINC . '/pluggable.php' ;
2016-12-08 20:54:26 +01:00
}
$this -> security_nonces [ $action ] = wp_create_nonce ( $action );
}
2020-05-06 20:22:11 +07:00
public function get_security_nonces () {
2016-12-08 20:54:26 +01:00
return $this -> security_nonces ;
}
2020-05-06 20:22:11 +07:00
public function add_action ( $action , $callback ) {
2016-12-08 20:54:26 +01:00
add_action ( 'wp_ajax_' . $action , $callback );
2020-05-06 20:22:11 +07:00
$this -> add_security_nonce ( $action );
2016-12-08 20:54:26 +01:00
}
2020-04-21 18:37:52 +02:00
public function secure_request ( $action = '' , $query_arg = 'security' ) {
2020-05-06 00:47:59 +07:00
if ( ! MainWP_Helper :: is_admin () ) {
2016-12-08 20:54:26 +01:00
die ( 0 );
}
2020-04-21 18:37:52 +02:00
if ( '' == $action ) {
2016-12-08 20:54:26 +01:00
return ;
}
if ( ! $this -> check_security ( $action , $query_arg ) ) {
2020-05-13 18:48:37 +07:00
die ( wp_json_encode ( array ( 'error' => __ ( 'Invalid request!' , 'mainwp-child' ) ) ) );
2016-12-08 20:54:26 +01:00
}
if ( isset ( $_POST [ 'dts' ] ) ) {
$ajaxPosts = get_option ( 'mainwp_ajaxposts' );
if ( ! is_array ( $ajaxPosts ) ) {
$ajaxPosts = array ();
}
2020-03-26 20:01:04 +00:00
// If already processed, just quit!
2016-12-08 20:54:26 +01:00
if ( isset ( $ajaxPosts [ $action ] ) && ( $ajaxPosts [ $action ] == $_POST [ 'dts' ] ) ) {
2020-05-13 18:48:37 +07:00
die ( wp_json_encode ( array ( 'error' => __ ( 'Double request!' , 'mainwp-child' ) ) ) );
2016-12-08 20:54:26 +01:00
}
$ajaxPosts [ $action ] = $_POST [ 'dts' ];
MainWP_Helper :: update_option ( 'mainwp_ajaxposts' , $ajaxPosts );
}
}
2020-04-21 18:37:52 +02:00
public function check_security ( $action = - 1 , $query_arg = 'security' ) {
if ( - 1 == $action ) {
2016-12-08 20:54:26 +01:00
return false ;
}
$adminurl = strtolower ( admin_url () );
$referer = strtolower ( wp_get_referer () );
$result = isset ( $_REQUEST [ $query_arg ] ) ? wp_verify_nonce ( $_REQUEST [ $query_arg ], $action ) : false ;
2020-04-21 18:37:52 +02:00
if ( ! $result && ! ( - 1 == $action && 0 === strpos ( $referer , $adminurl ) ) ) {
2016-12-08 20:54:26 +01:00
return false ;
}
return true ;
}
public function init () {
2020-05-06 20:22:11 +07:00
add_action ( 'check_admin_referer' , array ( self :: get_class_name (), 'permalink_changed' ) );
2015-10-15 22:52:37 +10:00
if ( get_option ( 'mainwp_child_clone_permalink' ) || get_option ( 'mainwp_child_restore_permalink' ) ) {
2020-05-06 20:22:11 +07:00
add_action ( 'admin_notices' , array ( self :: get_class_name (), 'permalink_admin_notice' ) );
2015-10-15 22:52:37 +10:00
}
}
public static function print_scripts () {
wp_enqueue_script ( 'jquery-ui-tooltip' );
wp_enqueue_script ( 'jquery-ui-autocomplete' );
wp_enqueue_script ( 'jquery-ui-progressbar' );
wp_enqueue_script ( 'jquery-ui-dialog' );
global $wp_scripts ;
$ui = $wp_scripts -> query ( 'jquery-ui-core' );
$version = $ui -> ver ;
2020-05-06 00:47:59 +07:00
if ( MainWP_Helper :: starts_with ( $version , '1.10' ) ) {
2020-05-05 20:13:38 +07:00
wp_enqueue_style ( 'jquery-ui-style' , plugins_url ( '/css/1.10.4/jquery-ui.min.css' , dirname ( __FILE__ ) ), array (), '1.10' , 'all' );
2015-10-15 22:52:37 +10:00
} else {
2020-05-05 20:13:38 +07:00
wp_enqueue_style ( 'jquery-ui-style' , plugins_url ( '/css/1.11.1/jquery-ui.min.css' , dirname ( __FILE__ ) ), array (), '1.11' , 'all' );
2015-10-15 22:52:37 +10:00
}
}
public static function upload_mimes ( $mime_types = array () ) {
if ( ! isset ( $mime_types [ 'tar.bz2' ] ) ) {
$mime_types [ 'tar.bz2' ] = 'application/x-tar' ;
}
return $mime_types ;
}
public static function render () {
$uploadError = false ;
$uploadFile = false ;
2017-02-21 20:40:43 +01:00
if ( isset ( $_REQUEST [ 'upload' ] ) && wp_verify_nonce ( $_POST [ '_nonce' ], 'cloneRestore' ) ) {
2015-10-15 22:52:37 +10:00
if ( isset ( $_FILES [ 'file' ] ) ) {
if ( ! function_exists ( 'wp_handle_upload' ) ) {
2020-03-26 14:11:33 +00:00
require_once ABSPATH . 'wp-admin/includes/file.php' ;
2015-10-15 22:52:37 +10:00
}
$uploadedfile = $_FILES [ 'file' ];
$upload_overrides = array ( 'test_form' => false );
2020-05-05 13:19:34 +00:00
add_filter ( 'upload_mimes' , array ( self :: get_class_name (), 'upload_mimes' ) );
2015-10-15 22:52:37 +10:00
$movefile = wp_handle_upload ( $uploadedfile , $upload_overrides );
if ( $movefile ) {
$uploadFile = str_replace ( ABSPATH , '' , $movefile [ 'file' ] );
} else {
$uploadError = __ ( 'File could not be uploaded.' , 'mainwp-child' );
}
} else {
$uploadError = __ ( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' , 'mainwp-child' );
}
}
$sitesToClone = get_option ( 'mainwp_child_clone_sites' );
$uploadSizeInBytes = min ( MainWP_Helper :: return_bytes ( ini_get ( 'upload_max_filesize' ) ), MainWP_Helper :: return_bytes ( ini_get ( 'post_max_size' ) ) );
$uploadSize = MainWP_Helper :: human_filesize ( $uploadSizeInBytes );
2020-04-21 18:37:52 +02:00
2020-05-06 20:22:11 +07:00
self :: render_style ();
2015-10-15 22:52:37 +10:00
if ( '0' === $sitesToClone ) {
2016-10-24 20:33:37 +02:00
echo '<div class="mainwp-child_info-box-red"><strong>' . esc_html__ ( 'Cloning is currently off - To turn on return to your main dashboard and turn cloning on on the Clone page.' , 'mainwp-child' ) . '</strong></div>' ;
2015-10-15 22:52:37 +10:00
return ;
}
$error = false ;
2020-05-06 00:47:59 +07:00
MainWP_Helper :: get_wp_filesystem ();
2015-10-15 22:52:37 +10:00
global $wp_filesystem ;
if ( ( ! empty ( $wp_filesystem ) && ! $wp_filesystem -> is_writable ( WP_CONTENT_DIR ) ) || ( empty ( $wp_filesystem ) && ! is_writable ( WP_CONTENT_DIR ) ) ) {
echo '<div class="mainwp-child_info-box-red"><strong>' . esc_html__ ( 'Your content directory is not writable. Please set 0755 permission to ' , 'mainwp-child' ) . esc_html ( basename ( WP_CONTENT_DIR ) ) . '. (' . esc_html ( WP_CONTENT_DIR ) . ')</strong></div>' ;
$error = true ;
}
?>
2020-04-21 18:37:52 +02:00
< div class = " mainwp-child_info-box-green " style = " display: none; " >
< ? php esc_html_e ( 'Cloning process completed successfully! You will now need to click ' , 'mainwp-child' ); ?>
< a href = " <?php echo esc_url( admin_url( 'options-permalink.php' ) ); ?> " >< ? php esc_html_e ( 'here' , 'mainwp-child' ); ?> </a>
< ? php esc_html_e ( ' to re-login to the admin and re-save permalinks.' , 'mainwp-child' ); ?>
2020-03-27 15:13:11 +00:00
</ div >
2015-10-15 22:52:37 +10:00
< ? php
2020-05-15 23:53:53 +07:00
self :: render_form ( $sitesToClone , $uploadFile , $uploadSize , $error , $uploadError );
self :: render_clone_from_server ();
self :: render_java_script ();
}
2020-05-15 16:54:45 +00:00
private static function render_form ( $sitesToClone , $uploadFile , $uploadSize , $error , $uploadError ) {
2020-05-15 23:53:53 +07:00
2020-05-15 16:54:45 +00:00
if ( ! empty ( $uploadFile ) ) {
2020-03-26 14:05:04 +00:00
esc_html_e ( 'Upload successful.' , 'mainwp-child' );
2020-03-27 15:13:11 +00:00
?>
2020-04-21 18:37:52 +02:00
< a href = " # " id = " mainwp-child_uploadclonebutton " class = " button-primary " file = " <?php echo esc_attr( $uploadFile ); ?> " >< ? php esc_html_e ( 'Clone/Restore website' , 'mainwp-child' ); ?> </a>
< ? php
2020-05-15 23:53:53 +07:00
return ;
}
2020-05-15 16:54:45 +00:00
2020-05-15 23:53:53 +07:00
if ( $uploadError ) {
?>
< div class = " mainwp-child_info-box-red " >< ? php echo esc_html ( $uploadError ); ?> </div>
< ? php
}
2015-10-15 22:52:37 +10:00
2020-05-15 23:53:53 +07:00
if ( empty ( $sitesToClone ) ) {
echo '<div class="mainwp-child_info-box-yellow"><strong>' . esc_html__ ( 'Cloning is currently on but no sites have been allowed, to allow sites return to your main dashboard and turn cloning on on the Clone page.' , 'mainwp-child' ) . '</strong></div>' ;
} else {
?>
< form method = " post " action = " " >
< div class = " mainwp-child_select_sites_box " >
< div class = " postbox " >
< div class = " mainwp-child_displayby " >< ? php esc_html_e ( 'Display by:' , 'mainwp-child' ); ?> <a class="mainwp-child_action left mainwp-child_action_down" href="#" id="mainwp-child_displayby_sitename"><?php esc_html_e( 'Site Name', 'mainwp-child' ); ?></a><a class="mainwp-child_action right" href="#" id="mainwp-child_displayby_url"><?php esc_html_e( 'URL', 'mainwp-child' ); ?></a></div>
< h2 class = " hndle " >< ? php esc_html_e ( 'Select Source for clone' , 'mainwp-child' ); ?> </h2>
< div class = " inside " >
< div id = " mainwp-child_clonesite_select_site " >
< ? php
foreach ( $sitesToClone as $siteId => $siteToClone ) {
2015-10-15 22:52:37 +10:00
?>
2020-05-15 23:53:53 +07:00
< div class = " clonesite_select_site_item " id = " <?php echo esc_attr( $siteId ); ?> " rand = " <?php echo esc_attr( MainWP_Helper::rand_string( 5 ) ); ?> " >
< div class = " mainwp-child_size_label " size = " <?php echo esc_attr( $siteToClone['size'] ); ?> " >< ? php echo esc_html ( $siteToClone [ 'size' ] ); ?> MB</div>
< div class = " mainwp-child_name_label " >< ? php echo esc_html ( $siteToClone [ 'name' ] ); ?> </div>
< div class = " mainwp-child_url_label " >< ? php echo esc_html ( MainWP_Helper :: get_nice_url ( $siteToClone [ 'url' ] ) ); ?> </div>
</ div >
< ? php
}
?>
2020-03-27 15:13:11 +00:00
</ div >
2020-05-15 23:53:53 +07:00
< p >< ? php _e ( 'The site selected above will replace this site\'s files and database' , 'mainwp-child' ); ?> </p>
2020-03-27 15:13:11 +00:00
</ div >
2020-05-15 23:53:53 +07:00
< div class = " mainwp-child_clonebutton_container " >
< ? php if ( ! $error ) { ?>
< a href = " # " id = " mainwp-child_clonebutton " class = " button-primary " >< ? php esc_html_e ( 'Clone website' , 'mainwp-child' ); ?> </a>
< ? php } ?>
</ div >
< div style = " clear:both " ></ div >
2020-03-27 15:13:11 +00:00
</ div >
2020-04-21 18:37:52 +02:00
</ div >
2020-05-15 23:53:53 +07:00
</ form >
< br />
2015-10-15 22:52:37 +10:00
< ? php
2020-05-15 16:54:45 +00:00
}
2020-05-15 23:53:53 +07:00
?>
< div class = " postbox " >
< h2 class = " hndle " >< strong >< ? php esc_html_e ( 'Option 1:' , 'mainwp-child' ); ?> </strong> <?php esc_html_e( 'Restore/Clone from backup', 'mainwp-child' ); ?></h2>
< div class = " inside " >
< p >< ? php esc_html_e ( 'Upload backup in .zip format (Maximum filesize for your server settings: ' , 'mainwp-child' ); ?> <?php echo esc_html( $uploadSize ); ?>)</p>
< em >< ? php esc_html_e ( 'If you have a FULL backup created by the default MainWP Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.' , 'mainwp-child' ); ?>
< br />
< ? php esc_html_e ( 'A database only backup will not work.' , 'mainwp-child' ); ?> </em>
< br />
< br />
< form action = " <?php echo esc_attr( admin_url( 'options-general.php?page=mainwp_child_tab&tab=restore-clone&upload=yes' ) ); ?> " method = " post " enctype = " multipart/form-data " >
< input type = " file " name = " file " id = " file " />
< input type = " submit " name = " submit " id = " filesubmit " class = " button button-primary " disabled = " disabled " value = " <?php esc_attr_e( 'Clone/Restore Website', 'mainwp-child' ); ?> " />
< input type = " hidden " name = " _nonce " value = " <?php echo wp_create_nonce( 'cloneRestore' ); ?> " />
</ form >
</ div >
</ div >
< ? php
2015-10-15 22:52:37 +10:00
}
2020-05-15 16:54:45 +00:00
2020-05-06 20:22:11 +07:00
public static function render_normal_restore () {
2015-10-15 22:52:37 +10:00
$uploadError = false ;
$uploadFile = false ;
2020-04-21 18:37:52 +02:00
2017-02-21 20:40:43 +01:00
if ( isset ( $_REQUEST [ 'upload' ] ) && wp_verify_nonce ( $_POST [ '_nonce' ], 'cloneRestore' ) ) {
2015-10-15 22:52:37 +10:00
if ( isset ( $_FILES [ 'file' ] ) ) {
if ( ! function_exists ( 'wp_handle_upload' ) ) {
2020-03-26 14:11:33 +00:00
require_once ABSPATH . 'wp-admin/includes/file.php' ;
2015-10-15 22:52:37 +10:00
}
$uploadedfile = $_FILES [ 'file' ];
$upload_overrides = array ( 'test_form' => false );
$movefile = wp_handle_upload ( $uploadedfile , $upload_overrides );
if ( $movefile ) {
$uploadFile = str_replace ( ABSPATH , '' , $movefile [ 'file' ] );
} else {
$uploadError = __ ( 'File could not be uploaded.' , 'mainwp-child' );
}
} else {
$uploadError = __ ( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' , 'mainwp-child' );
}
}
$uploadSizeInBytes = min ( MainWP_Helper :: return_bytes ( ini_get ( 'upload_max_filesize' ) ), MainWP_Helper :: return_bytes ( ini_get ( 'post_max_size' ) ) );
$uploadSize = MainWP_Helper :: human_filesize ( $uploadSizeInBytes );
2020-05-06 20:22:11 +07:00
self :: render_style ();
2015-10-15 22:52:37 +10:00
?>
2016-04-27 21:54:28 +02:00
< div class = " postbox " >
2020-04-21 18:37:52 +02:00
< h2 class = " hndle " >< span >< strong >< ? php esc_html_e ( 'Option 1:' , 'mainwp-child' ); ?> </strong> <?php esc_html_e( 'Restore', 'mainwp-child' ); ?></span></h2>
2020-03-27 15:13:11 +00:00
< div class = " inside " >
2020-04-21 18:37:52 +02:00
< ? php
2020-05-06 00:47:59 +07:00
MainWP_Helper :: get_wp_filesystem ();
2016-04-27 21:54:28 +02:00
global $wp_filesystem ;
2020-04-21 18:37:52 +02:00
if ( ( ! empty ( $wp_filesystem ) && ! $wp_filesystem -> is_writable ( WP_CONTENT_DIR ) ) || ( empty ( $wp_filesystem ) && ! is_writable ( WP_CONTENT_DIR ) ) ) {
echo '<div class="mainwp-child_info-box-red"><strong>' . esc_html__ ( 'Your content directory is not writable. Please set 0755 permission to ' , 'mainwp-child' ) . esc_html ( basename ( WP_CONTENT_DIR ) ) . '. (' . esc_html ( WP_CONTENT_DIR ) . ')</strong></div>' ;
$error = true ;
}
2020-03-27 15:13:11 +00:00
?>
2020-04-21 18:37:52 +02:00
< div class = " mainwp-child_info-box-green " style = " display: none; " >< ? php esc_html_e ( 'Restore process completed successfully! You will now need to click ' , 'mainwp-child' ); ?>
< a href = " <?php echo esc_attr( admin_url( 'options-permalink.php' ) ); ?> " >< ? php esc_html_e ( 'here' , 'mainwp-child' ); ?> </a><?php esc_html_e( ' to re-login to the admin and re-save permalinks.', 'mainwp-child' ); ?>
</ div >
< ? php
if ( $uploadFile ) {
esc_html_e ( 'Upload successful.' , 'mainwp-child' );
2020-03-26 19:51:58 +00:00
?>
2020-04-21 18:37:52 +02:00
< a href = " # " id = " mainwp-child_uploadclonebutton " class = " button-primary " file = " <?php echo esc_attr( $uploadFile ); ?> " >< ? php esc_html_e ( 'Restore Website' , 'mainwp-child' ); ?> </a>
2020-03-26 19:51:58 +00:00
< ? php
2020-04-21 18:37:52 +02:00
} else {
if ( $uploadError ) {
?>
< div class = " mainwp-child_info-box-red " >< ? php echo esc_html ( $uploadError ); ?> </div>
2020-03-27 15:13:11 +00:00
< ? php
2020-04-21 18:37:52 +02:00
}
?>
< p >< ? php esc_html_e ( 'Upload backup in .zip format (Maximum filesize for your server settings: ' , 'mainwp-child' ); ?> <?php echo esc_html( $uploadSize ); ?>)</p>
< ? php
2020-05-06 20:22:11 +07:00
$branding_title = MainWP_Child_Branding :: instance () -> get_branding_title ();
2020-04-23 17:05:27 +02:00
if ( '' != $branding_title ) {
2020-04-21 16:37:59 +00:00
$branding_msg = 'If you have a FULL backup created by basic ' . esc_html ( stripslashes ( $branding_title ) ) . ' Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.' ;
} else {
$branding_msg = esc_html__ ( 'If you have a FULL backup created by basic MainWP Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.' , 'mainwp-child' );
}
?>
2020-04-21 18:37:52 +02:00
< em >
< ? php echo $branding_msg ; ?> <br/>
< ? php esc_html_e ( 'A database only backup will not work.' , 'mainwp-child' ); ?>
</ em >< br />< br />
< form action = " <?php echo esc_attr( admin_url( 'options-general.php?page=mainwp_child_tab&tab=restore-clone&upload=yes' ) ); ?> " method = " post " enctype = " multipart/form-data " >
< input type = " file " name = " file " id = " file " />
< input type = " submit " name = " submit " class = " button button-primary " id = " filesubmit " disabled = " disabled " value = " <?php esc_attr_e( 'Restore Website', 'mainwp-child' ); ?> " />
< input type = " hidden " name = " _nonce " value = " <?php echo wp_create_nonce( 'cloneRestore' ); ?> " />
</ form >
< ? php } ?>
2020-03-27 15:13:11 +00:00
</ div >
</ div >
2020-04-21 18:37:52 +02:00
< ? php
2019-02-14 22:38:14 +07:00
2020-05-06 20:22:11 +07:00
self :: render_clone_from_server ();
self :: render_java_script ();
2015-10-15 22:52:37 +10:00
}
2020-04-21 18:37:52 +02:00
/**
* Credit
*
* Plugin Name : Add From Server
* Version : 3.2 . 0.3
* Plugin URI : http :// dd32 . id . au / wordpress - plugins / add - from - server /
* Description : Plugin to allow the Media Manager to add files from the webservers filesystem . < strong > Note :</ strong > All files are copied to the uploads directory .
* Author : Dion Hulse
* Author URI : http :// dd32 . id . au /
*/
2020-05-06 20:22:11 +07:00
public static function render_clone_from_server () {
2020-04-21 18:37:52 +02:00
$page = $_REQUEST [ 'page' ];
2019-02-14 22:38:14 +07:00
$sitesToClone = get_option ( 'mainwp_child_clone_sites' );
2016-04-27 21:54:28 +02:00
$url = admin_url ( 'options-general.php?page=mainwp_child_tab&tab=restore-clone#title_03' );
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' , false );
2020-04-21 18:37:52 +02:00
$current_dir = $dirs [ 0 ];
$backup_dir = $current_dir ;
2015-10-15 22:52:37 +10:00
if ( isset ( $_REQUEST [ 'dir' ] ) ) {
2020-04-21 18:37:52 +02:00
$current_dir = stripslashes ( rawurldecode ( $_REQUEST [ 'dir' ] ) );
2015-10-15 22:52:37 +10:00
$current_dir = '/' . ltrim ( $current_dir , '/' );
if ( ! is_readable ( $current_dir ) && get_option ( 'mainwp_child_clone_from_server_last_folder' ) ) {
$current_dir = get_option ( 'mainwp_child_clone_from_server_last_folder' ) . $current_dir ;
}
}
if ( ! is_readable ( $current_dir ) ) {
$current_dir = WP_CONTENT_DIR ;
}
$current_dir = str_replace ( '\\' , '/' , $current_dir );
if ( strlen ( $current_dir ) > 1 ) {
$current_dir = untrailingslashit ( $current_dir );
}
2020-04-21 18:37:52 +02:00
2016-04-27 21:54:28 +02:00
echo '<div class="postbox">' ;
echo '<h2 id="title_03" class="hndle"><span><strong>' . esc_html__ ( 'Option 2:' , 'mainwp-child' ) . '</strong> ' . esc_html__ ( 'Restore/Clone From Server' , 'mainwp-child' ) . '</span></h2>' ;
echo '<div class="inside">' ;
echo '<em>' . esc_html__ ( 'If you have uploaded a FULL backup to your server (via FTP or other means) you can use this section to locate the zip file and select it. A database only backup will not work.' , 'mainwp-child' ) . '</em>' ;
2015-10-15 22:52:37 +10:00
if ( ! is_readable ( $current_dir ) ) {
echo '<div class="mainwp-child_info-box-yellow"><strong>' . esc_html__ ( 'Root directory is not readable. Please contact with site administrator to correct.' , 'mainwp-child' ) . '</strong></div>' ;
return ;
}
MainWP_Helper :: update_option ( 'mainwp_child_clone_from_server_last_folder' , rtrim ( $current_dir , '/' ) );
2020-04-21 16:37:59 +00:00
$parts = explode ( '/' , ltrim ( $current_dir , '/' ) );
$dirparts = '' ;
2020-04-21 18:37:52 +02:00
$count_parts = count ( $parts );
for ( $i = $count_parts - 1 ; $i >= 0 ; $i -- ) {
2015-10-15 22:52:37 +10:00
$part = $parts [ $i ];
$adir = implode ( '/' , array_slice ( $parts , 0 , $i + 1 ) );
if ( strlen ( $adir ) > 1 ) {
$adir = ltrim ( $adir , '/' );
}
$durl = esc_url ( add_query_arg ( array ( 'dir' => rawurlencode ( $adir ) ), $url ) );
$dirparts = '<a href="' . $durl . '">' . $part . DIRECTORY_SEPARATOR . '</a>' . $dirparts ;
}
2017-01-14 13:16:52 +01:00
echo '<div style="padding: 8px 12px; background-color: #e5e5e5; margin-top: 1em;">' . __ ( '<strong>Current Directory:</strong> <span>' . $dirparts . '</span>' , 'mainwp-child' ) . '</div>' ;
2015-10-15 22:52:37 +10:00
$quick_dirs = array ();
2017-01-14 13:16:52 +01:00
$quick_dirs [] = array ( __ ( 'Site Root' , 'mainwp-child' ), ABSPATH );
$quick_dirs [] = array ( __ ( 'Backup' , 'mainwp-child' ), $backup_dir );
2020-04-23 15:06:40 +00:00
$uploads = wp_upload_dir ();
2020-04-23 17:05:27 +02:00
if ( $uploads && false === $uploads [ 'error' ] ) {
2017-01-14 13:16:52 +01:00
$quick_dirs [] = array ( __ ( 'Uploads Folder' , 'mainwp-child' ), $uploads [ 'path' ] );
2015-10-15 22:52:37 +10:00
}
2017-01-14 13:16:52 +01:00
$quick_dirs [] = array ( __ ( 'Content Folder' , 'mainwp-child' ), WP_CONTENT_DIR );
2015-10-15 22:52:37 +10:00
$quick_links = array ();
foreach ( $quick_dirs as $dir ) {
list ( $text , $adir ) = $dir ;
2020-03-26 19:45:07 +00:00
$adir = str_replace ( '\\' , '/' , strtolower ( $adir ) );
2015-10-15 22:52:37 +10:00
if ( strlen ( $adir ) > 1 ) {
$adir = ltrim ( $adir , '/' );
}
$durl = esc_url ( add_query_arg ( array ( 'dir' => rawurlencode ( $adir ) ), $url ) );
$quick_links [] = " <a href=' $durl '> $text </a> " ;
}
if ( ! empty ( $quick_links ) ) {
2017-01-14 13:16:52 +01:00
echo '<div style="padding: 8px 12px; border-bottom: 1px solid #e5e5e5; margin-bottom: 1em;"><strong>' . esc_html__ ( 'Quick Jump:' , 'mainwp-child' ) . '</strong> ' . __ ( implode ( ' | ' , $quick_links ) ) . '</div>' ;
2015-10-15 22:52:37 +10:00
}
2020-05-15 16:54:45 +00:00
self :: render_clone_from_server_form ( $current_dir , $url );
2020-05-15 23:53:53 +07:00
}
private static function render_clone_from_server_form ( $current_dir , $url ) {
2020-05-15 16:54:45 +00:00
2015-10-15 22:52:37 +10:00
$dir_files = scandir ( $current_dir );
$directories = array ();
$files = array ();
$rejected_files = array ();
foreach ( ( array ) $dir_files as $file ) {
if ( in_array ( $file , array ( '.' , '..' ) ) ) {
continue ;
}
if ( is_dir ( $current_dir . '/' . $file ) ) {
$directories [] = $file ;
} else {
2020-05-06 00:47:59 +07:00
if ( ! MainWP_Helper :: is_archive ( $file ) ) {
2015-10-15 22:52:37 +10:00
$rejected_files [] = $file ;
} else {
$files [] = $file ;
}
}
}
sort ( $directories );
2020-05-15 16:54:45 +00:00
sort ( $files );
2015-10-15 22:52:37 +10:00
$parent = dirname ( $current_dir );
?>
2020-03-27 15:13:11 +00:00
< form method = " post " action = " " >
< div class = " mainwp-child_select_sites_box " id = " mainwp_child_select_files_from_server_box " >
< div class = " postbox " >
2016-04-27 21:54:28 +02:00
< h2 class = " hndle " >< ? php esc_html_e ( 'Select File' , 'mainwp-child' ); ?> </h2>
2020-03-27 15:13:11 +00:00
< div class = " inside " >
< div id = " mainwp-child_clonesite_select_site " >
< div class = " clonesite_select_site_item " >
< div class = " mainwp-child_name_label " >
2020-04-21 18:37:52 +02:00
< a href = " <?php echo esc_url( add_query_arg( array( 'dir' => rawurlencode( $parent ) ), $url ) ); ?> " title = " <?php echo esc_attr( dirname( $current_dir ) ); ?> " >< ? php esc_html_e ( 'Parent Folder' , 'mainwp-child' ); ?> </a>
2020-03-27 15:13:11 +00:00
</ div >
</ div >
2015-10-15 22:52:37 +10:00
< ? php
foreach ( ( array ) $directories as $file ) {
$filename = ltrim ( $file , '/' );
$folder_url = esc_url ( add_query_arg ( array ( 'dir' => rawurlencode ( $filename ) ), $url ) );
?>
2020-03-27 15:13:11 +00:00
< div class = " clonesite_select_site_item " >
< div class = " mainwp-child_name_label " >
2020-03-26 14:05:04 +00:00
< a href = " <?php echo esc_attr( $folder_url ); ?> " >< ? php echo esc_html ( rtrim ( $filename , '/' ) . DIRECTORY_SEPARATOR ); ?> </a>
2020-03-27 15:13:11 +00:00
</ div >
</ div >
2015-10-15 22:52:37 +10:00
< ? php
}
foreach ( $files as $file ) {
?>
2020-03-27 15:13:11 +00:00
< div class = " clonesite_select_site_item " >
< div class = " mainwp-child_name_label " >
2020-03-26 14:05:04 +00:00
< span >< ? php echo esc_html ( $file ); ?> </span>
2020-03-27 15:13:11 +00:00
</ div >
</ div >
2015-10-15 22:52:37 +10:00
< ? php
}
foreach ( $rejected_files as $file ) {
?>
2020-03-27 15:13:11 +00:00
< div class = " mainwp_rejected_files " >
< div class = " mainwp-child_name_label " >
2020-03-26 14:05:04 +00:00
< span >< ? php echo esc_html ( $file ); ?> </span>
2020-03-27 15:13:11 +00:00
</ div >
</ div >
2015-10-15 22:52:37 +10:00
< ? php
}
?>
2020-03-27 15:13:11 +00:00
</ div >
</ div >
2020-04-21 18:37:52 +02:00
< div class = " mainwp-child_clonebutton_container " >
< a href = " # " id = " mainwp-child_clonebutton_from_server " class = " button-primary button " >< ? php esc_html_e ( 'Clone/Restore Website' , 'mainwp-child' ); ?> </a>
2020-03-27 15:13:11 +00:00
</ div >
< div style = " clear:both " ></ div >
</ div >
</ div >
</ form >
2015-10-15 22:52:37 +10:00
< input type = " hidden " id = " clonesite_from_server_current_dir " value = " <?php echo esc_attr( $current_dir ); ?> " />
2016-04-27 21:54:28 +02:00
</ div >
</ div >
2015-10-15 22:52:37 +10:00
< ? php
}
2020-05-15 16:54:45 +00:00
2020-05-06 20:22:11 +07:00
public static function render_java_script () {
2015-10-15 22:52:37 +10:00
$uploadSizeInBytes = min ( MainWP_Helper :: return_bytes ( ini_get ( 'upload_max_filesize' ) ), MainWP_Helper :: return_bytes ( ini_get ( 'post_max_size' ) ) );
$uploadSize = MainWP_Helper :: human_filesize ( $uploadSizeInBytes );
?>
2020-03-27 15:13:11 +00:00
< div id = " mainwp-child_clone_status " title = " Restore process " ></ div >
< script language = " javascript " >
var child_security_nonces = [];
< ? php
2020-05-06 20:22:11 +07:00
$security_nonces = self :: get () -> get_security_nonces ();
2020-03-27 14:11:21 +00:00
foreach ( $security_nonces as $k => $v ) {
2020-03-26 19:51:58 +00:00
echo 'child_security_nonces[' . " ' " . $k . " ' " . '] = ' . " ' " . $v . " '; \n " ;
}
2016-12-08 20:54:26 +01:00
?>
mainwpchild_secure_data = function ( data , includeDts )
{
2020-03-27 15:13:11 +00:00
if ( data [ 'action' ] == undefined ) return data ;
2016-12-08 20:54:26 +01:00
2020-03-27 15:13:11 +00:00
data [ 'security' ] = child_security_nonces [ data [ 'action' ]];
if ( includeDts ) data [ 'dts' ] = Math . round ( new Date () . getTime () / 1000 );
return data ;
2016-12-08 20:54:26 +01:00
};
2020-03-27 15:13:11 +00:00
jQuery ( document ) . on ( 'change' , '#file' , function () {
2015-10-15 22:52:37 +10:00
var maxSize = < ? php echo esc_js ( $uploadSizeInBytes ); ?> ;
var humanSize = '<?php echo esc_js( $uploadSize ); ?>' ;
2020-03-27 15:13:11 +00:00
if ( this . files [ 0 ] . size > maxSize ) {
jQuery ( '#filesubmit' ) . attr ( 'disabled' , 'disabled' );
alert ( 'The selected file is bigger than your maximum allowed filesize. (Maximum: ' + humanSize + ')' );
}
else {
jQuery ( '#filesubmit' ) . removeAttr ( 'disabled' );
}
} );
jQuery ( document ) . on ( 'click' , '#mainwp-child_displayby_sitename' , function () {
jQuery ( '#mainwp-child_displayby_url' ) . removeClass ( 'mainwp-child_action_down' );
jQuery ( this ) . addClass ( 'mainwp-child_action_down' );
jQuery ( '.mainwp-child_url_label' ) . hide ();
jQuery ( '.mainwp-child_name_label' ) . show ();
return false ;
} );
jQuery ( document ) . on ( 'click' , '#mainwp-child_displayby_url' , function () {
jQuery ( '#mainwp-child_displayby_sitename' ) . removeClass ( 'mainwp-child_action_down' );
jQuery ( this ) . addClass ( 'mainwp-child_action_down' );
jQuery ( '.mainwp-child_name_label' ) . hide ();
jQuery ( '.mainwp-child_url_label' ) . show ();
return false ;
} );
jQuery ( document ) . on ( 'click' , '.clonesite_select_site_item' , function () {
jQuery ( '.clonesite_select_site_item' ) . removeClass ( 'selected' );
jQuery ( this ) . addClass ( 'selected' );
} );
var pollingCreation = undefined ;
var backupCreationFinished = false ;
var pollingDownloading = undefined ;
var backupDownloadFinished = false ;
handleCloneError = function ( resp ) {
updateClonePopup ( resp . error , true , 'red' );
};
updateClonePopup = function ( pText , pShowDate , pColor ) {
if ( pShowDate == undefined ) pShowDate = true ;
var theDiv = jQuery ( '#mainwp-child_clone_status' );
theDiv . append ( '<br /><span style="color: ' + pColor + ';">' + ( pShowDate ? cloneDateToHMS ( new Date () ) + ' ' : '' ) + pText + '</span>' );
theDiv . animate ( { scrollTop : theDiv . height () * 2 }, 100 );
};
cloneDateToHMS = function ( date ) {
var h = date . getHours ();
var m = date . getMinutes ();
var s = date . getSeconds ();
return '' + ( h <= 9 ? '0' + h : h ) + ':' + ( m <= 9 ? '0' + m : m ) + ':' + ( s <= 9 ? '0' + s : s );
};
var translations = [];
2015-10-15 22:52:37 +10:00
translations [ 'large_site' ] = " <?php esc_html_e( 'This is a large site (%dMB), the restore process will more than likely fail.', 'mainwp-child' ); ?> " ;
translations [ 'continue_anyway' ] = " <?php esc_html_e( 'Continue Anyway?', 'mainwp-child' ); ?> " ;
2020-03-26 14:05:04 +00:00
translations [ 'creating_backup' ] = " <?php esc_html_e( 'Creating backup on %1 $s expected size: %2 $dMB (estimated time: %3 $d seconds)', 'mainwp-child' ); ?> " ;
translations [ 'backup_created' ] = " <?php esc_html_e( 'Backup created on %1 $s total size to download: %2 $dMB ', 'mainwp-child' ); ?> " ;
2015-10-15 22:52:37 +10:00
translations [ 'downloading_backup' ] = " <?php esc_html_e( 'Downloading backup', 'mainwp-child' ); ?> " ;
translations [ 'backup_downloaded' ] = " <?php esc_html_e( 'Backup downloaded', 'mainwp-child' ); ?> " ;
translations [ 'extracting_backup' ] = " <?php esc_html_e( 'Extracting backup and updating your database, this might take a while. Please be patient.', 'mainwp-child' ); ?> " ;
translations [ 'clone_complete' ] = " <?php esc_html_e( 'Cloning process completed successfully!', 'mainwp-child' ); ?> " ;
2020-03-27 15:13:11 +00:00
cloneInitiateBackupCreation = function ( siteId , siteName , size , rand , continueAnyway ) {
if ( ( continueAnyway == undefined ) && ( size > 256 ) ) {
updateClonePopup ( mwp_sprintf ( translations [ 'large_site' ], size ) + ' <a href="#" class="button continueCloneButton" onClick="cloneInitiateBackupCreation(' + " ' " + siteId + " ' " + ', ' + " ' " + siteName + " ' " + ', ' + size + ', ' + " ' " + rand + " ' " + ', true); return false;">' + translations [ 'continue_anyway' ] + '</a>' );
return ;
}
else {
jQuery ( '.continueCloneButton' ) . hide ();
}
2020-04-21 18:37:52 +02:00
size = size / 2.4 ;
2020-03-27 15:13:11 +00:00
updateClonePopup ( mwp_sprintf ( translations [ 'creating_backup' ], siteName , size . toFixed ( 2 ), ( size / 5 * 3 ) . toFixed ( 2 ) ) );
updateClonePopup ( '<div id="mainwp-child-clone-create-progress" style="margin-top: 1em !important;"></div>' , false );
jQuery ( '#mainwp-child-clone-create-progress' ) . progressbar ( { value : 0 , max : ( size * 1024 )} );
var data = mainwpchild_secure_data ({
action : 'mainwp-child_clone_backupcreate' ,
siteId : siteId ,
rand : rand
});
jQuery . post ( ajaxurl , data , function ( pSiteId , pSiteName ) {
return function ( resp ) {
backupCreationFinished = true ;
clearTimeout ( pollingCreation );
var progressBar = jQuery ( '#mainwp-child-clone-create-progress' );
progressBar . progressbar ( 'value' , parseFloat ( progressBar . progressbar ( 'option' , 'max' ) ) );
if ( resp . error ) {
handleCloneError ( resp );
return ;
}
updateClonePopup ( mwp_sprintf ( translations [ 'backup_created' ], pSiteName , ( resp . size / 1024 ) . toFixed ( 2 ) ) );
cloneInitiateBackupDownload ( pSiteId , resp . url , resp . size );
}
}( siteId , siteName ), 'json' );
pollingCreation = setTimeout ( function () {
cloneBackupCreationPolling ( siteId , rand );
}, 1000 );
};
cloneBackupCreationPolling = function ( siteId , rand ) {
if ( backupCreationFinished ) return ;
var data = mainwpchild_secure_data ({
action : 'mainwp-child_clone_backupcreatepoll' ,
siteId : siteId ,
rand : rand
});
jQuery . post ( ajaxurl , data , function ( pSiteId , pRand ) {
return function ( resp ) {
if ( backupCreationFinished ) return ;
if ( resp . size ) {
var progressBar = jQuery ( '#mainwp-child-clone-create-progress' );
if ( progressBar . progressbar ( 'option' , 'value' ) < progressBar . progressbar ( 'option' , 'max' ) ) {
progressBar . progressbar ( 'value' , resp . size );
}
}
pollingCreation = setTimeout ( function () {
cloneBackupCreationPolling ( pSiteId , pRand );
}, 1000 );
}
}( siteId , rand ), 'json' );
};
cloneInitiateBackupDownload = function ( pSiteId , pFile , pSize ) {
updateClonePopup ( translations [ 'downloading_backup' ] );
updateClonePopup ( '<div id="mainwp-child-clone-download-progress" style="margin-top: 1em !important;"></div>' , false );
jQuery ( '#mainwp-child-clone-download-progress' ) . progressbar ( { value : 0 , max : pSize } );
var data = mainwpchild_secure_data ({
action : 'mainwp-child_clone_backupdownload' ,
file : pFile
});
if ( pSiteId != undefined ) data [ 'siteId' ] = pSiteId ;
jQuery . post ( ajaxurl , data , function ( siteId ) {
return function ( resp ) {
backupDownloadFinished = true ;
clearTimeout ( pollingDownloading );
var progressBar = jQuery ( '#mainwp-child-clone-download-progress' );
progressBar . progressbar ( 'value' , parseFloat ( progressBar . progressbar ( 'option' , 'max' ) ) );
if ( resp . error ) {
handleCloneError ( resp );
return ;
}
updateClonePopup ( translations [ 'backup_downloaded' ] );
cloneInitiateExtractBackup ();
}
}( pSiteId ), 'json' );
pollingDownloading = setTimeout ( function () {
cloneBackupDownloadPolling ( pSiteId , pFile );
}, 1000 );
};
cloneBackupDownloadPolling = function ( siteId , pFile ) {
if ( backupDownloadFinished ) return ;
var data = mainwpchild_secure_data ({
action : 'mainwp-child_clone_backupdownloadpoll' ,
siteId : siteId ,
file : pFile
});
jQuery . post ( ajaxurl , data , function ( pSiteId ) {
return function ( resp ) {
if ( backupDownloadFinished ) return ;
if ( resp . size ) {
var progressBar = jQuery ( '#mainwp-child-clone-download-progress' );
if ( progressBar . progressbar ( 'option' , 'value' ) < progressBar . progressbar ( 'option' , 'max' ) ) {
progressBar . progressbar ( 'value' , resp . size );
}
}
pollingDownloading = setTimeout ( function () {
cloneBackupDownloadPolling ( pSiteId );
}, 1000 );
}
}( siteId ), 'json' );
};
cloneInitiateExtractBackup = function ( file ) {
if ( file == undefined ) file = '' ;
updateClonePopup ( translations [ 'extracting_backup' ] );
var data = mainwpchild_secure_data ({
action : 'mainwp-child_clone_backupextract' ,
f : file
});
jQuery . ajax ( {
type : " POST " ,
url : ajaxurl ,
data : data ,
success : function ( resp ) {
if ( resp . error ) {
handleCloneError ( resp );
return ;
}
updateClonePopup ( translations [ 'clone_complete' ] );
setTimeout ( function () {
jQuery ( '#mainwp-child_clone_status' ) . dialog ( 'close' );
jQuery ( '.mainwp-child_select_sites_box' ) . hide ();
jQuery ( '.mainwp-child_info-box-green' ) . show ();
jQuery ( '#mainwp-child_uploadclonebutton' ) . hide ();
jQuery ( '#mainwp-child_clonebutton' ) . hide ();
jQuery ( '.mainwp-hide-after-restore' ) . hide ();
}, 1000 );
},
dataType : 'json'
} );
};
jQuery ( document ) . on ( 'click' , '#mainwp-child-restore' , function () {
jQuery ( '#mainwp-child_clone_status' ) . dialog ( {
resizable : false ,
height : 400 ,
width : 750 ,
modal : true ,
close : function ( event , ui ) {
bulkTaskRunning = false ;
jQuery ( '#mainwp-child_clone_status' ) . dialog ( 'destroy' );
}
} );
cloneInitiateBackupDownload ( undefined , jQuery ( this ) . attr ( 'file' ), jQuery ( this ) . attr ( 'size' ) );
return false ;
} );
jQuery ( document ) . on ( 'click' , '#mainwp-child_uploadclonebutton' , function () {
var file = jQuery ( this ) . attr ( 'file' );
jQuery ( '#mainwp-child_clone_status' ) . dialog ( {
resizable : false ,
height : 400 ,
width : 750 ,
modal : true ,
close : function ( event , ui ) {
bulkTaskRunning = false ;
jQuery ( '#mainwp-child_clone_status' ) . dialog ( 'destroy' );
}
} );
cloneInitiateExtractBackup ( file );
return false ;
} );
jQuery ( document ) . on ( 'click' , '#mainwp-child_clonebutton' , function () {
jQuery ( '#mainwp-child_clone_status' ) . dialog ( {
resizable : false ,
height : 400 ,
width : 750 ,
modal : true ,
close : function ( event , ui ) {
bulkTaskRunning = false ;
jQuery ( '#mainwp-child_clone_status' ) . dialog ( 'destroy' );
}
} );
var siteElement = jQuery ( '.clonesite_select_site_item.selected' );
var siteId = siteElement . attr ( 'id' );
var siteName = siteElement . find ( '.mainwp-child_name_label' ) . html ();
var siteSize = siteElement . find ( '.mainwp-child_size_label' ) . attr ( 'size' );
var siteRand = siteElement . attr ( 'rand' );
cloneInitiateBackupCreation ( siteId , siteName , siteSize , siteRand );
return false ;
} );
function mwp_sprintf () {
if ( ! arguments || arguments . length < 1 || ! RegExp ) {
return ;
}
var str = arguments [ 0 ];
var re = / ([ ^% ] * ) % ( ' .| 0 | \x20 ) ? ( - ) ? ( \d + ) ? ( \ . \d + ) ? ( %| b | c | d | u | f | o | s | x | X )( .* ) / ;
var a = b = [], numSubstitutions = 0 , numMatches = 0 ;
while ( a = re . exec ( str ) ) {
var leftpart = a [ 1 ], pPad = a [ 2 ], pJustify = a [ 3 ], pMinLength = a [ 4 ];
var pPrecision = a [ 5 ], pType = a [ 6 ], rightPart = a [ 7 ];
numMatches ++ ;
if ( pType == '%' ) {
subst = '%' ;
}
else {
numSubstitutions ++ ;
if ( numSubstitutions >= arguments . length ) {
alert ( 'Error! Not enough function arguments (' + ( arguments . length - 1 ) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).' );
}
var param = arguments [ numSubstitutions ];
var pad = '' ;
if ( pPad && pPad . substr ( 0 , 1 ) == " ' " ) pad = leftpart . substr ( 1 , 1 );
else if ( pPad ) pad = pPad ;
var justifyRight = true ;
if ( pJustify && pJustify === " - " ) justifyRight = false ;
var minLength = - 1 ;
if ( pMinLength ) minLength = parseInt ( pMinLength );
var precision = - 1 ;
if ( pPrecision && pType == 'f' ) precision = parseInt ( pPrecision . substring ( 1 ) );
var subst = param ;
if ( pType == 'b' ) subst = parseInt ( param ) . toString ( 2 );
else if ( pType == 'c' ) subst = String . fromCharCode ( parseInt ( param ) );
else if ( pType == 'd' ) subst = parseInt ( param ) ? parseInt ( param ) : 0 ;
else if ( pType == 'u' ) subst = Math . abs ( param );
else if ( pType == 'f' ) subst = ( precision > - 1 ) ? Math . round ( parseFloat ( param ) * Math . pow ( 10 , precision ) ) / Math . pow ( 10 , precision ) : parseFloat ( param );
else if ( pType == 'o' ) subst = parseInt ( param ) . toString ( 8 );
else if ( pType == 's' ) subst = param ;
else if ( pType == 'x' ) subst = ( '' + parseInt ( param ) . toString ( 16 )) . toLowerCase ();
else if ( pType == 'X' ) subst = ( '' + parseInt ( param ) . toString ( 16 )) . toUpperCase ();
}
str = leftpart + subst + rightPart ;
}
return str ;
}
jQuery ( document ) . on ( 'click' , '#mainwp-child_clonebutton_from_server' , function () {
var cur_dir = jQuery ( '#clonesite_from_server_current_dir' ) . val ();
var file = cur_dir + '/' + jQuery ( '.clonesite_select_site_item.selected span' ) . html ();
jQuery ( '#mainwp-child_clone_status' ) . dialog ( {
resizable : false ,
height : 400 ,
width : 750 ,
modal : true ,
close : function ( event , ui ) {
bulkTaskRunning = false ;
jQuery ( '#mainwp-child_clone_status' ) . dialog ( 'destroy' );
}
} );
cloneInitiateExtractBackup ( file );
return false ;
} );
</ script >
2019-02-14 22:38:14 +07:00
< ? php
2015-10-15 22:52:37 +10:00
}
2020-05-06 20:22:11 +07:00
public static function render_style () {
2015-10-15 22:52:37 +10:00
?>
2020-03-27 15:13:11 +00:00
< style >
#mainwp-child_clone_status {
display : none ;
}
. mainwp - child_info - box - yellow {
margin : 5 px 0 15 px ;
padding : . 6 em ;
background : #fff;
border - left : 4 px solid #ffec00;
clear : both ;
color : #333;
box - shadow : 0 1 px 1 px rgba ( 0 , 0 , 0 , . 04 );
}
. mainwp - child_info - box - red {
margin : 5 px 0 15 px ;
padding : . 6 em ;
background : #fff;
border - left : 4 px solid #bb4539;
clear : both ;
color : #333;
box - shadow : 0 1 px 1 px rgba ( 0 , 0 , 0 , . 04 );
}
. mainwp - child_info - box - green {
margin : 5 px 0 15 px ;
padding : . 6 em ;
background : #fff;
border - left : 4 px solid #7fb100;
clear : both ;
color : #333;
box - shadow : 0 1 px 1 px rgba ( 0 , 0 , 0 , . 04 );
}
. mainwp - child_select_sites_box {
width : 100 % ;
}
#mainwp-child_clonesite_select_site {
max - height : 585 px ! important ;
overflow : auto ;
background : #fff;
width : 100 % ;
border : 1 px solid #DDDDDD;
height : 300 px ;
overflow - y : scroll ;
margin - top : 10 px ;
}
. clonesite_select_site_item {
padding : 5 px ;
}
. clonesite_select_site_item . selected {
background - color : rgba ( 127 , 177 , 0 , 0.3 );
}
. clonesite_select_site_item : hover {
cursor : pointer ;
background - color : rgba ( 127 , 177 , 0 , 0.3 );
}
. mainwp - child_select_sites_box . postbox h2 {
margin - left : 10 px ;
}
. mainwp - child_action {
text - decoration : none ;
background : none repeat scroll 0 0 #FFFFFF;
border - color : #C9CBD1 #BFC2C8 #A9ABB1;
border - style : solid ;
color : #3A3D46;
display : inline - block ;
font - size : 12 px ;
padding : 4 px 8 px ;
- webkit - box - shadow : 0 1 px 0 rgba ( 0 , 0 , 0 , 0.05 );
- moz - box - shadow : 0 1 px 0 rgba ( 0 , 0 , 0 , 0.05 );
box - shadow : 0 1 px 0 rgba ( 0 , 0 , 0 , 0.05 );
}
. mainwp - child_action . left {
border - width : 1 px 0 1 px 1 px ;
- webkit - border - radius : 3 px 0 0 3 px ;
- moz - border - radius : 3 px 0 0 3 px ;
border - radius : 3 px 0 0 3 px ;
}
. mainwp - child_action . right {
border - width : 1 px 1 px 1 px 1 px ;
- webkit - border - radius : 0 3 px 3 px 0 ;
- moz - border - radius : 0 3 px 3 px 0 ;
border - radius : 0 3 px 3 px 0 ;
}
. mainwp - child_action_down {
background - image : - webkit - gradient ( linear , left top , left bottom , color - stop ( 0 % , rgba ( 220 , 221 , 225 , 1 )), color - stop ( 100 % , rgba ( 234 , 236 , 241 , 1 )));
background : - webkit - linear - gradient ( top , rgba ( 220 , 221 , 225 , 1 ) 0 % , rgba ( 234 , 236 , 241 , 1 ) 100 % );
background : - moz - linear - gradient ( top , rgba ( 220 , 221 , 225 , 1 ) 0 % , rgba ( 234 , 236 , 241 , 1 ) 100 % );
background : - o - linear - gradient ( top , rgba ( 220 , 221 , 225 , 1 ) 0 % , rgba ( 234 , 236 , 241 , 1 ) 100 % );
background : - ms - linear - gradient ( top , rgba ( 220 , 221 , 225 , 1 ) 0 % , rgba ( 234 , 236 , 241 , 1 ) 100 % );
background : linear - gradient ( top , rgba ( 220 , 221 , 225 , 1 ) 0 % , rgba ( 234 , 236 , 241 , 1 ) 100 % );
filter : progid : DXImageTransform . Microsoft . gradient ( startColorstr = '#dcdde1' , endColorstr = '#eaecf1' , GradientType = 0 );
- webkit - box - shadow : 0 1 px 0 rgba ( 255 , 255 , 255 , 0.59 ), 0 2 px 0 rgba ( 0 , 0 , 0 , 0.05 ) inset ;
- moz - box - shadow : 0 1 px 0 rgba ( 255 , 255 , 255 , 0.59 ), 0 2 px 0 rgba ( 0 , 0 , 0 , 0.05 ) inset ;
box - shadow : 0 1 px 0 rgba ( 255 , 255 , 255 , 0.59 ), 0 2 px 0 rgba ( 0 , 0 , 0 , 0.05 ) inset ;
border - color : #b1b5c7 #bec2d1 #c9ccd9;
}
. mainwp - child_displayby {
float : right ;
padding - top : 15 px ;
padding - right : 10 px ;
margin - top : - 8 px ;
}
. mainwp - child_url_label {
display : none ;
}
. mainwp - child_size_label {
float : right ;
padding - right : 10 px ;
font - style : italic ;
color : #8f8f8f;
}
. mainwp - child_clonebutton_container {
padding : 10 px ;
}
. ui - dialog {
padding : . 5 em ;
width : 600 px ! important ;
overflow : hidden ;
- webkit - box - shadow : 0 px 0 px 15 px rgba ( 50 , 50 , 50 , 0.45 );
- moz - box - shadow : 0 px 0 px 15 px rgba ( 50 , 50 , 50 , 0.45 );
box - shadow : 0 px 0 px 15 px rgba ( 50 , 50 , 50 , 0.45 );
background : #fff !important;
}
. ui - dialog . ui - dialog - titlebar {
background : none ;
border : none ;
}
. ui - dialog . ui - dialog - title {
font - size : 20 px ;
font - family : Helvetica ;
text - transform : uppercase ;
color : #555;
}
. ui - dialog h3 {
font - family : Helvetica ;
text - transform : uppercase ;
color : #888;
border - radius : 25 px ;
- moz - border - radius : 25 px ;
- webkit - border - radius : 25 px ;
}
. ui - dialog . ui - dialog - titlebar - close {
background : none ;
border - radius : 15 px ;
- moz - border - radius : 15 px ;
- webkit - border - radius : 15 px ;
color : #fff;
}
. ui - dialog . ui - dialog - titlebar - close : hover {
background : #7fb100;
}
#mainwp-child_clone_status .ui-progressbar {
border : 5 px Solid #ddd !important;
border - radius : 25 px ! important ;
- moz - border - radius : 25 px ! important ;
- webkit - border - radius : 25 px ! important ;
}
#mainwp-child_clone_status .ui-progressbar-value {
background : #7fb100 !important;
border - radius : 25 px ! important ;
- moz - border - radius : 25 px ! important ;
- webkit - border - radius : 25 px ! important ;
display : inline - block ;
overflow : hidden ;
- webkit - transition : width . 4 s ease - in - out ;
- moz - transition : width . 4 s ease - in - out ;
- ms - transition : width . 4 s ease - in - out ;
- o - transition : width . 4 s ease - in - out ;
transition : width . 4 s ease - in - out ;
}
#mainwp-child_clone_status .ui-progressbar-value:after {
content : " " ;
position : relative ;
top : 0 ;
height : 100 % ;
width : 100 % ;
display : inline - block ;
- webkit - background - size : 30 px 30 px ;
- moz - background - size : 30 px 30 px ;
background - size : 30 px 30 px ;
overflow : hidden ! important ;
background - image : - webkit - gradient ( linear , left top , right bottom ,
color - stop ( . 25 , rgba ( 255 , 255 , 255 , . 15 )), color - stop ( . 25 , transparent ),
color - stop ( . 5 , transparent ), color - stop ( . 5 , rgba ( 255 , 255 , 255 , . 15 )),
color - stop ( . 75 , rgba ( 255 , 255 , 255 , . 15 )), color - stop ( . 75 , transparent ),
to ( transparent ));
background - image : - webkit - linear - gradient ( 135 deg , rgba ( 255 , 255 , 255 , . 15 ) 25 % , transparent 25 % ,
transparent 50 % , rgba ( 255 , 255 , 255 , . 15 ) 50 % , rgba ( 255 , 255 , 255 , . 15 ) 75 % ,
transparent 75 % , transparent );
background - image : - moz - linear - gradient ( 135 deg , rgba ( 255 , 255 , 255 , . 15 ) 25 % , transparent 25 % ,
transparent 50 % , rgba ( 255 , 255 , 255 , . 15 ) 50 % , rgba ( 255 , 255 , 255 , . 15 ) 75 % ,
transparent 75 % , transparent );
background - image : - ms - linear - gradient ( 135 deg , rgba ( 255 , 255 , 255 , . 15 ) 25 % , transparent 25 % ,
transparent 50 % , rgba ( 255 , 255 , 255 , . 15 ) 50 % , rgba ( 255 , 255 , 255 , . 15 ) 75 % ,
transparent 75 % , transparent );
background - image : - o - linear - gradient ( 135 deg , rgba ( 255 , 255 , 255 , . 15 ) 25 % , transparent 25 % ,
transparent 50 % , rgba ( 255 , 255 , 255 , . 15 ) 50 % , rgba ( 255 , 255 , 255 , . 15 ) 75 % ,
transparent 75 % , transparent );
background - image : linear - gradient ( 135 deg , rgba ( 255 , 255 , 255 , . 15 ) 25 % , transparent 25 % ,
transparent 50 % , rgba ( 255 , 255 , 255 , . 15 ) 50 % , rgba ( 255 , 255 , 255 , . 15 ) 75 % ,
transparent 75 % , transparent );
- webkit - animation : animate - stripes 6 s linear infinite ;
- moz - animation : animate - stripes 6 s linear infinite ;
}
@- webkit - keyframes animate - stripes {
0 % {
background - position : 0 0 ;
}
100 % {
background - position : 100 % 0 ;
}
}
@- moz - keyframes animate - stripes {
0 % {
background - position : 0 0 ;
}
100 % {
background - position : 100 % 0 ;
}
}
#mainwp_child_select_files_from_server_box .mainwp-child_name_label > a {
text - decoration : none ;
}
#mainwp_child_select_files_from_server_box .mainwp_rejected_files {
background - color : #FFE8EE;
padding : 5 px ;
}
</ style >
2015-10-15 22:52:37 +10:00
< ? php
}
2020-05-06 20:22:11 +07:00
public function clone_backup_create () {
2015-10-15 22:52:37 +10:00
try {
2020-04-21 18:37:52 +02:00
$this -> secure_request ( 'mainwp-child_clone_backupcreate' );
2016-12-08 20:54:26 +01:00
2015-10-15 22:52:37 +10:00
if ( ! isset ( $_POST [ 'siteId' ] ) ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( __ ( 'No site given' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
2020-04-21 18:37:52 +02:00
$siteId = $_POST [ 'siteId' ];
$rand = $_POST [ 'rand' ];
2015-10-15 22:52:37 +10:00
$sitesToClone = get_option ( 'mainwp_child_clone_sites' );
2020-04-21 18:37:52 +02:00
2015-10-15 22:52:37 +10:00
if ( ! is_array ( $sitesToClone ) || ! isset ( $sitesToClone [ $siteId ] ) ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( __ ( 'Site not found' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
$siteToClone = $sitesToClone [ $siteId ];
$url = $siteToClone [ 'url' ];
2020-04-21 18:37:52 +02:00
$key = $siteToClone [ 'extauth' ];
2015-10-15 22:52:37 +10:00
2020-05-06 00:47:59 +07:00
MainWP_Helper :: end_session ();
2020-03-26 20:01:04 +00:00
// Send request to the childsite!
2015-10-15 22:52:37 +10:00
global $wp_version ;
$method = ( function_exists ( 'gzopen' ) ? 'tar.gz' : 'zip' );
2020-05-20 01:07:47 +07:00
$result = MainWP_Utility :: fetch_url (
2020-04-21 18:37:52 +02:00
$url ,
array (
'cloneFunc' => 'createCloneBackup' ,
'key' => $key ,
'f' => $rand ,
'wpversion' => $wp_version ,
'zipmethod' => $method ,
'json_result' => true ,
)
);
2015-10-15 22:52:37 +10:00
if ( ! $result [ 'backup' ] ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( __ ( 'Could not create backupfile on child' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
2020-04-23 19:53:22 +02:00
session_start ();
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_temp_clone_plugins' , $result [ 'plugins' ] );
MainWP_Helper :: update_option ( 'mainwp_temp_clone_themes' , $result [ 'themes' ] );
2020-03-26 15:29:54 +00:00
$output = array (
'url' => $result [ 'backup' ],
'size' => round ( $result [ 'size' ] / 1024 , 0 ),
);
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2015-10-15 22:52:37 +10:00
$output = array ( 'error' => $e -> getMessage () );
}
2020-05-13 18:48:37 +07:00
die ( wp_json_encode ( $output ) );
2015-10-15 22:52:37 +10:00
}
2020-05-06 20:22:11 +07:00
public function clone_backup_create_poll () {
2015-10-15 22:52:37 +10:00
try {
2020-04-21 18:37:52 +02:00
$this -> secure_request ( 'mainwp-child_clone_backupcreatepoll' );
2016-12-08 20:54:26 +01:00
2015-10-15 22:52:37 +10:00
if ( ! isset ( $_POST [ 'siteId' ] ) ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( __ ( 'No site given' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
$siteId = $_POST [ 'siteId' ];
$rand = $_POST [ 'rand' ];
$sitesToClone = get_option ( 'mainwp_child_clone_sites' );
if ( ! is_array ( $sitesToClone ) || ! isset ( $sitesToClone [ $siteId ] ) ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( __ ( 'Site not found' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
$siteToClone = $sitesToClone [ $siteId ];
$url = $siteToClone [ 'url' ];
$key = $siteToClone [ 'extauth' ];
2020-05-06 00:47:59 +07:00
MainWP_Helper :: end_session ();
2020-03-26 20:01:04 +00:00
// Send request to the childsite!
2020-05-20 01:07:47 +07:00
$result = MainWP_Utility :: fetch_url (
2020-04-22 20:05:24 +02:00
$url ,
array (
'cloneFunc' => 'createCloneBackupPoll' ,
'key' => $key ,
'f' => $rand ,
'json_result' => true ,
)
);
2015-10-15 22:52:37 +10:00
if ( ! isset ( $result [ 'size' ] ) ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( __ ( 'Invalid response' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
$output = array ( 'size' => round ( $result [ 'size' ] / 1024 , 0 ) );
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2015-10-15 22:52:37 +10:00
$output = array ( 'error' => $e -> getMessage () );
}
2020-05-13 18:48:37 +07:00
die ( wp_json_encode ( $output ) );
2015-10-15 22:52:37 +10:00
}
2020-05-06 20:22:11 +07:00
public function clone_backup_download () {
2015-10-15 22:52:37 +10:00
try {
2020-04-21 18:37:52 +02:00
$this -> secure_request ( 'mainwp-child_clone_backupdownload' );
2016-12-08 20:54:26 +01:00
2015-10-15 22:52:37 +10:00
if ( ! isset ( $_POST [ 'file' ] ) ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( __ ( 'No download link given' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
$file = $_POST [ 'file' ];
if ( isset ( $_POST [ 'siteId' ] ) ) {
2020-04-21 18:37:52 +02:00
$siteId = $_POST [ 'siteId' ];
2015-10-15 22:52:37 +10:00
$sitesToClone = get_option ( 'mainwp_child_clone_sites' );
2020-04-21 18:37:52 +02:00
2015-10-15 22:52:37 +10:00
if ( ! is_array ( $sitesToClone ) || ! isset ( $sitesToClone [ $siteId ] ) ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( __ ( 'Site not found' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
$siteToClone = $sitesToClone [ $siteId ];
$url = $siteToClone [ 'url' ];
$key = $siteToClone [ 'extauth' ];
2020-05-08 16:44:48 +07:00
$url = trailingslashit ( $url ) . '?cloneFunc=dl&key=' . rawurlencode ( $key ) . '&f=' . $file ;
2015-10-15 22:52:37 +10:00
} else {
$url = $file ;
}
2020-05-06 00:47:59 +07:00
MainWP_Helper :: end_session ();
2020-03-26 20:01:04 +00:00
// Send request to the childsite!
2015-10-15 22:52:37 +10:00
$split = explode ( '=' , $file );
$file = urldecode ( $split [ count ( $split ) - 1 ] );
$filename = 'download-' . basename ( $file );
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' , false );
2015-10-15 22:52:37 +10:00
$backupdir = $dirs [ 0 ];
2020-04-23 17:05:27 +02:00
$dh = opendir ( $backupdir );
if ( $dh ) {
$file = readdir ( $dh );
while ( false !== $file ) {
2020-05-06 00:47:59 +07:00
if ( '.' !== $file && '..' !== $file && MainWP_Helper :: is_archive ( $file , 'download-' ) ) {
2020-04-23 19:53:22 +02:00
unlink ( $backupdir . $file );
2015-10-15 22:52:37 +10:00
}
}
closedir ( $dh );
}
$filename = $backupdir . $filename ;
2020-04-21 18:37:52 +02:00
$response = wp_remote_get (
$url ,
array (
'timeout' => 300000 ,
'stream' => true ,
'filename' => $filename ,
)
);
2015-10-15 22:52:37 +10:00
if ( is_wp_error ( $response ) ) {
unlink ( $filename );
return $response ;
}
if ( 200 !== ( int ) wp_remote_retrieve_response_code ( $response ) ) {
unlink ( $filename );
2020-05-07 01:03:56 +07:00
return new \WP_Error ( 'http_404' , trim ( wp_remote_retrieve_response_message ( $response ) ) );
2015-10-15 22:52:37 +10:00
}
$output = array ( 'done' => $filename );
2020-04-21 18:37:52 +02:00
// Delete backup on child.
2015-10-15 22:52:37 +10:00
try {
if ( isset ( $_POST [ 'siteId' ] ) ) {
$siteId = $_POST [ 'siteId' ];
$sitesToClone = get_option ( 'mainwp_child_clone_sites' );
if ( is_array ( $sitesToClone ) && isset ( $sitesToClone [ $siteId ] ) ) {
$siteToClone = $sitesToClone [ $siteId ];
2020-05-20 01:07:47 +07:00
MainWP_Utility :: fetch_url (
2020-04-21 18:37:52 +02:00
$siteToClone [ 'url' ],
array (
'cloneFunc' => 'deleteCloneBackup' ,
'key' => $siteToClone [ 'extauth' ],
'f' => $_POST [ 'file' ],
'json_result' => true ,
)
);
2015-10-15 22:52:37 +10:00
}
}
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2015-10-15 22:52:37 +10:00
throw $e ;
}
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2015-10-15 22:52:37 +10:00
$output = array ( 'error' => $e -> getMessage () );
}
2020-05-13 18:48:37 +07:00
die ( wp_json_encode ( $output ) );
2015-10-15 22:52:37 +10:00
}
2020-05-06 20:22:11 +07:00
public function clone_backup_download_poll () {
2015-10-15 22:52:37 +10:00
try {
2020-04-22 20:05:24 +02:00
$this -> secure_request ( 'mainwp-child_clone_backupdownloadpoll' );
2016-12-08 20:54:26 +01:00
2020-05-06 00:47:59 +07:00
MainWP_Helper :: end_session ();
2015-10-15 22:52:37 +10:00
2020-05-06 00:47:59 +07:00
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' , false );
2020-04-21 18:37:52 +02:00
$backupdir = $dirs [ 0 ];
2015-10-15 22:52:37 +10:00
$files = glob ( $backupdir . 'download-*' );
$archiveFile = false ;
2020-04-21 18:37:52 +02:00
2015-10-15 22:52:37 +10:00
foreach ( $files as $file ) {
2020-05-06 00:47:59 +07:00
if ( MainWP_Helper :: is_archive ( $file , 'download-' ) ) {
2015-10-15 22:52:37 +10:00
$archiveFile = $file ;
break ;
}
}
if ( false === $archiveFile ) {
2020-05-07 01:03:56 +07:00
throw new \Exception ( __ ( 'No download file found' , 'mainwp-child' ) );
2015-10-15 22:52:37 +10:00
}
$output = array ( 'size' => filesize ( $archiveFile ) / 1024 );
2020-05-07 01:03:56 +07:00
} catch ( \Exception $e ) {
2015-10-15 22:52:37 +10:00
$output = array ( 'error' => $e -> getMessage () );
}
2020-05-13 18:48:37 +07:00
die ( wp_json_encode ( $output ) );
2015-10-15 22:52:37 +10:00
}
2020-05-06 20:22:11 +07:00
public function clone_backup_extract () {
2015-10-15 22:52:37 +10:00
try {
2020-04-22 20:05:24 +02:00
$this -> secure_request ( 'mainwp-child_clone_backupextract' );
2016-12-08 20:54:26 +01:00
2020-05-06 00:47:59 +07:00
MainWP_Helper :: end_session ();
2015-10-15 22:52:37 +10:00
2020-05-18 13:16:52 +00:00
$file = ( isset ( $_POST [ 'f' ] ) ? $_POST [ 'f' ] : $_POST [ 'file' ] );
$testFull = false ;
$file = $this -> clone_backup_get_file ( $file , $testFull );
2015-10-15 22:52:37 +10:00
$cloneInstall = new MainWP_Clone_Install ( $file );
2020-05-06 20:22:11 +07:00
$cloneInstall -> read_configuration_file ();
2015-10-15 22:52:37 +10:00
$plugins = get_option ( 'mainwp_temp_clone_plugins' );
$themes = get_option ( 'mainwp_temp_clone_themes' );
if ( $testFull ) {
2020-05-06 20:22:11 +07:00
$cloneInstall -> test_download ();
2015-10-15 22:52:37 +10:00
}
2020-05-06 20:22:11 +07:00
$cloneInstall -> remove_config_file ();
$cloneInstall -> extract_backup ();
2015-10-15 22:52:37 +10:00
$pubkey = get_option ( 'mainwp_child_pubkey' );
$uniqueId = get_option ( 'mainwp_child_uniqueId' );
$server = get_option ( 'mainwp_child_server' );
$nonce = get_option ( 'mainwp_child_nonce' );
$nossl = get_option ( 'mainwp_child_nossl' );
$nossl_key = get_option ( 'mainwp_child_nossl_key' );
$sitesToClone = get_option ( 'mainwp_child_clone_sites' );
$cloneInstall -> install ();
2020-04-21 18:37:52 +02:00
delete_option ( 'mainwp_child_pubkey' );
delete_option ( 'mainwp_child_uniqueId' );
delete_option ( 'mainwp_child_server' );
delete_option ( 'mainwp_child_nonce' );
delete_option ( 'mainwp_child_nossl' );
delete_option ( 'mainwp_child_nossl_key' );
delete_option ( 'mainwp_child_clone_sites' );
2017-05-11 21:07:42 +02:00
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_child_pubkey' , $pubkey , 'yes' );
MainWP_Helper :: update_option ( 'mainwp_child_uniqueId' , $uniqueId );
MainWP_Helper :: update_option ( 'mainwp_child_server' , $server );
MainWP_Helper :: update_option ( 'mainwp_child_nonce' , $nonce );
MainWP_Helper :: update_option ( 'mainwp_child_nossl' , $nossl , 'yes' );
MainWP_Helper :: update_option ( 'mainwp_child_nossl_key' , $nossl_key );
MainWP_Helper :: update_option ( 'mainwp_child_clone_sites' , $sitesToClone );
2020-05-06 00:47:59 +07:00
if ( ! MainWP_Helper :: starts_with ( basename ( $file ), 'download-backup-' ) ) {
2015-10-15 22:52:37 +10:00
MainWP_Helper :: update_option ( 'mainwp_child_restore_permalink' , true , 'yes' );
} else {
MainWP_Helper :: update_option ( 'mainwp_child_clone_permalink' , true , 'yes' );
}
2020-05-06 20:22:11 +07:00
$cloneInstall -> update_wp_config ();
2015-10-15 22:52:37 +10:00
$cloneInstall -> clean ();
2020-05-18 13:16:52 +00:00
$output = $this -> clone_backup_delete_files ( $plugins , $themes );
2020-05-18 20:15:34 +07:00
} catch ( \Exception $e ) {
$output = array ( 'error' => $e -> getMessage () );
}
2020-05-18 13:16:52 +00:00
2020-05-18 20:15:34 +07:00
die ( wp_json_encode ( $output ) );
}
2020-04-21 18:37:52 +02:00
2020-05-18 13:16:52 +00:00
private function clone_backup_get_file ( $file , & $testFull ) {
2020-05-18 20:15:34 +07:00
if ( '' === $file ) {
$dirs = MainWP_Helper :: get_mainwp_dir ( 'backup' , false );
$backupdir = $dirs [ 0 ];
$files = glob ( $backupdir . 'download-*' );
$archiveFile = false ;
foreach ( $files as $file ) {
if ( MainWP_Helper :: is_archive ( $file , 'download-' ) ) {
$archiveFile = $file ;
break ;
}
}
if ( false === $archiveFile ) {
throw new \Exception ( __ ( 'No download file found' , 'mainwp-child' ) );
}
$file = $archiveFile ;
} elseif ( file_exists ( $file ) ) {
$testFull = true ;
} else {
$file = ABSPATH . $file ;
if ( ! file_exists ( $file ) ) {
throw new \Exception ( __ ( 'Backup file not found' , 'mainwp-child' ) );
}
$testFull = true ;
}
return $file ;
}
2020-05-18 13:16:52 +00:00
private function clone_backup_delete_files ( $plugins , $themes ) {
2020-05-18 20:15:34 +07:00
if ( false !== $plugins ) {
$out = array ();
if ( is_array ( $plugins ) ) {
$dir = WP_CONTENT_DIR . '/plugins/' ;
$fh = opendir ( $dir );
while ( $entry = readdir ( $fh ) ) {
if ( ! is_dir ( $dir . $entry ) ) {
continue ;
}
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
continue ;
}
if ( ! in_array ( $entry , $plugins ) ) {
MainWP_Helper :: delete_dir ( $dir . $entry );
2015-10-15 22:52:37 +10:00
}
}
2020-05-18 20:15:34 +07:00
closedir ( $fh );
2015-10-15 22:52:37 +10:00
}
2020-05-18 20:15:34 +07:00
delete_option ( 'mainwp_temp_clone_plugins' );
}
if ( false !== $themes ) {
$out = array ();
if ( is_array ( $themes ) ) {
$dir = WP_CONTENT_DIR . '/themes/' ;
$fh = opendir ( $dir );
while ( $entry = readdir ( $fh ) ) {
if ( ! is_dir ( $dir . $entry ) ) {
continue ;
}
if ( ( '.' === $entry ) || ( '..' === $entry ) ) {
continue ;
}
if ( ! in_array ( $entry , $themes ) ) {
MainWP_Helper :: delete_dir ( $dir . $entry );
2015-10-15 22:52:37 +10:00
}
}
2020-05-18 20:15:34 +07:00
closedir ( $fh );
2015-10-15 22:52:37 +10:00
}
2020-05-18 20:15:34 +07:00
delete_option ( 'mainwp_temp_clone_themes' );
2015-10-15 22:52:37 +10:00
}
2020-05-18 20:15:34 +07:00
$output = array ( 'result' => 'ok' );
wp_logout ();
wp_set_current_user ( 0 );
return $output ;
2015-10-15 22:52:37 +10:00
}
2020-05-18 13:16:52 +00:00
2020-05-06 20:22:11 +07:00
public static function permalink_changed ( $action ) {
2015-10-15 22:52:37 +10:00
if ( 'update-permalink' === $action ) {
if ( isset ( $_POST [ 'permalink_structure' ] ) || isset ( $_POST [ 'category_base' ] ) || isset ( $_POST [ 'tag_base' ] ) ) {
delete_option ( 'mainwp_child_clone_permalink' );
delete_option ( 'mainwp_child_restore_permalink' );
}
}
}
2020-05-06 20:22:11 +07:00
public static function permalink_admin_notice () {
2015-10-15 22:52:37 +10:00
if ( isset ( $_POST [ 'permalink_structure' ] ) || isset ( $_POST [ 'category_base' ] ) || isset ( $_POST [ 'tag_base' ] ) ) {
return ;
}
?>
2020-03-27 15:13:11 +00:00
< style >
. mainwp - child_info - box - green {
margin : 5 px 0 15 px ;
padding : . 6 em ;
background : rgba ( 127 , 177 , 0 , 0.3 );
border : 1 px solid #7fb100;
border - radius : 3 px ;
margin - right : 10 px ;
- moz - border - radius : 3 px ;
- webkit - border - radius : 3 px ;
clear : both ;
}
</ style >
2020-03-26 14:05:04 +00:00
< div class = " mainwp-child_info-box-green " >
2020-04-21 18:37:52 +02:00
< ? php
if ( get_option ( 'mainwp_child_restore_permalink' ) ) {
2015-10-15 22:52:37 +10:00
esc_html_e ( 'Restore process completed successfully! Check and re-save permalinks ' , 'mainwp-child' );
2020-04-21 18:37:52 +02:00
} else {
2015-10-15 22:52:37 +10:00
esc_html_e ( 'Cloning process completed successfully! Check and re-save permalinks ' , 'mainwp-child' );
2020-04-21 18:37:52 +02:00
}
?>
< a href = " <?php echo esc_attr( admin_url( 'options-permalink.php' ) ); ?> " >< ? php esc_html_e ( 'here' , 'mainwp-child' ); ?> </a>.
2020-03-27 15:13:11 +00:00
</ div >
2015-10-15 22:52:37 +10:00
< ? php
}
2020-05-06 20:22:11 +07:00
public static function render_restore () {
2015-10-15 22:52:37 +10:00
if ( '' === session_id () ) {
2020-04-23 19:53:22 +02:00
session_start ();
2015-10-15 22:52:37 +10:00
}
$file = null ;
$size = null ;
2020-04-21 18:37:52 +02:00
2015-10-15 22:52:37 +10:00
if ( isset ( $_SESSION [ 'file' ] ) ) {
$file = $_SESSION [ 'file' ];
$size = $_SESSION [ 'size' ];
unset ( $_SESSION [ 'file' ] );
unset ( $_SESSION [ 'size' ] );
}
if ( null === $file ) {
die ( '<meta http-equiv="refresh" content="0;url=' . esc_url ( admin_url () ) . '">' );
}
2020-05-06 20:22:11 +07:00
self :: render_style ();
2015-10-15 22:52:37 +10:00
?>
2016-04-28 19:06:52 +02:00
< div class = " postbox " >
2020-04-21 18:37:52 +02:00
< h2 class = " hndle " >< ? php esc_html_e ( 'Restore' , 'mainwp-child' ); ?> </h2>
< div class = " inside " >
< div class = " mainwp-hide-after-restore " >
< br />
< ? php esc_html_e ( 'Be sure to use a FULL backup created by your Network dashboard, if critical folders are excluded it may result in a not working installation.' , 'mainwp-child' ); ?>
< br />
< br />
< a href = " # " class = " button-primary " file = " <?php echo esc_attr( urldecode( $file ) ); ?> " size = " <?php echo esc_attr( $size / 1024 ); ?> " id = " mainwp-child-restore " >< ? php esc_html_e ( 'Start Restore' , 'mainwp-child' ); ?> </a>
< i >< ? php esc_html_e ( 'CAUTION: this will overwrite your existing site.' , 'mainwp-child' ); ?> </i>
</ div >
< div class = " mainwp-child_info-box-green " style = " display: none; " >< ? php esc_html_e ( 'Restore process completed successfully! You will now need to click ' , 'mainwp-child' ); ?>
< a href = " <?php echo esc_attr( admin_url( 'options-permalink.php' ) ); ?> " >< ? php esc_html_e ( 'here' , 'mainwp-child' ); ?> </a><?php esc_html_e( ' to re-login to the admin and re-save permalinks.', 'mainwp-child' ); ?>
</ div >
</ div >
2020-03-27 15:13:11 +00:00
</ div >
2020-05-06 20:22:11 +07:00
< ? php self :: render_java_script (); ?>
2020-04-21 18:37:52 +02:00
< script type = " text/javascript " > translations [ 'clone_complete' ] = '<?php esc_html_e( ' Restore process completed successfully ! ', ' mainwp - child ' ); ?>' ; </ script >
2015-10-15 22:52:37 +10:00
< ? php
}
}