Пример #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;
     }
 }
 /**
  *
  * export slider from data, output a file for download
  */
 public function exportSlider($useDummy = false)
 {
     $export_zip = true;
     if (function_exists("unzip_file") == false) {
         if (UniteZipRev::isZipExists() == false) {
             $export_zip = false;
         }
     }
     if (!class_exists('ZipArchive')) {
         $export_zip = false;
     }
     if ($export_zip) {
         $zip = new ZipArchive();
         $success = $zip->open(GlobalsRevSlider::$urlExportZip, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE);
         if ($success !== true) {
             throwError("Can't create zip file: " . GlobalsRevSlider::$urlExportZip);
         }
         $this->validateInited();
         $sliderParams = $this->getParamsForExport();
         $arrSlides = $this->getSlidesForExport($useDummy);
         $arrStaticSlide = $this->getStaticSlideForExport($useDummy);
         $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides);
         if ($useDummy == 'true') {
             $upload_dir = wp_upload_dir();
             $arrSliderExport = $this->recursive_preg_replace('#^uploads#', $upload_dir['baseurl'], $arrSliderExport);
         }
         if (!empty($arrStaticSlide)) {
             $arrSliderExport['static_slides'] = $arrStaticSlide;
         }
         $strExport = serialize($arrSliderExport);
         //$strExportAnim = serialize(RevOperations::getFullCustomAnimations());
         $exportname = !empty($this->alias) ? $this->alias . '.zip' : "slider_export.zip";
         $usedCaptions = array();
         $usedAnimations = array();
         $usedImages = array();
         if (!empty($arrSlides) && count($arrSlides) > 0) {
             foreach ($arrSlides as $key => $slide) {
                 if (isset($slide['params']['image']) && $slide['params']['image'] != '') {
                     $usedImages[$slide['params']['image']] = true;
                 }
                 //['params']['image'] background url
                 if (isset($slide['layers']) && !empty($slide['layers']) && count($slide['layers']) > 0) {
                     foreach ($slide['layers'] as $lKey => $layer) {
                         if (isset($layer['style']) && $layer['style'] != '') {
                             $usedCaptions[$layer['style']] = true;
                         }
                         if (isset($layer['animation']) && $layer['animation'] != '' && strpos($layer['animation'], 'customin') !== false) {
                             $usedAnimations[str_replace('customin-', '', $layer['animation'])] = true;
                         }
                         if (isset($layer['endanimation']) && $layer['endanimation'] != '' && strpos($layer['endanimation'], 'customout') !== false) {
                             $usedAnimations[str_replace('customout-', '', $layer['endanimation'])] = true;
                         }
                         if (isset($layer['image_url']) && $layer['image_url'] != '') {
                             $usedImages[$layer['image_url']] = true;
                         }
                         //image_url if image caption
                     }
                 }
             }
         }
         if (!empty($arrStaticSlide) && count($arrStaticSlide) > 0) {
             foreach ($arrStaticSlide as $key => $slide) {
                 if (isset($slide['params']['image']) && $slide['params']['image'] != '') {
                     $usedImages[$slide['params']['image']] = true;
                 }
                 //['params']['image'] background url
                 if (isset($slide['layers']) && !empty($slide['layers']) && count($slide['layers']) > 0) {
                     foreach ($slide['layers'] as $lKey => $layer) {
                         if (isset($layer['style']) && $layer['style'] != '') {
                             $usedCaptions[$layer['style']] = true;
                         }
                         if (isset($layer['animation']) && $layer['animation'] != '' && strpos($layer['animation'], 'customin') !== false) {
                             $usedAnimations[str_replace('customin-', '', $layer['animation'])] = true;
                         }
                         if (isset($layer['endanimation']) && $layer['endanimation'] != '' && strpos($layer['endanimation'], 'customout') !== false) {
                             $usedAnimations[str_replace('customout-', '', $layer['endanimation'])] = true;
                         }
                         if (isset($layer['image_url']) && $layer['image_url'] != '') {
                             $usedImages[$layer['image_url']] = true;
                         }
                         //image_url if image caption
                     }
                 }
             }
         }
         $styles = '';
         if (!empty($usedCaptions)) {
             $captions = array();
             foreach ($usedCaptions as $class => $val) {
                 $cap = RevOperations::getCaptionsContentArray($class);
                 if (!empty($cap)) {
                     $captions[] = $cap;
                 }
             }
             $styles = UniteCssParserRev::parseArrayToCss($captions, "\n", false);
         }
         $animations = '';
         if (!empty($usedAnimations)) {
             $animation = array();
             foreach ($usedAnimations as $anim => $val) {
                 $anima = RevOperations::getFullCustomAnimationByID($anim);
                 if ($anima !== false) {
                     $animation[] = RevOperations::getFullCustomAnimationByID($anim);
                 }
             }
             if (!empty($animation)) {
                 $animations = serialize($animation);
             }
         }
         //add images to zip
         if (!empty($usedImages)) {
             $upload_dir = UniteFunctionsWPRev::getPathUploads();
             $upload_dir_multisiteless = wp_upload_dir();
             $cont_url = $upload_dir_multisiteless['baseurl'];
             $cont_url_no_www = str_replace('www.', '', $upload_dir_multisiteless['baseurl']);
             $upload_dir_multisiteless = $upload_dir_multisiteless['basedir'] . '/';
             foreach ($usedImages as $file => $val) {
                 if ($useDummy == "true") {
                     //only use dummy images
                 } else {
                     //use the real images
                     if (strpos($file, 'http') !== false) {
                         $checkpath = str_replace(array($cont_url, $cont_url_no_www), '', $file);
                         if (is_file($upload_dir . $checkpath)) {
                             $zip->addFile($upload_dir . $checkpath, 'images/' . $checkpath);
                         } elseif (is_file($upload_dir_multisiteless . $checkpath)) {
                             $zip->addFile($upload_dir_multisiteless . $checkpath, 'images/' . $checkpath);
                         }
                     } else {
                         if (is_file($upload_dir . $file)) {
                             $zip->addFile($upload_dir . $file, 'images/' . $file);
                         } elseif (is_file($upload_dir_multisiteless . $file)) {
                             $zip->addFile($upload_dir_multisiteless . $file, 'images/' . $file);
                         }
                     }
                 }
             }
         }
         $zip->addFromString("slider_export.txt", $strExport);
         //add slider settings
         if (strlen(trim($animations)) > 0) {
             $zip->addFromString("custom_animations.txt", $animations);
         }
         //add custom animations
         if (strlen(trim($styles)) > 0) {
             $zip->addFromString("dynamic-captions.css", $styles);
         }
         //add dynamic styles
         $static_css = RevOperations::getStaticCss();
         $zip->addFromString("static-captions.css", $static_css);
         //add slider settings
         $zip->close();
         header("Content-type: application/zip");
         header("Content-Disposition: attachment; filename=" . $exportname);
         header("Pragma: no-cache");
         header("Expires: 0");
         readfile(GlobalsRevSlider::$urlExportZip);
         @unlink(GlobalsRevSlider::$urlExportZip);
         //delete file after sending it to user
     } else {
         //fallback, do old export
         $this->validateInited();
         $sliderParams = $this->getParamsForExport();
         $arrSlides = $this->getSlidesForExport();
         $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides);
         $strExport = serialize($arrSliderExport);
         if (!empty($this->alias)) {
             $filename = $this->alias . ".txt";
         } else {
             $filename = "slider_export.txt";
         }
         UniteFunctionsRev::downloadFile($strExport, $filename);
     }
 }
Пример #3
0
 /**
  * 
  * export slider from data, output a file for download
  */
 public function exportSlider($useDummy = false)
 {
     $export_zip = true;
     if (function_exists("unzip_file") == false) {
         if (UniteZipRev::isZipExists() == false) {
             $export_zip = false;
         }
         //UniteFunctionsRev::throwError("The ZipArchive php extension not exists, can't create the export file. Please turn it on in php ini.");
     }
     if (!class_exists('ZipArchive')) {
         $export_zip = false;
     }
     //if(!class_exists('ZipArchive')) UniteFunctionsRev::throwError("The ZipArchive php extension not exists, can't create the export file. Please turn it on in php ini.");
     if ($export_zip) {
         $zip = new ZipArchive();
         $success = $zip->open(GlobalsRevSlider::$urlExportZip, ZipArchive::OVERWRITE);
         if ($success == false) {
             throwError("Can't create zip file: " . GlobalsRevSlider::$urlExportZip);
         }
         $this->validateInited();
         $sliderParams = $this->getParamsForExport();
         $arrSlides = $this->getSlidesForExport($useDummy);
         $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides);
         $strExport = serialize($arrSliderExport);
         //$strExportAnim = serialize(RevOperations::getFullCustomAnimations());
         $exportname = !empty($this->alias) ? $this->alias . '.zip' : "slider_export.zip";
         $usedCaptions = array();
         $usedAnimations = array();
         $usedImages = array();
         if (!empty($arrSlides) && count($arrSlides) > 0) {
             foreach ($arrSlides as $key => $slide) {
                 if (isset($slide['params']['image']) && $slide['params']['image'] != '') {
                     $usedImages[$slide['params']['image']] = true;
                 }
                 //['params']['image'] background url
                 if (isset($slide['layers']) && !empty($slide['layers']) && count($slide['layers']) > 0) {
                     foreach ($slide['layers'] as $lKey => $layer) {
                         if (isset($layer['style']) && $layer['style'] != '') {
                             $usedCaptions[$layer['style']] = true;
                         }
                         if (isset($layer['animation']) && $layer['animation'] != '' && strpos($layer['animation'], 'customin') !== false) {
                             $usedAnimations[str_replace('customin-', '', $layer['animation'])] = true;
                         }
                         if (isset($layer['endanimation']) && $layer['endanimation'] != '' && strpos($layer['endanimation'], 'customout') !== false) {
                             $usedAnimations[str_replace('customout-', '', $layer['endanimation'])] = true;
                         }
                         if (isset($layer['image_url']) && $layer['image_url'] != '') {
                             $usedImages[$layer['image_url']] = true;
                         }
                         //image_url if image caption
                     }
                 }
             }
         }
         $styles = '';
         if (!empty($usedCaptions)) {
             $captions = array();
             foreach ($usedCaptions as $class => $val) {
                 $captions[] = RevOperations::getCaptionsContentArray($class);
             }
             $styles = UniteCssParserRev::parseArrayToCss($captions, "\n");
         }
         $animations = '';
         if (!empty($usedAnimations)) {
             $animation = array();
             foreach ($usedAnimations as $anim => $val) {
                 $anima = RevOperations::getFullCustomAnimationByID($anim);
                 if ($anima !== false) {
                     $animation[] = RevOperations::getFullCustomAnimationByID($anim);
                 }
             }
             if (!empty($animation)) {
                 $animations = serialize($animation);
             }
         }
         //add images to zip
         if (!empty($usedImages)) {
             $upload_dir = UniteFunctionsWPRev::getPathUploads();
             foreach ($usedImages as $file => $val) {
                 if ($useDummy == "true") {
                     //only use dummy images
                 } else {
                     //use the real images
                     $zip->addFile($upload_dir . $file, 'images/' . $file);
                 }
             }
         }
         $zip->addFromString("slider_export.txt", $strExport);
         //add slider settings
         if (strlen(trim($animations)) > 0) {
             $zip->addFromString("custom_animations.txt", $animations);
         }
         //add custom animations
         if (strlen(trim($styles)) > 0) {
             $zip->addFromString("dynamic-captions.css", $styles);
         }
         //add dynamic styles
         //$zip->addFromString("custom_animations.txt", $strExportAnim); //add custom animations
         //$zip->addFile(GlobalsRevSlider::$filepath_dynamic_captions,'dynamic-captions.css'); //add dynamic styles
         $zip->addFile(GlobalsRevSlider::$filepath_static_captions, 'static-captions.css');
         //add static styles
         $zip->close();
         header("Content-type: application/zip");
         header("Content-Disposition: attachment; filename=" . $exportname);
         header("Pragma: no-cache");
         header("Expires: 0");
         readfile(GlobalsRevSlider::$urlExportZip);
         @unlink(GlobalsRevSlider::$urlExportZip);
         //delete file after sending it to user
     } else {
         //fallback, do old export
         $this->validateInited();
         $sliderParams = $this->getParamsForExport();
         $arrSlides = $this->getSlidesForExport();
         $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides);
         $strExport = serialize($arrSliderExport);
         if (!empty($this->alias)) {
             $filename = $this->alias . ".txt";
         } else {
             $filename = "slider_export.txt";
         }
         UniteFunctionsRev::downloadFile($strExport, $filename);
     }
 }
 public function exportSlider($useDummy = false)
 {
     $export_zip = true;
     if (function_exists("unzip_file") == false) {
         if (UniteZipRev::isZipExists() == false) {
             $export_zip = false;
         }
     }
     if (!class_exists('ZipArchive')) {
         $export_zip = false;
     }
     if ($export_zip) {
         $zip = new ZipArchive();
         // $success = $zip->open(GlobalsRevSlider::$urlExportZip, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE);
         $success = $zip->open(GlobalsRevSlider::$urlExportZip, ZipArchive::OVERWRITE);
         if ($success !== true) {
             throwError("Can't create zip file: " . GlobalsRevSlider::$urlExportZip);
         }
         $this->validateInited();
         $sliderParams = $this->getParamsForExport();
         $arrSlides = $this->getSlidesForExport($useDummy);
         $arrStaticSlide = $this->getStaticSlideForExport($useDummy);
         $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides);
         if (!empty($arrStaticSlide)) {
             $arrSliderExport['static_slides'] = $arrStaticSlide;
         }
         $strExport = serialize($arrSliderExport);
         $exportname = !empty($this->alias) ? $this->alias . '.zip' : "slider_export.zip";
         $usedCaptions = array();
         $usedAnimations = array();
         $usedImages = array();
         if (!empty($arrSlides) && count($arrSlides) > 0) {
             foreach ($arrSlides as $key => $slide) {
                 if (isset($slide['params']['image']) && $slide['params']['image'] != '') {
                     $usedImages[$slide['params']['image']] = true;
                 }
                 if (isset($slide['layers']) && !empty($slide['layers']) && count($slide['layers']) > 0) {
                     foreach ($slide['layers'] as $lKey => $layer) {
                         if (isset($layer['style']) && $layer['style'] != '') {
                             $usedCaptions[$layer['style']] = true;
                         }
                         if (isset($layer['animation']) && $layer['animation'] != '' && strpos($layer['animation'], 'customin') !== false) {
                             $usedAnimations[str_replace('customin-', '', $layer['animation'])] = true;
                         }
                         if (isset($layer['endanimation']) && $layer['endanimation'] != '' && strpos($layer['endanimation'], 'customout') !== false) {
                             $usedAnimations[str_replace('customout-', '', $layer['endanimation'])] = true;
                         }
                         if (isset($layer['image_url']) && $layer['image_url'] != '') {
                             $usedImages[$layer['image_url']] = true;
                         }
                     }
                 }
             }
         }
         if (!empty($arrStaticSlide) && count($arrStaticSlide) > 0) {
             foreach ($arrStaticSlide as $key => $slide) {
                 if (isset($slide['params']['image']) && $slide['params']['image'] != '') {
                     $usedImages[$slide['params']['image']] = true;
                 }
                 if (isset($slide['layers']) && !empty($slide['layers']) && count($slide['layers']) > 0) {
                     foreach ($slide['layers'] as $lKey => $layer) {
                         if (isset($layer['style']) && $layer['style'] != '') {
                             $usedCaptions[$layer['style']] = true;
                         }
                         if (isset($layer['animation']) && $layer['animation'] != '' && strpos($layer['animation'], 'customin') !== false) {
                             $usedAnimations[str_replace('customin-', '', $layer['animation'])] = true;
                         }
                         if (isset($layer['endanimation']) && $layer['endanimation'] != '' && strpos($layer['endanimation'], 'customout') !== false) {
                             $usedAnimations[str_replace('customout-', '', $layer['endanimation'])] = true;
                         }
                         if (isset($layer['image_url']) && $layer['image_url'] != '') {
                             $usedImages[$layer['image_url']] = true;
                         }
                     }
                 }
             }
         }
         $styles = '';
         if (!empty($usedCaptions)) {
             $captions = array();
             foreach ($usedCaptions as $class => $val) {
                 $cap = RevOperations::getCaptionsContentArray($class);
                 if (!empty($cap)) {
                     $captions[] = $cap;
                 }
             }
             $styles = UniteCssParserRev::parseArrayToCss($captions, "\n");
         }
         $animations = '';
         if (!empty($usedAnimations)) {
             $animation = array();
             foreach ($usedAnimations as $anim => $val) {
                 $anima = RevOperations::getFullCustomAnimationByID($anim);
                 if ($anima !== false) {
                     $animation[] = RevOperations::getFullCustomAnimationByID($anim);
                 }
             }
             if (!empty($animation)) {
                 $animations = serialize($animation);
             }
         }
         if (!empty($usedImages)) {
             // $upload_dir = UniteFunctionsWPRev::getPathUploads();
             $upload_dir = get_mainsite_dir();
             foreach ($usedImages as $file => $val) {
                 if ($useDummy == "true") {
                 } else {
                     if (strpos($file, 'http') !== false) {
                     } else {
                         if (is_file($upload_dir . $file)) {
                             $zip->addFile(realpath($upload_dir . $file), 'images/' . $file);
                         }
                     }
                 }
             }
         }
         $zip->addFromString("slider_export.txt", $strExport);
         if (strlen(trim($animations)) > 0) {
             $zip->addFromString("custom_animations.txt", $animations);
         }
         if (strlen(trim($styles)) > 0) {
             $zip->addFromString("dynamic-captions.css", $styles);
         }
         $static_css = RevOperations::getStaticCss();
         $zip->addFromString("static-captions.css", $static_css);
         $zip->close();
         header("Content-type: application/zip");
         header("Content-Disposition: attachment; filename=" . $exportname);
         header("Pragma: no-cache");
         header("Expires: 0");
         readfile(GlobalsRevSlider::$urlExportZip);
         @unlink(GlobalsRevSlider::$urlExportZip);
     } else {
         $this->validateInited();
         $sliderParams = $this->getParamsForExport();
         $arrSlides = $this->getSlidesForExport();
         $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides);
         $strExport = serialize($arrSliderExport);
         if (!empty($this->alias)) {
             $filename = $this->alias . ".txt";
         } else {
             $filename = "slider_export.txt";
         }
         UniteFunctionsRev::downloadFile($strExport, $filename);
     }
 }