Beispiel #1
0
function step_1_validate_form($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'] = 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'] = 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 = 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 = 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']))) {

		$_SESSION['restore_form']['snapshot']['extract-path'] = dirname(__FILE__) ."/_snapshot/extract/";
		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'] = 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_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 = 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.";
			}

			move_tree($_SESSION['restore_form']['wordpress']['extract-path'], $_SESSION['restore_form']['wordpress']['install-path']);
		}
	}


	return $form_errors;
}
Beispiel #2
0
function trailingslashit_snapshot($string) {
	return untrailingslashit_snapshot($string) . '/';
}