Ejemplo n.º 1
0
 /**
  * 
  * Enter description here ...
  */
 protected static function updatePlugin($viewBack = false)
 {
     $linkBack = self::getViewUrl($viewBack);
     $htmlLinkBack = UniteFunctionsRev::getHtmlLink($linkBack, "Go Back");
     //check if css table exist, if not, we need to verify that the current captions.css can be parsed
     if (UniteFunctionsWPRev::isDBTableExists(GlobalsRevSlider::TABLE_CSS_NAME)) {
         $captions = RevOperations::getCaptionsCssContentArray();
         if ($captions === false) {
             $message = "CSS parse error! Please make sure your captions.css is valid CSS before updating the plugin!";
             echo "<div style='color:#B80A0A;font-size:18px;'><b>Update Error: </b> {$message}</div><br>";
             echo $htmlLinkBack;
             exit;
         }
     }
     $zip = new UniteZipRev();
     try {
         if (function_exists("unzip_file") == false) {
             if (UniteZipRev::isZipExists() == false) {
                 UniteFunctionsRev::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 = UniteFunctionsRev::getVal($_FILES, "update_file");
         if (empty($arrFiles)) {
             UniteFunctionsRev::throwError("Update file don't found.");
         }
         $filename = UniteFunctionsRev::getVal($arrFiles, "name");
         if (empty($filename)) {
             UniteFunctionsRev::throwError("Update filename not found.");
         }
         $fileType = UniteFunctionsRev::getVal($arrFiles, "type");
         /*				
         $fileType = strtolower($fileType);
         
         if($fileType != "application/zip")
         	UniteFunctionsRev::throwError("The file uploaded is not zip.");
         */
         $filepathTemp = UniteFunctionsRev::getVal($arrFiles, "tmp_name");
         if (file_exists($filepathTemp) == false) {
             UniteFunctionsRev::throwError("Can't find the uploaded file.");
         }
         //crate temp folder
         UniteFunctionsRev::checkCreateDir(self::$path_temp);
         //create the update folder
         $pathUpdate = self::$path_temp . "update_extract/";
         UniteFunctionsRev::checkCreateDir($pathUpdate);
         //remove all files in the update folder
         if (is_dir($pathUpdate)) {
             $arrNotDeleted = UniteFunctionsRev::deleteDir($pathUpdate, false);
             if (!empty($arrNotDeleted)) {
                 $strNotDeleted = print_r($arrNotDeleted, true);
                 UniteFunctionsRev::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) {
             UniteFunctionsRev::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 = UniteFunctionsRev::getFoldersList($pathUpdate);
         if (empty($arrFolders)) {
             UniteFunctionsRev::throwError("The update folder is not extracted");
         }
         if (count($arrFolders) > 1) {
             UniteFunctionsRev::throwError("Extracted folders are more then 1. Please check the update file.");
         }
         //get product folder
         $productFolder = $arrFolders[0];
         if (empty($productFolder)) {
             UniteFunctionsRev::throwError("Wrong product folder.");
         }
         if ($productFolder != self::$dir_plugin) {
             UniteFunctionsRev::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) {
             UniteFunctionsRev::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[] = "rs-plugin/css/captions.css";
         $arrBlackList[] = "rs-plugin/css/dynamic-captions.css";
         $arrBlackList[] = "rs-plugin/css/static-captions.css";
         UniteFunctionsRev::copyDir($pathUpdateProduct, $pathOriginalPlugin, "", $arrBlackList);
         //delete the update
         UniteFunctionsRev::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;
     }
 }