コード例 #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('MainWPClone', '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(MainWPHelper::return_bytes(ini_get('upload_max_filesize')), MainWPHelper::return_bytes(ini_get('post_max_size')));
        $uploadSize = MainWPHelper::human_filesize($uploadSizeInBytes);
        self::renderHeader();
        ?>
<div id="icon-options-general" class="icon32"><br></div><h2><?php 
        _e('Clone or Restore', 'mainwp-child');
        ?>
</h2><?php 
        if ($sitesToClone == '0') {
            echo '<div class="mainwp-child_info-box-red"><strong>' . __('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;
        MainWPHelper::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>' . __('Your content directory is not writable. Please set 0755 permission to ', 'mainwp-child') . basename(WP_CONTENT_DIR) . '. (' . WP_CONTENT_DIR . ')</strong></div>';
            $error = true;
        }
        ?>
    <div class="mainwp-child_info-box-green" style="display: none;"><?php 
        _e('Cloning process completed successfully! You will now need to click ', 'mainwp-child');
        ?>
 <a href="<?php 
        echo admin_url('options-permalink.php');
        ?>
"><?php 
        _e('here', 'mainwp-child');
        ?>
</a><?php 
        _e(' to re-login to the admin and re-save permalinks.', 'mainwp-child');
        ?>
</div>

    <?php 
        if ($uploadFile) {
            _e('Upload successful.', 'mainwp-child');
            ?>
 <a href="#" id="mainwp-child_uploadclonebutton" class="button-primary" file="<?php 
            echo $uploadFile;
            ?>
"><?php 
            _e('Clone/Restore Website', 'mainwp-child');
            ?>
</a><?php 
        } else {
            if ($uploadError) {
                ?>
<div class="mainwp-child_info-box-red"><?php 
                echo $uploadError;
                ?>
</div><?php 
            }
            if (empty($sitesToClone)) {
                echo '<div class="mainwp-child_info-box-yellow"><strong>' . __('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 
                _e('Display by:', 'mainwp-child');
                ?>
 <a class="mainwp-child_action left mainwp-child_action_down" href="#" id="mainwp-child_displayby_sitename"><?php 
                _e('Site Name', 'mainwp-child');
                ?>
</a><a class="mainwp-child_action right" href="#" id="mainwp-child_displayby_url"><?php 
                _e('URL', 'mainwp-child');
                ?>
</a></div><h2><?php 
                _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 $siteId;
                    ?>
" rand="<?php 
                    echo MainWPHelper::randString(5);
                    ?>
">
                                <div class="mainwp-child_size_label" size="<?php 
                    echo $siteToClone['size'];
                    ?>
"><?php 
                    echo $siteToClone['size'];
                    ?>
 MB</div>
                                <div class="mainwp-child_name_label"><?php 
                    echo $siteToClone['name'];
                    ?>
</div>
                                <div class="mainwp-child_url_label"><?php 
                    echo MainWPHelper::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 
                    _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 
            _e('Option 1:', 'mainwp-child');
            ?>
</strong> <?php 
            _e('Restore/Clone From Backup', 'mainwp-child');
            ?>
</h2>
        <br />
    <div class="mainwp-child_info-box-green"><?php 
            _e('Upload backup in .zip format (Maximum filesize for your server settings: ', 'mainwp-child');
            echo $uploadSize;
            ?>
)</div>
    <i><?php 
            _e('If you have a FULL backup created by your Network dashboard you may restore it by uploading here.', 'mainwp-child');
            ?>
<br />
    <?php 
            _e('A database only backup will not work.', 'mainwp-child');
            ?>
</i><br /><br />
    <form action="<?php 
            echo admin_url('admin.php?page=' . ($sitesToClone != '0' ? 'MainWPClone' : '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 
            _e('Clone/Restore Website', 'mainwp-child');
            ?>
" /></form>
        <?php 
        }
        self::renderCloneFromServer();
        self::renderJavaScript();
    }