public static function restoreBackupFile(&$arrForm) { // RESTORE BACKUP if (!isset($_POST['submit_file']) && !isset($_FILES['file']) && (!isset($_GET['restore']) || empty($_GET['restore']))) { return; } require_once Xpandbuddy::$pathName . '/library/Twig.php'; // cronfile start if (isset($_POST['submit_file'])) { switch ($_FILES['file']['error']) { case '0': // all ok if (!Xpandbuddy_Twig::zipUpload($_FILES['file'])) { $arrForm['error'] = Xpandbuddy_Twig::$error; } else { $arrForm['action'] = 'File is uploaded'; return; } break; case '1': $arrForm['error'] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; break; case '2': $arrForm['error'] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'; break; case '3': $arrForm['error'] = 'The uploaded file was only partially uploaded.'; break; case '4': /**/ break; case '6': $arrForm['error'] = 'Missing a temporary folder.'; break; case '7': $arrForm['error'] = 'Failed to write file to disk.'; break; case '8': $arrForm['error'] = 'A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop'; break; } return; } require_once Xpandbuddy::$pathName . '/library/Projects.php'; $_object = new Xpandbuddy_Projects(); if (isset($_GET['project']) && !empty($_GET['project'])) { $_object->withIds($_GET['project'])->onlyOne()->getList($_arrProject); } if (isset($_arrProject['flg_type'])) { foreach ($_arrProject['flg_type'] as $type) { switch ($type) { case '1': if (is_file(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . 'wp-backups' . Xpandbuddy_Twig::_subdirCreation() . $_GET['restore'])) { if (!Xpandbuddy_Twig::zipUpload(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . 'wp-backups' . Xpandbuddy_Twig::_subdirCreation() . $_GET['restore'])) { $arrForm['error'] = Xpandbuddy_Twig::$error; } else { $arrForm['action'] = 'Backup is uploaded!'; return; } } break; case '2': if (strlen((string) PHP_INT_MAX) >= 19) { require_once Xpandbuddy::$pathName . "/library/Dropbox/autoload.php"; $dbxClient = Dropbox_Client($_arrProject['settings']['access_token']); if (substr($_GET['restore'], strrpos($_GET['restore'], ".")) == '.gz') { $_tail = '.tar.gz'; } else { $_tail = '.zip'; } $file = fopen(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . Xpandbuddy_Twig::archiveName($_arrProject['settings']['blog']['url'], $_arrProject['id'], time()) . $_tail, "w+b"); $dbxClient->getFile($_GET['restore'], $file); fclose($file); if (!Xpandbuddy_Twig::zipUpload(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . Xpandbuddy_Twig::archiveName($_arrProject['settings']['blog']['url'], $_arrProject['id'], time()) . $_tail)) { $arrForm['error'] = Xpandbuddy_Twig::$error; @unlink(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . Xpandbuddy_Twig::archiveName($_arrProject['settings']['blog']['url'], $_arrProject['id'], time()) . $_tail); } else { $arrForm['action'] = 'Dropbox backup is uploaded'; @unlink(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . Xpandbuddy_Twig::archiveName($_arrProject['settings']['blog']['url'], $_arrProject['id'], time()) . $_tail); return; } } break; case '3': require_once Xpandbuddy::$pathName . "/library/GoogleAPI/Google_Client.php"; $client = new Google_Client(); $client->setClientId($_arrProject['settings']['google_key']); $client->setClientSecret($_arrProject['settings']['google_secret']); $client->setRedirectUri(admin_url('admin.php?page=xpandbuddy')); $client->setScopes(array('https://www.googleapis.com/auth/drive')); $client->refreshToken($_arrProject['settings']['refresh_token']); $accessToken = json_decode($client->getAccessToken()); $accessToken = $accessToken->access_token; $_folderName = str_replace(array("http://", "https://", ".", "/"), array("", "", "_", "_"), $_arrProject['settings']['blog']['url']); $req = new Google_HttpRequest('https://www.googleapis.com/drive/v2/files?q=' . urlencode("mimeType = 'application/vnd.google-apps.folder' and title = '" . $_folderName . "' and trashed = false"), 'GET', array('Authorization' => "Bearer " . $accessToken)); $siteFolder = json_decode(Google_Client::$io->makeRequest($req)->getResponseBody()); if (count($siteFolder->items) != 0) { $req = new Google_HttpRequest('https://www.googleapis.com/drive/v2/files?q=' . urlencode("'" . $siteFolder->items[0]->id . "' in parents"), 'GET', array('Authorization' => "Bearer " . $accessToken)); $siteFiles = json_decode(Google_Client::$io->makeRequest($req)->getResponseBody()); foreach ($siteFiles->items as $_file) { if ($_file->originalFilename == $_GET['restore']) { $filePosition = $_file->originalFilename; if (substr($filePosition, strrpos($filePosition, ".")) == '.gz') { $_tail = '.tar.gz'; } else { $_tail = '.zip'; } $file = fopen(substr(ABSPATH, 0, -1) . Xpandbuddy_Twig::archiveName($_arrProject['settings']['blog']['url'], $_arrProject['id'], time()) . $_tail, "w+b"); $src = fopen($_file->alternateLink, 'r'); if (!copy($src, $file)) { $arrForm['error'] = "Copy Error!"; continue; } fclose($file); fclose($src); if (!Xpandbuddy_Twig::zipUpload(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . Xpandbuddy_Twig::archiveName($_arrProject['settings']['blog']['url'], $_arrProject['id'], time()) . $_tail)) { $arrForm['error'] = Xpandbuddy_Twig::$error; } else { $arrForm['action'] = 'Google Drive backup is uploaded'; } @unlink(substr(ABSPATH, 0, -1) . Xpandbuddy_Twig::archiveName($_arrProject['settings']['blog']['url'], $_arrProject['id'], time()) . $_tail); return; } } } break; case '4': if (!empty($_arrProject['settings']['host']) && !empty($_arrProject['settings']['user']) && !empty($_arrProject['settings']['pass'])) { require_once Xpandbuddy::$pathName . "/library/Ftp.php"; $_ftp = new Xpandbuddy_Ftp(); if (!$_ftp->setChmod('0644')->setHost(urldecode($_arrProject['settings']['host']))->setUser(urldecode($_arrProject['settings']['user']))->setPassw(urldecode($_arrProject['settings']['pass']))->setRoot($_arrProject['settings']['dir_name'])->makeConnectToRootDir()) { $arrForm['error'] = "FTP connnection Error!"; } if (!$_ftp->fileDownload($_GET['restore'], substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . $_GET['restore'], true)) { $arrForm['error'] = "Get file from FTP Error!"; } $_ftp->closeConnection(); if (!Xpandbuddy_Twig::zipUpload(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . $_GET['restore'])) { $arrForm['error'] = Xpandbuddy_Twig::$error; @unlink(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . $_GET['restore']); } else { $arrForm['action'] = 'FTP backup is uploaded'; @unlink(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . $_GET['restore']); return; } } break; case '5': if (is_file(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . 'wp-backups' . Xpandbuddy_Twig::_subdirCreation() . $_GET['restore'])) { if (!Xpandbuddy_Twig::zipUpload(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . 'wp-backups' . Xpandbuddy_Twig::_subdirCreation() . $_GET['restore'])) { $arrForm['error'] = Xpandbuddy_Twig::$error; } else { $arrForm['action'] = 'Backup is uploaded!'; return; } } break; } } if (isset($_GET['restore'])) { if (is_file(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . 'wp-backups' . Xpandbuddy_Twig::_subdirCreation() . $_GET['restore'])) { if (!Xpandbuddy_Twig::zipUpload(substr(ABSPATH, 0, -1) . DIRECTORY_SEPARATOR . 'wp-backups' . Xpandbuddy_Twig::_subdirCreation() . $_GET['restore'])) { $arrForm['error'] = Xpandbuddy_Twig::$error; } else { $arrForm['action'] = 'Backup is uploaded!'; } } } } return; }