/** * * Enter description here ... */ protected static function updatePlugin($viewBack = null, $isRedirect = true) { $linkBack = self::getViewUrl($viewBack); $htmlLinkBack = UniteFunctionsBiz::getHtmlLink($linkBack, "Go Back"); $zip = new UniteZipBiz(); try { if (function_exists("unzip_file") == false) { if (UniteZipBiz::isZipExists() == false) { UniteFunctionsBiz::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 = UniteFunctionsBiz::getVal($_FILES, "update_file"); if (empty($arrFiles)) { UniteFunctionsBiz::throwError("Update file don't found."); } $filename = UniteFunctionsBiz::getVal($arrFiles, "name"); if (empty($filename)) { UniteFunctionsBiz::throwError("Update filename not found."); } $fileType = UniteFunctionsBiz::getVal($arrFiles, "type"); /* $fileType = strtolower($fileType); if($fileType != "application/zip") UniteFunctionsBiz::throwError("The file uploaded is not zip."); */ $filepathTemp = UniteFunctionsBiz::getVal($arrFiles, "tmp_name"); if (file_exists($filepathTemp) == false) { UniteFunctionsBiz::throwError("Can't find the uploaded file."); } //crate temp folder UniteFunctionsBiz::checkCreateDir(self::$path_temp); //create the update folder $pathUpdate = self::$path_temp . "update_extract/"; UniteFunctionsBiz::checkCreateDir($pathUpdate); //remove all files in the update folder if (is_dir($pathUpdate)) { $arrNotDeleted = UniteFunctionsBiz::deleteDir($pathUpdate, false); if (!empty($arrNotDeleted)) { $strNotDeleted = print_r($arrNotDeleted, true); UniteFunctionsBiz::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) { UniteFunctionsBiz::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 = UniteFunctionsBiz::getFoldersList($pathUpdate); if (empty($arrFolders)) { UniteFunctionsBiz::throwError("The update folder is not extracted"); } if (count($arrFolders) > 1) { UniteFunctionsBiz::throwError("Extracted folders are more then 1. Please check the update file."); } //get product folder $productFolder = $arrFolders[0]; if (empty($productFolder)) { UniteFunctionsBiz::throwError("Wrong product folder."); } if ($productFolder != self::$dir_plugin) { UniteFunctionsBiz::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) { UniteFunctionsBiz::throwError("Wrong update extracted folder. The file: {$checkFilepath} not found."); } //copy the plugin without the captions file. //$pathOriginalPlugin = $pathUpdate."copy/"; $pathOriginalPlugin = self::$path_plugin; $arrBlackList = array(); //$arrBlackList[] = "showbiz-plugin/css/captions.css"; UniteFunctionsBiz::copyDir($pathUpdateProduct, $pathOriginalPlugin, "", $arrBlackList); //delete the update UniteFunctionsBiz::deleteDir($pathUpdate); if ($isRedirect == true) { dmp("Updated Successfully, redirecting..."); echo "<script>location.href='{$linkBack}'</script>"; } return true; } 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; } }