query( 'jquery-ui-core' ); $version = $ui->ver; if ( MainWP_Helper::startsWith( $version, '1.10' ) ) { wp_enqueue_style( 'jquery-ui-style', plugins_url( '/css/1.10.4/jquery-ui.min.css', dirname( __FILE__ ) ) ); } else { wp_enqueue_style( 'jquery-ui-style', plugins_url( '/css/1.11.1/jquery-ui.min.css', dirname( __FILE__ ) ) ); } } public static function renderHeader() { self::renderStyle(); ?>
' . __( 'Current Directory: ' . $dirparts . '', 'mainwp' ) . '
'; $quick_dirs = array(); $quick_dirs[] = array( __( 'Site Root', 'mainwp' ), ABSPATH ); $quick_dirs[] = array( __( 'Backup', 'mainwp' ), $backup_dir ); if ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) { $quick_dirs[] = array( __( 'Uploads Folder', 'mainwp' ), $uploads['path'] ); } $quick_dirs[] = array( __( 'Content Folder', 'mainwp' ), WP_CONTENT_DIR ); $quick_links = array(); foreach ( $quick_dirs as $dir ) { list( $text, $adir ) = $dir; $adir = str_replace( '\\', '/', strtolower( $adir ) ); if ( strlen( $adir ) > 1 ) { $adir = ltrim( $adir, '/' ); } $durl = esc_url( add_query_arg( array( 'dir' => rawurlencode( $adir ) ), $url ) ); $quick_links[] = "$text"; } if ( ! empty( $quick_links ) ) { echo '' . esc_html__( 'Quick Jump:', 'mainwp' ) . ' ' . __( implode( ' | ', $quick_links ) ) . '
'; } $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 { if ( ! MainWP_Helper::isArchive( $file ) ) { $rejected_files[] = $file; } else { $files[] = $file; } } } sort( $directories ); sort( $files ); $parent = dirname( $current_dir ); ?> 'createCloneBackup', 'key' => $key, 'f' => $rand, 'wpversion' => $wp_version, 'zipmethod' => $method, ) ); if ( ! $result['backup'] ) { throw new Exception( __( 'Could not create backupfile on child', 'mainwp-child' ) ); } @session_start(); MainWP_Helper::update_option( 'mainwp_temp_clone_plugins', $result['plugins'] ); MainWP_Helper::update_option( 'mainwp_temp_clone_themes', $result['themes'] ); $output = array( 'url' => $result['backup'], 'size' => round( $result['size'] / 1024, 0 ) ); } catch ( Exception $e ) { $output = array( 'error' => $e->getMessage() ); } die( json_encode( $output ) ); } public static function cloneBackupCreatePoll() { try { if ( ! isset( $_POST['siteId'] ) ) { throw new Exception( __( 'No site given', 'mainwp-child' ) ); } $siteId = $_POST['siteId']; $rand = $_POST['rand']; $sitesToClone = get_option( 'mainwp_child_clone_sites' ); if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) { throw new Exception( __( 'Site not found', 'mainwp-child' ) ); } $siteToClone = $sitesToClone[ $siteId ]; $url = $siteToClone['url']; $key = $siteToClone['extauth']; MainWP_Helper::endSession(); //Send request to the childsite! $result = MainWP_Helper::fetchUrl( $url, array( 'cloneFunc' => 'createCloneBackupPoll', 'key' => $key, 'f' => $rand, ) ); if ( ! isset( $result['size'] ) ) { throw new Exception( __( 'Invalid response', 'mainwp-child' ) ); } $output = array( 'size' => round( $result['size'] / 1024, 0 ) ); } catch ( Exception $e ) { $output = array( 'error' => $e->getMessage() ); } //Return size in kb die( json_encode( $output ) ); } public static function cloneBackupDownload() { try { if ( ! isset( $_POST['file'] ) ) { throw new Exception( __( 'No download link given', 'mainwp-child' ) ); } // if (!isset($_POST['siteId'])) throw new Exception(__('No site given','mainwp-child')); $file = $_POST['file']; if ( isset( $_POST['siteId'] ) ) { $siteId = $_POST['siteId']; $sitesToClone = get_option( 'mainwp_child_clone_sites' ); if ( ! is_array( $sitesToClone ) || ! isset( $sitesToClone[ $siteId ] ) ) { throw new Exception( __( 'Site not found', 'mainwp-child' ) ); } $siteToClone = $sitesToClone[ $siteId ]; $url = $siteToClone['url']; $key = $siteToClone['extauth']; $url = trailingslashit( $url ) . '?cloneFunc=dl&key=' . urlencode( $key ) . '&f=' . $file; } else { $url = $file; } MainWP_Helper::endSession(); //Send request to the childsite! $split = explode( '=', $file ); $file = urldecode( $split[ count( $split ) - 1 ] ); $filename = 'download-' . basename( $file ); $dirs = MainWP_Helper::getMainWPDir( 'backup', false ); $backupdir = $dirs[0]; if ( $dh = opendir( $backupdir ) ) { while ( ( $file = readdir( $dh ) ) !== false ) { if ( '.' !== $file && '..' !== $file && MainWP_Helper::isArchive( $file, 'download-' ) ) { @unlink( $backupdir . $file ); } } closedir( $dh ); } $filename = $backupdir . $filename; $response = wp_remote_get( $url, array( 'timeout' => 300000, 'stream' => true, 'filename' => $filename ) ); if ( is_wp_error( $response ) ) { unlink( $filename ); return $response; } if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { unlink( $filename ); return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) ); } $output = array( 'done' => $filename ); //Delete backup on child 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 ]; MainWP_Helper::fetchUrl( $siteToClone['url'], array( 'cloneFunc' => 'deleteCloneBackup', 'key' => $siteToClone['extauth'], 'f' => $_POST['file'], ) ); } } } catch ( Exception $e ) { throw $e; } } catch ( Exception $e ) { $output = array( 'error' => $e->getMessage() ); } die( json_encode( $output ) ); } public static function cloneBackupDownloadPoll() { try { MainWP_Helper::endSession(); $dirs = MainWP_Helper::getMainWPDir( 'backup', false ); $backupdir = $dirs[0]; $files = glob( $backupdir . 'download-*' ); $archiveFile = false; foreach ( $files as $file ) { if ( MainWP_Helper::isArchive( $file, 'download-' ) ) { $archiveFile = $file; break; } } if ( false === $archiveFile ) { throw new Exception( __( 'No download file found', 'mainwp-child' ) ); } $output = array( 'size' => filesize( $archiveFile ) / 1024 ); } catch ( Exception $e ) { $output = array( 'error' => $e->getMessage() ); } //return size in kb die( json_encode( $output ) ); } public static function cloneBackupExtract() { try { MainWP_Helper::endSession(); $file = ( isset( $_POST['f'] ) ? $_POST['f'] : $_POST['file'] ); $testFull = false; if ( '' === $file ) { $dirs = MainWP_Helper::getMainWPDir( 'backup', false ); $backupdir = $dirs[0]; $files = glob( $backupdir . 'download-*' ); $archiveFile = false; foreach ( $files as $file ) { if ( MainWP_Helper::isArchive( $file, 'download-' ) ) { $archiveFile = $file; break; } } if ( false === $archiveFile ) { throw new Exception( __( 'No download file found', 'mainwp-child' ) ); } $file = $archiveFile; } else if ( 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 size in kb $cloneInstall = new MainWP_Clone_Install( $file ); //todo: RS: refactor to get those plugins after install (after .18 release) $cloneInstall->readConfigurationFile(); $plugins = get_option( 'mainwp_temp_clone_plugins' ); $themes = get_option( 'mainwp_temp_clone_themes' ); if ( $testFull ) { $cloneInstall->testDownload(); } $cloneInstall->removeConfigFile(); $cloneInstall->extractBackup(); $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(); $cloneInstall->updateWPConfig(); // $cloneInstall->update_option('mainwp_child_pubkey', $pubkey); // $cloneInstall->update_option('mainwp_child_uniqueId', $uniqueId); // $cloneInstall->update_option('mainwp_child_server', $server); // $cloneInstall->update_option('mainwp_child_nonce', $nonce); // $cloneInstall->update_option('mainwp_child_nossl', $nossl); // $cloneInstall->update_option('mainwp_child_nossl_key', $nossl_key); // $cloneInstall->update_option('mainwp_child_clone_sites', $sitesToClone); // $cloneInstall->update_option('mainwp_child_clone_permalink', true); 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 ); if ( ! MainWP_Helper::startsWith( basename( $file ), 'download-backup-' ) ) { MainWP_Helper::update_option( 'mainwp_child_restore_permalink', true, 'yes' ); } else { MainWP_Helper::update_option( 'mainwp_child_clone_permalink', true, 'yes' ); } $cloneInstall->clean(); 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 ); } } @closedir( $fh ); } 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 ); } } @closedir( $fh ); } delete_option( 'mainwp_temp_clone_themes' ); } $output = array( 'result' => 'ok' ); //todo: remove old tables if other prefix? wp_logout(); wp_set_current_user( 0 ); } catch ( Exception $e ) { $output = array( 'error' => $e->getMessage() ); } //return size in kb die( json_encode( $output ) ); } public static function permalinkChanged( $action ) { 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' ); } } } public static function permalinkAdminNotice() { if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) || isset( $_POST['tag_base'] ) ) { return; } ?> ' ); } self::renderStyle(); ?>