/**
         * Panel showing form to restore previous Snapshot.
         *
         * @since 1.0.2
         * @uses metaboxes setup in $this->admin_menu_proc()
         * @uses $_REQUEST['item']
         * @uses $this->config_data['items']
         *
         * @param none
         *
         * @return none
         */
        function snapshot_admin_show_restore_panel($item)
        {
            //			require( WPMUDEVSnapshot::instance()->get_setting( 'SNAPSHOT_PLUGIN_BASE_DIR' ) . '/lib/snapshot_admin_metaboxes.php' );
            $this->_snapshot_metaboxes = new Snapshot_View_Metabox_Admin();
            if (isset($_GET['snapshot-data-item']) && isset($item['data'][intval($_GET['snapshot-data-item'])])) {
                $data_item_key = intval($_GET['snapshot-data-item']);
                ?>
				<div id="snapshot-settings-metaboxes-general" class="wrap snapshot-wrap">
					<h2><?php 
                _ex("Restore Snapshot", "Snapshot Plugin Page Title", SNAPSHOT_I18N_DOMAIN);
                ?>
</h2>

					<p class="snapshot-restore-description"><?php 
                _ex("On this page you can restore a previous snapshot. Using the 'Restore Options' section below you can also opt to turn off all plugins as well as switch to a different theme as part of the restore.", 'Snapshot page description', SNAPSHOT_I18N_DOMAIN);
                ?>
</p>

					<div id='snapshot-ajax-warning' class='updated fade'>
						<p><?php 
                _e('You are about to restore a previous version of your WordPress database. This will remove any new information added since the snapshot backup.', SNAPSHOT_I18N_DOMAIN);
                ?>
</p>
					</div>

					<?php 
                if (!Snapshot_Helper_Utility::check_server_timeout()) {
                    $current_timeout = ini_get('max_execution_time');
                    ?>
						<div class='error snapshot-error'>
						<p><?php 
                    printf(__('Your web server timeout is set very low, %d seconds. Also, it appears this timeout cannot be adjusted via the Snapshot restore process. Attempting a snapshot restore could result in a partial restore of your tables.', SNAPSHOT_I18N_DOMAIN), $current_timeout);
                    ?>
</p>
						</div><?php 
                }
                ?>
					<?php 
                Snapshot_Helper_UI::form_ajax_panels();
                ?>
					<?php 
                if (isset($_GET['snapshot-data-item'])) {
                    $data_item = $item['data'][$_GET['snapshot-data-item']];
                }
                $backupFolder = WPMUDEVSnapshot::instance()->snapshot_get_item_destination_path($item, $data_item);
                if (empty($backupFolder)) {
                    $backupFolder = WPMUDEVSnapshot::instance()->get_setting('backupBaseFolderFull');
                }
                if (isset($data_item['filename']) && strlen($data_item['filename'])) {
                    $manifest_filename = Snapshot_Helper_Utility::extract_archive_manifest(trailingslashit($backupFolder) . $data_item['filename']);
                    if ($manifest_filename) {
                        //echo "manifest_filename=[". $manifest_filename ."]<br />";
                        $manifest_data = Snapshot_Helper_Utility::consume_archive_manifest($manifest_filename);
                        if ($manifest_data) {
                            //echo "manifest_data<pre>"; print_r($manifest_data); echo "</pre>";
                            $item['MANIFEST'] = $manifest_data;
                        }
                    }
                }
                ?>


					<div id="poststuff" class="metabox-holder">

						<form id="snapshot-edit-restore" action="<?php 
                echo WPMUDEVSnapshot::instance()->get_setting('SNAPSHOT_MENU_URL');
                ?>
snapshots_edit_panel"
						      method="post">
							<input type="hidden" name="snapshot-action" value="restore-request"/>
							<input type="hidden" name="item" value="<?php 
                echo $item['timestamp'];
                ?>
"/>
							<?php 
                wp_nonce_field('snapshot-restore', 'snapshot-noonce-field');
                ?>

							<?php 
                $this->_snapshot_metaboxes->snapshot_metaboxes_show_item_header_information(__('Snapshot Information', SNAPSHOT_I18N_DOMAIN), $item, true);
                ?>

							<?php 
                $this->_snapshot_metaboxes->snapshot_metabox_show_archive_files(__('Selected Archive to Restore', SNAPSHOT_I18N_DOMAIN), $item, true);
                ?>
							<?php 
                //if (is_multisite()) {
                $this->_snapshot_metaboxes->snapshot_metabox_restore_blog_options(__('Restore Blog Options', SNAPSHOT_I18N_DOMAIN), $item);
                //}
                ?>
							<?php 
                $this->_snapshot_metaboxes->snapshot_metabox_show_restore_tables_options(__('What Tables to Restore?', SNAPSHOT_I18N_DOMAIN), $item, $data_item_key);
                ?>
							<?php 
                $this->_snapshot_metaboxes->snapshot_metabox_show_restore_files_options(__('What Files to Restore?', SNAPSHOT_I18N_DOMAIN), $item, $data_item_key);
                ?>
							<?php 
                $this->_snapshot_metaboxes->snapshot_metabox_restore_options(__('Restore Theme Options', SNAPSHOT_I18N_DOMAIN), $item);
                ?>
							<input id="snapshot-form-restore-submit" class="button-primary"
								<?php 
                if (!$data_item_key) {
                    ?>
 disabled="disabled" <?php 
                }
                ?>
								   type="submit" value="<?php 
                _e('Restore Snapshot', SNAPSHOT_I18N_DOMAIN);
                ?>
"/>
							<a class="button-secondary"
							   href="<?php 
                echo WPMUDEVSnapshot::instance()->get_setting('SNAPSHOT_MENU_URL');
                ?>
									snapshots_edit_panel"><?php 
                _e('Cancel', SNAPSHOT_I18N_DOMAIN);
                ?>
</a>
						</form>
					</div>
				</div>
			<?php 
            } else {
                ?>
				<div id="snapshot-settings-metaboxes-general" class="wrap snapshot-wrap">
					<h2><?php 
                _ex("Restore Snapshot", "Snapshot Plugin Page Title", SNAPSHOT_I18N_DOMAIN);
                ?>
</h2>

					<p class="snapshot-restore-description"><?php 
                _ex("ERROR: Missing argument. Please return to the main Snapshot panel and select the archive to restore. ", 'Snapshot page description', SNAPSHOT_I18N_DOMAIN);
                ?>
						<a href="?page=snapshots_edit_panel">Snapshot</a>.</p>
				</div>
			<?php 
            }
        }
 /**
  * AJAX callback function from the snapshot restore form. This is the first
  * step of the restore. This step will unzip the archive and retrieve the
  * the MANIFEST file content.
  *
  * @since 1.0.2
  * @see
  *
  * @param none
  *
  * @return JSON formatted array status.
  */
 function snapshot_ajax_restore_init($item)
 {
     global $wpdb, $current_blog;
     $error_status = array();
     $error_status['errorStatus'] = false;
     $error_status['errorText'] = "";
     $error_status['responseText'] = "";
     $home_path = apply_filters('snapshot_home_path', get_home_path());
     if (!isset($_POST['item_data'])) {
         $error_status['errorStatus'] = true;
         $error_status['errorText'] = "<p>" . __("ERROR: The Snapshot missing 'item_data' key", SNAPSHOT_I18N_DOMAIN) . "</p>";
         return $error_status;
     }
     $item_data = intval($_POST['item_data']);
     if (!isset($item['data'][$item_data])) {
         $error_status['errorStatus'] = true;
         $error_status['errorText'] = "<p>" . __("ERROR: The Snapshot incorrect 'item_data' [" . $item_data . "] key", SNAPSHOT_I18N_DOMAIN) . "</p>";
         return $error_status;
     }
     //$error_status['data'] = $item['data'];
     $data_item = $item['data'][$item_data];
     //echo "data_item<pre>"; print_r($data_item); echo "</pre>";
     $backupZipFolder = $this->snapshot_get_item_destination_path($item, $data_item, false);
     //echo "backupZipFolder[". $backupZipFolder ."]<br />";
     //die();
     $restoreFile = trailingslashit($backupZipFolder) . $data_item['filename'];
     $error_status['restoreFile'] = $restoreFile;
     if (!file_exists($restoreFile)) {
         $error_status_errorText = "<p>" . __("ERROR: The Snapshot file not found:", SNAPSHOT_I18N_DOMAIN) . " " . $restoreFile . "</p>";
         $restoreFile = trailingslashit($this->_settings['backupBaseFolderFull']) . $data_item['filename'];
         $error_status['restoreFile'] = $restoreFile;
         if (!file_exists($restoreFile)) {
             $error_status['errorStatus'] = true;
             $error_status['errorText'] = $error_status_errorText . "<p>" . __("ERROR: The Snapshot file not found:", SNAPSHOT_I18N_DOMAIN) . " " . $restoreFile . "</p>";
             return $error_status;
         }
     }
     // Create a unique folder for our restore processing. Will later need to remove it.
     $sessionRestoreFolder = trailingslashit($this->_settings['backupRestoreFolderFull']);
     wp_mkdir_p($sessionRestoreFolder);
     if (!is_writable($sessionRestoreFolder)) {
         $error_status['errorStatus'] = true;
         $error_status['errorText'] = "<p>" . __("ERROR: The Snapshot folder is not writeable. Check the settings", SNAPSHOT_I18N_DOMAIN) . " " . $sessionRestoreFolder . "</p>";
         return $error_status;
     }
     // Cleanup any files from a previous restore attempt
     if ($dh = opendir($sessionRestoreFolder)) {
         while (($file = readdir($dh)) !== false) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             Snapshot_Helper_Utility::recursive_rmdir($sessionRestoreFolder . $file);
         }
         closedir($dh);
     }
     if ($this->config_data['config']['zipLibrary'] == "PclZip") {
         if (!defined('PCLZIP_TEMPORARY_DIR')) {
             define('PCLZIP_TEMPORARY_DIR', trailingslashit($this->_settings['backupBackupFolderFull']) . $item['timestamp'] . "/");
         }
         if (!class_exists('class PclZip')) {
             require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
         }
         $zipArchive = new PclZip($restoreFile);
         $zip_contents = $zipArchive->listContent();
         if ($zip_contents) {
             $extract_files = $zipArchive->extract(PCLZIP_OPT_PATH, $sessionRestoreFolder);
             if ($extract_files) {
                 $this->_session->data['restoreFolder'] = $sessionRestoreFolder;
             }
         }
     } else {
         $zip = new ZipArchive();
         $res = $zip->open($restoreFile);
         if ($res === true) {
             $extract_ret = $zip->extractTo($sessionRestoreFolder);
             if ($extract_ret !== false) {
                 $this->_session->data['restoreFolder'] = $sessionRestoreFolder;
             }
         }
     }
     $error_status['MANIFEST'] = array();
     $snapshot_manifest_file = trailingslashit($sessionRestoreFolder) . 'snapshot_manifest.txt';
     if (file_exists($snapshot_manifest_file)) {
         $error_status['MANIFEST'] = Snapshot_Helper_Utility::consume_archive_manifest($snapshot_manifest_file);
         //unlink($snapshot_manifest_file);
     }
     if (isset($error_status['MANIFEST']['SNAPSHOT_VERSION'])) {
         if ($error_status['MANIFEST']['SNAPSHOT_VERSION'] == "1.0" && !isset($error_status['MANIFEST']['TABLES-DATA'])) {
             $backupFile = trailingslashit($sessionRestoreFolder) . 'snapshot_backups.sql';
             $table_segments = Snapshot_Helper_Utility::get_table_segments_from_single($backupFile);
             if ($table_segments) {
                 $error_status['MANIFEST']['TABLES-DATA'] = $table_segments;
                 unlink($backupFile);
             }
         }
     }
     if (is_multisite()) {
         //echo "item<pre>"; print_r($item); echo "</pre>";
         //echo "error_status<pre>"; print_r($error_status); echo "</pre>";
         //echo "_POST<pre>"; print_r($_POST); echo "</pre>";
         //switch_to_blog( $item['blog-id'] );
         $error_status['MANIFEST']['RESTORE']['SOURCE'] = array();
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_BLOG_ID'] = $error_status['MANIFEST']['WP_BLOG_ID'];
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_PREFIX'] = $error_status['MANIFEST']['WP_DB_PREFIX'];
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_BASE_PREFIX'] = $error_status['MANIFEST']['WP_DB_BASE_PREFIX'];
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_SITEURL'] = $error_status['MANIFEST']['WP_SITEURL'];
         $error_status['MANIFEST']['RESTORE']['SOURCE']['UPLOAD_DIR'] = $error_status['MANIFEST']['WP_UPLOAD_PATH'];
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_UPLOAD_URLS'] = $error_status['MANIFEST']['WP_UPLOAD_URLS'];
         switch_to_blog($_POST['snapshot-blog-id']);
         $error_status['MANIFEST']['RESTORE']['DEST'] = array();
         $error_status['MANIFEST']['RESTORE']['DEST']['WP_BLOG_ID'] = $_POST['snapshot-blog-id'];
         $error_status['MANIFEST']['RESTORE']['DEST']['WP_DB_PREFIX'] = $wpdb->get_blog_prefix($_POST['snapshot-blog-id']);
         $error_status['MANIFEST']['RESTORE']['DEST']['WP_DB_BASE_PREFIX'] = $wpdb->base_prefix;
         $error_status['MANIFEST']['RESTORE']['DEST']['WP_SITEURL'] = get_site_url($_POST['snapshot-blog-id']);
         if (empty($error_status['MANIFEST']['RESTORE']['DEST']['WP_SITEURL'])) {
             if (!empty($_POST['snapshot_blog_search'])) {
                 $error_status['MANIFEST']['RESTORE']['DEST']['WP_SITEURL'] = network_site_url('/' . untrailingslashit($_POST['snapshot_blog_search']) . '/');
             } else {
                 $error_status['MANIFEST']['RESTORE']['DEST']['WP_SITEURL'] = $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_SITEURL'];
             }
         }
         $wp_upload_dir = wp_upload_dir();
         //echo "wp_upload_dir<pre>"; print_r($wp_upload_dir); echo "</pre>";
         //die();
         $wp_upload_dir['basedir'] = str_replace('\\', '/', $wp_upload_dir['basedir']);
         $error_status['MANIFEST']['RESTORE']['DEST']['UPLOAD_DIR'] = str_replace($home_path, '', $wp_upload_dir['basedir']);
         //echo "error_status<pre>"; print_r($error_status); echo "</pre>";
         //die();
     } else {
         $error_status['MANIFEST']['RESTORE']['SOURCE'] = array();
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_BLOG_ID'] = $error_status['MANIFEST']['WP_BLOG_ID'];
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_PREFIX'] = $error_status['MANIFEST']['WP_DB_PREFIX'];
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_BASE_PREFIX'] = $error_status['MANIFEST']['WP_DB_BASE_PREFIX'];
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_SITEURL'] = $error_status['MANIFEST']['WP_SITEURL'];
         $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_UPLOAD_URLS'] = $error_status['MANIFEST']['WP_UPLOAD_URLS'];
         $wp_upload_dir = wp_upload_dir();
         $wp_upload_dir['basedir'] = str_replace('\\', '/', $wp_upload_dir['basedir']);
         $error_status['MANIFEST']['RESTORE']['SOURCE']['UPLOAD_DIR'] = $wp_upload_dir['basedir'];
         $error_status['MANIFEST']['RESTORE']['DEST'] = array();
         $error_status['MANIFEST']['RESTORE']['DEST']['WP_BLOG_ID'] = $error_status['MANIFEST']['WP_BLOG_ID'];
         $error_status['MANIFEST']['RESTORE']['DEST']['WP_DB_PREFIX'] = $wpdb->prefix;
         $error_status['MANIFEST']['RESTORE']['DEST']['WP_DB_BASE_PREFIX'] = $wpdb->base_prefix;
         $error_status['MANIFEST']['RESTORE']['DEST']['WP_SITEURL'] = get_site_url($error_status['MANIFEST']['WP_BLOG_ID']);
         if (empty($error_status['MANIFEST']['RESTORE']['DEST']['WP_SITEURL'])) {
             $error_status['MANIFEST']['RESTORE']['DEST']['WP_SITEURL'] = $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_SITEURL'];
         }
         $error_status['MANIFEST']['RESTORE']['DEST']['UPLOAD_DIR'] = $error_status['MANIFEST']['RESTORE']['SOURCE']['UPLOAD_DIR'];
     }
     if (!isset($_POST['snapshot-tables-option'])) {
         $_POST['snapshot-tables-option'] = "none";
     }
     if ($_POST['snapshot-tables-option'] == "none") {
         unset($error_status['MANIFEST']['TABLES']);
         $error_status['MANIFEST']['TABLES'] = array();
     } else {
         if ($_POST['snapshot-tables-option'] == "selected") {
             if (isset($_POST['snapshot-tables-array'])) {
                 $error_status['MANIFEST']['TABLES'] = $_POST['snapshot-tables-array'];
             }
         } else {
             if ($_POST['snapshot-tables-option'] == "all") {
                 $manifest_tables = array();
                 foreach ($error_status['MANIFEST']['TABLES'] as $table_set_key => $table_set) {
                     // Per the instructions on the page. When selecting 'all' we do not include the global tables: users and usermeta
                     if ($table_set_key == 'global') {
                         continue;
                     }
                     $manifest_tables = array_merge($manifest_tables, array_values($table_set));
                 }
                 //echo "manifest_tables<pre>"; print_r($manifest_tables); echo "</pre>";
                 //die();
                 $error_status['MANIFEST']['TABLES'] = $manifest_tables;
             }
         }
     }
     //echo "RESTORE<pre>"; print_r($error_status['MANIFEST']['RESTORE']); echo "</pre>";
     //echo "TABLES<pre>"; print_r($error_status['MANIFEST']['TABLES']); echo "</pre>";
     //echo "MANIFEST<pre>"; print_r($error_status['MANIFEST']); echo "</pre>";
     //echo "wpdb<pre>"; print_r($wpdb); echo "</pre>";
     //die();
     // upload_path wp-content/blogs.dir/7/files
     if (isset($error_status['MANIFEST']['TABLES']) && count($error_status['MANIFEST']['TABLES'])) {
         $tables_array = array();
         foreach ($error_status['MANIFEST']['TABLES'] as $table_name) {
             $table_info = array();
             $table_info['table_name'] = $table_name;
             if (strncasecmp($table_name, $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_PREFIX'], strlen($error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_PREFIX'])) == 0) {
                 $table_info['table_name_base'] = str_replace($error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_PREFIX'], '', $table_name);
                 $table_info['table_name_restore'] = $this->_settings['recover_table_prefix'] . str_replace($error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_PREFIX'], $error_status['MANIFEST']['RESTORE']['DEST']['WP_DB_PREFIX'], $table_name);
                 $table_name_dest = str_replace($error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_PREFIX'], $error_status['MANIFEST']['RESTORE']['DEST']['WP_DB_PREFIX'], $table_name);
             } else {
                 if (strncasecmp($table_name, $error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_BASE_PREFIX'], strlen($error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_BASE_PREFIX'])) == 0) {
                     $table_info['table_name_base'] = str_replace($error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_BASE_PREFIX'], '', $table_name);
                     $table_info['table_name_restore'] = $this->_settings['recover_table_prefix'] . str_replace($error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_BASE_PREFIX'], $error_status['MANIFEST']['RESTORE']['DEST']['WP_DB_BASE_PREFIX'], $table_name);
                     $table_name_dest = str_replace($error_status['MANIFEST']['RESTORE']['SOURCE']['WP_DB_BASE_PREFIX'], $error_status['MANIFEST']['RESTORE']['DEST']['WP_DB_BASE_PREFIX'], $table_name);
                 } else {
                     // If the table name is not using the DB_PREFIX or DB_BASE_PREFIX then don't convert it.
                     $table_info['table_name_base'] = $table_name;
                     $table_info['table_name_restore'] = $table_name;
                     $table_name_dest = $table_name;
                 }
             }
             $table_info['label'] = $table_name . " > " . $table_name_dest;
             $table_info['table_name_dest'] = $table_name_dest;
             $tables_array[$table_name] = $table_info;
         }
         $error_status['MANIFEST']['TABLES'] = $tables_array;
         //echo "MANIFEST<pre>"; print_r($error_status['MANIFEST']['TABLES']); echo "</pre>";
         //die();
     }
     if (isset($error_status['MANIFEST']['TABLES-DATA']) && count($error_status['MANIFEST']['TABLES-DATA'])) {
         $tables_data_sets = array();
         foreach ($error_status['MANIFEST']['TABLES-DATA'] as $table_set) {
             if (!isset($table_set['table_name'])) {
                 continue;
             }
             //echo "table_set table_name[". $table_set['table_name'] ."]<br />";
             if (array_key_exists($table_set['table_name'], $error_status['MANIFEST']['TABLES']) !== false) {
                 $tables_data_sets[] = $table_set;
             } else {
                 //echo "Table[". $table_set['table_name'] ."] not found in tables<br />";
             }
         }
         $error_status['MANIFEST']['TABLES-DATA'] = $tables_data_sets;
     }
     //echo "MANIFEST<pre>"; print_r($error_status['MANIFEST']['TABLES']); echo "</pre>";
     //echo "MANIFEST<pre>"; print_r($error_status['MANIFEST']['TABLES-DATA']); echo "</pre>";
     //die();
     if (!isset($_POST['snapshot-files-option'])) {
         $_POST['snapshot-files-option'] = "none";
     }
     if ($_POST['snapshot-files-option'] == "none") {
         unset($error_status['MANIFEST']['FILES-DATA']);
         $error_status['MANIFEST']['FILES-DATA'] = array();
     } else {
         if ($_POST['snapshot-files-option'] == "selected") {
             if (isset($_POST['snapshot-files-sections'])) {
                 $error_status['MANIFEST']['FILES-DATA'] = $_POST['snapshot-files-sections'];
             }
         } else {
             if ($_POST['snapshot-files-option'] == "all") {
                 if (isset($error_status['MANIFEST']['ITEM']['data'])) {
                     $data_item = Snapshot_Helper_Utility::latest_data_item($error_status['MANIFEST']['ITEM']['data']);
                     if (isset($data_item['files-sections'])) {
                         $error_status['MANIFEST']['FILES-DATA'] = array_values($data_item['files-sections']);
                         $array_idx = array_search('config', $error_status['MANIFEST']['FILES-DATA']);
                         if ($array_idx !== false) {
                             unset($error_status['MANIFEST']['FILES-DATA'][$array_idx]);
                         }
                         $array_idx = array_search('htaccess', $error_status['MANIFEST']['FILES-DATA']);
                         if ($array_idx !== false) {
                             unset($error_status['MANIFEST']['FILES-DATA'][$array_idx]);
                         }
                     }
                 }
             }
         }
     }
     //echo "_POST<pre>"; print_r($_POST); echo "</pre>";
     //echo "MANIFEST<pre>"; print_r($error_status['MANIFEST']); echo "</pre>";
     //echo "MANIFEST RESTORE<pre>"; print_r($error_status['MANIFEST']['RESTORE']); echo "</pre>";
     //die();
     $this->_session->data['MANIFEST'] = $error_status['MANIFEST'];
     return $error_status;
 }
 public static function validate_step_1($restore_form)
 {
     $form_errors = array();
     $form_errors['form'] = array();
     $form_errors['message-error'] = array();
     $form_errors['message-success'] = array();
     // Do the form validation first before the heavy processing
     if (!isset($restore_form['snapshot']['archive-file']) || !strlen($restore_form['snapshot']['archive-file'])) {
         $form_errors['form']['snapshot']['archive-file'] = "Snapshot Archive file cannot be empty.";
     } else {
         $_SESSION['restore_form']['snapshot']['archive-file'] = $restore_form['snapshot']['archive-file'];
     }
     if (!isset($restore_form['wordpress']['reload']) || !strlen($restore_form['wordpress']['reload'])) {
         $form_errors['form']['wordpress']['reload'] = "WordPress Reload cannot be empty.";
     } else {
         if ($restore_form['wordpress']['reload'] != "yes" && $restore_form['wordpress']['reload'] != "no") {
             $form_errors['form']['wordpress']['reload'] = "WordPress Reload invalid value given.";
             return $form_errors;
         } else {
             $_SESSION['restore_form']['wordpress']['reload'] = $restore_form['wordpress']['reload'];
         }
     }
     if (!isset($restore_form['wordpress']['install-path']) || !strlen($restore_form['wordpress']['install-path'])) {
         $form_errors['form']['wordpress']['install-path'] = "WordPress Install Path file cannot be empty.";
     } else {
         $_SESSION['restore_form']['wordpress']['install-path'] = self::untrailingslashit_snapshot($restore_form['wordpress']['install-path']);
         if (!file_exists($_SESSION['restore_form']['wordpress']['install-path'])) {
             mkdir($_SESSION['restore_form']['wordpress']['install-path'], 0777, true);
         }
         $_SESSION['restore_form']['wordpress']['install-path'] = self::trailingslashit_snapshot($_SESSION['restore_form']['wordpress']['install-path']);
     }
     if (count($form_errors['form'])) {
         return $form_errors;
     }
     // If here then the form is valid. Now get into the heavy processing
     if (!isset($_SESSION['restore_form']['snapshot']['archive-file'])) {
         $_SESSION['restore_form']['snapshot']['archive-file'] = '';
     }
     unset($_SESSION['restore_form']['snapshot']['archive-file-local']);
     unset($_SESSION['restore_form']['snapshot']['archive-file-remote']);
     if (substr($_SESSION['restore_form']['snapshot']['archive-file'], 0, strlen('http')) == "http") {
         $_SESSION['restore_form']['snapshot']['archive-file-remote'] = $_SESSION['restore_form']['snapshot']['archive-file'];
         $_SESSION['restore_form']['snapshot']['archive-file-local'] = dirname(__FILE__) . "/_snapshot/file/" . basename($_SESSION['restore_form']['snapshot']['archive-file']);
         if (file_exists($_SESSION['restore_form']['snapshot']['archive-file-local'])) {
             $unlink_ret = unlink($_SESSION['restore_form']['snapshot']['archive-file-local']);
             if ($unlink_ret !== true) {
                 $form_errors['message-error'][] = "Unable to delete previous local file [" . $_SESSION['restore_form']['snapshot']['archive-file-local'] . "]. Manually delete the file. Check parent folder permissions and reload the page.";
                 return $form_errors;
             }
         }
         $func_ret = Snapshot_Helper_Utility::remote_url_to_local_file($_SESSION['restore_form']['snapshot']['archive-file-remote'], $_SESSION['restore_form']['snapshot']['archive-file-local']);
         if (!file_exists($_SESSION['restore_form']['snapshot']['archive-file-local']) || !filesize($_SESSION['restore_form']['snapshot']['archive-file-local'])) {
             $form_errors['message-error'][] = "Attempted to download remote Snapshot file to local [" . $_SESSION['restore_form']['snapshot']['archive-file-local'] . "]<br />";
             ". File not found or is empty. Check parent folder permissions and reload the page.";
             return $form_errors;
         } else {
             $form_errors['message-success'][] = "Remote Snapshot Archive [" . $_SESSION['restore_form']['snapshot']['archive-file-remote'] . "] downloaded and extracted successfully.";
         }
     } else {
         $local_file = '';
         if (substr($_SESSION['restore_form']['snapshot']['archive-file'], 0, 1) == "/") {
             $local_file = $_SESSION['restore_form']['snapshot']['archive-file'];
         } else {
             $local_file = self::trailingslashit_snapshot($_SERVER['DOCUMENT_ROOT']) . $_SESSION['restore_form']['snapshot']['archive-file'];
         }
         if (file_exists($local_file)) {
             $_SESSION['restore_form']['snapshot']['archive-file-local'] = $local_file;
             $form_errors['message-success'][] = "Local Snapshot Archive located [" . basename($local_file) . "] successfully.";
         }
     }
     if (isset($_SESSION['restore_form']['snapshot']['archive-file-local']) && strlen($_SESSION['restore_form']['snapshot']['archive-file-local'])) {
         /**
          * THIS IS WHERE THE RECOVERY BEGINS.
          */
         $_SESSION['restore_form']['snapshot']['extract-path'] = WP_CONTENT_DIR . "/_snapshot_recovery/extract/";
         self::unzip_archive($_SESSION['restore_form']['snapshot']['archive-file-local'], $_SESSION['restore_form']['snapshot']['extract-path']);
         // Locate and consume the Snapshot manifest file
         $_SESSION['restore_form']['snapshot']['manifest-file'] = self::trailingslashit_snapshot($_SESSION['restore_form']['snapshot']['extract-path']) . "snapshot_manifest.txt";
         if (!file_exists($_SESSION['restore_form']['snapshot']['manifest-file'])) {
             $form_errors['message-error'][] = "Snapshot archive Manifest file missing. Cannot restore/migrate via Snapshot.";
             return $form_errors;
         }
         $manifest_data = Snapshot_Helper_Utility::consume_archive_manifest($_SESSION['restore_form']['snapshot']['manifest-file']);
         if (is_array($manifest_data)) {
             $_SESSION['restore_form']['snapshot']['manifest-data'] = $manifest_data;
             $form_errors['message-success'][] = "Snapshot archive Manifest located and loaded successfully.";
         }
     }
     if ($_SESSION['restore_form']['wordpress']['reload'] == "yes" && isset($_SESSION['restore_form']['snapshot']['manifest-data']['WP_VERSION'])) {
         $_SESSION['restore_form']['wordpress']['archive-file-remote'] = 'http://wordpress.org/wordpress-' . $_SESSION['restore_form']['snapshot']['manifest-data']['WP_VERSION'] . '.zip';
         $_SESSION['restore_form']['wordpress']['archive-file-local'] = dirname(__FILE__) . "/_wordpress/file/" . basename($_SESSION['restore_form']['wordpress']['archive-file-remote']);
         $func_ret = Snapshot_Helper_Utility::remote_url_to_local_file($_SESSION['restore_form']['wordpress']['archive-file-remote'], $_SESSION['restore_form']['wordpress']['archive-file-local']);
         if (!file_exists($_SESSION['restore_form']['wordpress']['archive-file-local']) || !filesize($_SESSION['restore_form']['wordpress']['archive-file-local'])) {
             $form_errors['message-error'][] = "Attempted to download WordPress file to local [" . $_SESSION['restore_form']['wordpress']['archive-file-local'] . "]. File not found or is empty. Check parent folder permissions and reload the page.";
             return $form_errors;
         } else {
             $form_errors['message-success'][] = "Remote WordPress  Archive [" . basename($_SESSION['restore_form']['wordpress']['archive-file-local']) . "] downloaded successfully.";
             // Extract WordPress files into place
             $_SESSION['restore_form']['wordpress']['extract-path'] = dirname(__FILE__) . "/_wordpress/extract/";
             $unzip_ret = unzip_archive($_SESSION['restore_form']['wordpress']['archive-file-local'], $_SESSION['restore_form']['wordpress']['extract-path']);
             if (file_exists($_SESSION['restore_form']['wordpress']['extract-path'] . "/wordpress")) {
                 $_SESSION['restore_form']['wordpress']['extract-path'] = $_SESSION['restore_form']['wordpress']['extract-path'] . "/wordpress";
                 $form_errors['message-success'][] = "WordPress Archive extracted successfully.";
             }
             self::move_tree($_SESSION['restore_form']['wordpress']['extract-path'], $_SESSION['restore_form']['wordpress']['install-path']);
         }
     }
     return $form_errors;
 }