コード例 #1
0
        function snapshot_admin_show_import_panel()
        {
            //			require( WPMUDEVSnapshot::instance()->get_setting( 'SNAPSHOT_PLUGIN_BASE_DIR' ) . '/lib/snapshot_admin_metaboxes.php' );
            $_snapshot_metaboxes = new Snapshot_View_Metabox_Admin();
            ?>
			<div id="snapshot-settings-metaboxes-general" class="wrap snapshot-wrap">
				<h2><?php 
            _ex("Snapshots Scan / Import", "Snapshot Plugin Page Title", SNAPSHOT_I18N_DOMAIN);
            ?>
</h2>

				<div id="poststuff" class="metabox-holder">
					<div id="post-body" class="">
						<div id="post-body-content" class="snapshot-metabox-holder-main">
							<p><?php 
            _e('The Snapshot import form below is used to import snapshot archives from outside of this environment into view of the snapshot plugin. If you are attempting to restore an archive from a remote server for example you first need to import the archive here. This will then show the archive in the All Snapshots listing. From that page you can then perform the needed restore.', SNAPSHOT_I18N_DOMAIN);
            ?>
</p>

							<form
								action="<?php 
            echo WPMUDEVSnapshot::instance()->get_setting('SNAPSHOT_MENU_URL');
            ?>
snapshots_import_panel"
								method="post">
								<input type="hidden" value="archives-import" name="snapshot-action">
								<?php 
            wp_nonce_field('snapshot-import', 'snapshot-noonce-field');
            ?>

								<?php 
            $_snapshot_metaboxes->snapshot_metaboxes_show_import(__('Import Options', SNAPSHOT_I18N_DOMAIN));
            ?>

								<input id="snapshot-add-button" class="button-primary" type="submit"
								       value="<?php 
            _e('Scan / Import Snapshots', SNAPSHOT_I18N_DOMAIN);
            ?>
"/>
							</form>
						</div>
					</div>
					<?php 
            //echo "_POST<pre>"; print_r($_POST); echo "</pre>";
            //echo "_GET<pre>"; print_r($_GET); echo "</pre>";
            if (isset($_REQUEST['snapshot-action']) && esc_attr($_REQUEST['snapshot-action']) == "archives-import") {
                if (wp_verify_nonce($_POST['snapshot-noonce-field'], 'snapshot-import')) {
                    if (isset($_POST['snapshot-import-archive-remote-url']) && !empty($_POST['snapshot-import-archive-remote-url'])) {
                        //echo "remote url[". $_POST['snapshot-import-archive-remote-url'] ."]<br />";
                        if (substr($_POST['snapshot-import-archive-remote-url'], 0, 4) == 'http') {
                            if (function_exists('curl_version')) {
                                $remoteFile = esc_url_raw($_POST['snapshot-import-archive-remote-url']);
                                @set_time_limit(900);
                                // 15 minutes Technically, server to server should be quick for large files.
                                ?>
<p><?php 
                                _e("PHP max_execution_time", SNAPSHOT_I18N_DOMAIN);
                                ?>
										: <?php 
                                echo ini_get('max_execution_time');
                                ?>
s</p><?php 
                                ?>
<p><?php 
                                _e("Attempting to download remote file", SNAPSHOT_I18N_DOMAIN);
                                ?>
										: <?php 
                                echo $remoteFile;
                                ?>
</p><?php 
                                flush();
                                $restoreFile = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull')) . basename($remoteFile);
                                //echo "remoteFile=[". $remoteFile ."]<br />";
                                //echo "restoreFile=[". $restoreFile ."]<br />";
                                Snapshot_Helper_Utility::remote_url_to_local_file($remoteFile, $restoreFile);
                                if (file_exists($restoreFile)) {
                                    $restoreFolder = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupRestoreFolderFull')) . "_imports";
                                    echo "<ol>";
                                    echo "<li><strong>" . __('Processing archive', SNAPSHOT_I18N_DOMAIN) . ": ", basename($restoreFile) . "</strong> (" . Snapshot_Helper_Utility::size_format(filesize($restoreFile)) . ")<ul><li>";
                                    flush();
                                    $error_status = Snapshot_Helper_Utility::archives_import_proc($restoreFile, $restoreFolder);
                                    //echo "error_status<pre>"; print_r($error_status); echo "</pre>";
                                    if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === true) {
                                        if (isset($error_status['errorText']) && strlen($error_status['errorText'])) {
                                            echo '<span class="snapshot-error">Error: ' . $error_status['errorText'] . '</span></br />';
                                        }
                                    } else {
                                        if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === false) {
                                            if (isset($error_status['responseText']) && strlen($error_status['responseText'])) {
                                                echo '<span class="snapshot-success">Success: ' . $error_status['responseText'] . '</span></br />';
                                            } else {
                                            }
                                        }
                                    }
                                    echo "</li></ul></li>";
                                    echo "</ol>";
                                } else {
                                    echo '<p>' . __('Error: Your server does not have lib_curl installed. So the import process cannot retrieve remote file.', SNAPSHOT_I18N_DOMAIN) . '</p>';
                                }
                            } else {
                                echo "<p>" . __('local import file not found. This could mean either the entered URL was not valid or the file was not publicly accessible.', SNAPSHOT_I18N_DOMAIN) . "</p>";
                            }
                        } else {
                            // Then a local directory
                            // Are we dealing with a absolote path...
                            if (substr($_POST['snapshot-import-archive-remote-url'], 0, 1) == "/") {
                                $dir = trailingslashit(esc_attr($_POST['snapshot-import-archive-remote-url']));
                            } else {
                                $dir = trailingslashit(trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull')) . esc_attr($_POST['snapshot-import-archive-remote-url']));
                            }
                            //echo "dir[". $dir ."]<br />";
                            if (is_dir($dir)) {
                                echo "<p>" . __('Importing archives from', SNAPSHOT_I18N_DOMAIN) . ": " . $dir . "</p>";
                                if ($dh = opendir($dir)) {
                                    $restoreFolder = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupRestoreFolderFull')) . "_imports";
                                    echo "<ol>";
                                    while (($file = readdir($dh)) !== false) {
                                        if ($file == '.' || $file == '..' || $file == 'index.php' || $file[0] == '.') {
                                            continue;
                                        }
                                        if (pathinfo($file, PATHINFO_EXTENSION) != "zip") {
                                            continue;
                                        }
                                        $restoreFile = $dir . $file;
                                        if (is_dir($restoreFile)) {
                                            continue;
                                        }
                                        echo "<li><strong>" . __('Processing archive', SNAPSHOT_I18N_DOMAIN) . ": ", basename($restoreFile) . "</strong> (" . Snapshot_Helper_Utility::size_format(filesize($restoreFile)) . ")<ul><li>";
                                        flush();
                                        $error_status = Snapshot_Helper_Utility::archives_import_proc($restoreFile, $restoreFolder);
                                        //echo "error_status<pre>"; print_r($error_status); echo "</pre>";
                                        if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === true) {
                                            if (isset($error_status['errorText']) && strlen($error_status['errorText'])) {
                                                echo '<span class="snapshot-error">Error: ' . $error_status['errorText'] . '</span></br />';
                                            }
                                        } else {
                                            if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === false) {
                                                if (isset($error_status['responseText']) && strlen($error_status['responseText'])) {
                                                    echo '<span class="snapshot-success">Success: ' . $error_status['responseText'] . '</span></br />';
                                                } else {
                                                }
                                            }
                                        }
                                        echo "</li></ul></li>";
                                    }
                                    echo "</ol>";
                                    closedir($dh);
                                }
                            } else {
                                echo "<p>" . sprintf(__('local import file not found %s. This could mean either the entered path was not valid or accessible.', SNAPSHOT_I18N_DOMAIN), $dir) . "</p>";
                            }
                        }
                    } else {
                        $dir = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull'));
                        echo "<p>" . __('Importing archives from', SNAPSHOT_I18N_DOMAIN) . ": " . $dir . "</p>";
                        if ($dh = opendir($dir)) {
                            $restoreFolder = trailingslashit(WPMUDEVSnapshot::instance()->get_setting('backupRestoreFolderFull')) . "_imports";
                            echo "<ol>";
                            while (($file = readdir($dh)) !== false) {
                                if ($file == '.' || $file == '..' || $file == 'index.php' || $file[0] == '.') {
                                    continue;
                                }
                                if (pathinfo($file, PATHINFO_EXTENSION) != "zip") {
                                    continue;
                                }
                                $restoreFile = $dir . $file;
                                if (is_dir($restoreFile)) {
                                    continue;
                                }
                                echo "<li><strong>" . __('Processing archive', SNAPSHOT_I18N_DOMAIN) . ": ", basename($restoreFile) . "</strong> (" . Snapshot_Helper_Utility::size_format(filesize($restoreFile)) . ")<ul><li>";
                                flush();
                                $error_status = Snapshot_Helper_Utility::archives_import_proc($restoreFile, $restoreFolder);
                                //echo "error_status<pre>"; print_r($error_status); echo "</pre>";
                                if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === true) {
                                    if (isset($error_status['errorText']) && strlen($error_status['errorText'])) {
                                        echo '<span class="snapshot-error">Error: ' . $error_status['errorText'] . '</span></br />';
                                    }
                                } else {
                                    if (isset($error_status['errorStatus']) && $error_status['errorStatus'] === false) {
                                        if (isset($error_status['responseText']) && strlen($error_status['responseText'])) {
                                            echo '<span class="snapshot-success">Success: ' . $error_status['responseText'] . '</span></br />';
                                        } else {
                                        }
                                    }
                                }
                                echo "</li></ul></li>";
                            }
                            echo "</ol>";
                            closedir($dh);
                        }
                    }
                }
                echo "<p>" . __('Snapshot import complete', SNAPSHOT_I18N_DOMAIN) . "</p>";
            }
            ?>
				</div>
			</div>
		<?php 
        }