Пример #1
0
    public static function render()
    {
        $uploadError = false;
        $uploadFile = false;
        if (isset($_REQUEST['upload'])) {
            if (isset($_FILES['file'])) {
                if (!function_exists('wp_handle_upload')) {
                    require_once ABSPATH . 'wp-admin/includes/file.php';
                }
                $uploadedfile = $_FILES['file'];
                $upload_overrides = array('test_form' => false);
                add_filter('upload_mimes', array('MainWP_Clone', 'upload_mimes'));
                $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);
        self::renderHeader();
        ?>
        <div id="icon-options-general" class="icon32"><br></div>
		<h2><?php 
        esc_html_e('Clone or Restore', 'mainwp-child');
        ?>
</h2><?php 
        if ('0' === $sitesToClone) {
            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 Migrate/Clone page.', 'mainwp-child') . '</strong></div>';
            return;
        }
        $error = false;
        MainWP_Helper::getWPFilesystem();
        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;
        }
        ?>
        <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');
        ?>
        </div>

		<?php 
        if ($uploadFile) {
            esc_html_e('Upload successful.', 'mainwp-child');
            ?>
 <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 
        } else {
            if ($uploadError) {
                ?>
				<div class="mainwp-child_info-box-red"><?php 
                echo esc_html($uploadError);
                ?>
</div><?php 
            }
            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 Migrate/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><?php 
                esc_html_e('Clone Options', 'mainwp-child');
                ?>
</h2>

                            <div class="inside">
                                <div id="mainwp-child_clonesite_select_site">
									<?php 
                foreach ($sitesToClone as $siteId => $siteToClone) {
                    ?>
										<div class="clonesite_select_site_item" id="<?php 
                    echo esc_attr($siteId);
                    ?>
"
										     rand="<?php 
                    echo esc_attr(MainWP_Helper::randString(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::getNiceURL($siteToClone['url']));
                    ?>
</div>
                                        </div>
										<?php 
                }
                ?>
                                </div>
                            </div>
							<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>
                        </div>
                    </div>
                </form>
                <br/>
				<?php 
            }
            $sitesToClone = get_option('mainwp_child_clone_sites');
            ?>
            <div id="icon-options-general" class="icon32"><br></div><h2>
				<strong><?php 
            esc_html_e('Option 1:', 'mainwp-child');
            ?>
</strong> <?php 
            esc_html_e('Restore/Clone From Backup', 'mainwp-child');
            ?>
            </h2>
            <br/>
            <div
				class="mainwp-child_info-box-green"><?php 
            esc_html_e('Upload backup in .zip format (Maximum filesize for your server settings: ', 'mainwp-child');
            echo esc_html($uploadSize);
            ?>
                )
            </div>
			<i><?php 
            esc_html_e('If you have a FULL backup created by your Network dashboard you may restore it by uploading here.', 'mainwp-child');
            ?>
                <br/>
				<?php 
            esc_html_e('A database only backup will not work.', 'mainwp-child');
            ?>
</i><br/><br/>
            <form
				action="<?php 
            echo esc_attr(admin_url('admin.php?page=' . (0 !== $sitesToClone ? 'MainWP_Clone' : 'MainWPRestore') . '&upload=yes'));
            ?>
"
                method="post" enctype="multipart/form-data"><input type="file" name="file" id="file"/> <input
                    type="submit" name="submit" id="filesubmit" disabled="disabled"
					value="<?php 
            esc_attr_e('Clone/Restore Website', 'mainwp-child');
            ?>
"/></form>
			<?php 
        }
        self::renderCloneFromServer();
        self::renderJavaScript();
    }