protected static function updatePlugin($viewBack = false) { $linkBack = self::getViewUrl($viewBack); $htmlLinkBack = UniteFunctionsBanner::getHtmlLink($linkBack, "Go Back"); $zip = new UniteZipBanner(); try { if (function_exists("unzip_file") == false) { if (UniteZipBanner::isZipExists() == false) { UniteFunctionsBanner::throwError("The ZipArchive php extension not exists, can't extract the update file. Please turn it on in php ini."); } } dmp("Update in progress..."); $arrFiles = UniteFunctionsBanner::getVal($_FILES, "update_file"); if (empty($arrFiles)) { UniteFunctionsBanner::throwError("Update file don't found."); } $filename = UniteFunctionsBanner::getVal($arrFiles, "name"); if (empty($filename)) { UniteFunctionsBanner::throwError("Update filename not found."); } $fileType = UniteFunctionsBanner::getVal($arrFiles, "type"); /* $fileType = strtolower($fileType); if($fileType != "application/zip") UniteFunctionsBanner::throwError("The file uploaded is not zip."); */ $filepathTemp = UniteFunctionsBanner::getVal($arrFiles, "tmp_name"); if (file_exists($filepathTemp) == false) { UniteFunctionsBanner::throwError("Can't find the uploaded file."); } //Crate temp folder UniteFunctionsBanner::checkCreateDir(self::$path_temp); //Create the update folder $pathUpdate = self::$path_temp . "update_extract/"; UniteFunctionsBanner::checkCreateDir($pathUpdate); //Remove all files in the update folder if (is_dir($pathUpdate)) { $arrNotDeleted = UniteFunctionsBanner::deleteDir($pathUpdate, false); if (!empty($arrNotDeleted)) { $strNotDeleted = print_r($arrNotDeleted, true); UniteFunctionsBanner::throwError("Could not delete those files from the update folder: {$strNotDeleted}"); } } //Copy the zip file $filepathZip = $pathUpdate . $filename; $success = move_uploaded_file($filepathTemp, $filepathZip); if ($success == false) { UniteFunctionsBanner::throwError("Can't move the uploaded file here: {$filepathZip}."); } if (function_exists("unzip_file") == true) { WP_Filesystem(); $response = unzip_file($filepathZip, $pathUpdate); } else { $zip->extract($filepathZip, $pathUpdate); } //Get extracted folder $arrFolders = UniteFunctionsBanner::getFoldersList($pathUpdate); if (empty($arrFolders)) { UniteFunctionsBanner::throwError("The update folder is not extracted"); } if (count($arrFolders) > 1) { UniteFunctionsBanner::throwError("Extracted folders are more then 1. Please check the update file."); } //Get product folder $productFolder = $arrFolders[0]; if (empty($productFolder)) { UniteFunctionsBanner::throwError("Wrong product folder."); } if ($productFolder != self::$dir_plugin) { UniteFunctionsBanner::throwError("The update folder don't match the product folder, please check the update file."); } $pathUpdateProduct = $pathUpdate . $productFolder . "/"; //Check some file in folder to validate it's the real one: $checkFilepath = $pathUpdateProduct . $productFolder . ".php"; if (file_exists($checkFilepath) == false) { UniteFunctionsBanner::throwError("Wrong update extracted folder. The file: {$checkFilepath} not found."); } //Copy the plugin without the captions file $pathOriginalPlugin = self::$path_plugin; $arrBlackList = array(); $arrBlackList[] = "css/caption.css"; UniteFunctionsBanner::copyDir($pathUpdateProduct, $pathOriginalPlugin, "", $arrBlackList); //Delete the update UniteFunctionsBanner::deleteDir($pathUpdate); dmp("Updated Successfully, redirecting..."); echo "<script>location.href='{$linkBack}'</script>"; } catch (Exception $e) { $message = $e->getMessage(); $message .= " <br> Please update the plugin manually via the ftp"; echo "<div style='color:#B80A0A;font-size:18px;'><b>Update Error: </b> {$message}</div><br>"; echo $htmlLinkBack; exit; } }