/**
  * get image real path physical on disk from url
  */
 public static function getImageRealPathFromUrl($urlImage)
 {
     $filepath = self::getImagePathFromURL($urlImage);
     $realPath = RevSliderFunctionsWP::getPathUploads() . $filepath;
     return $realPath;
 }
 /**
  * 
  * export slider from data, output a file for download
  */
 public function exportSlider($useDummy = false)
 {
     $export_zip = true;
     if (function_exists("unzip_file") == false) {
         if (class_exists("ZipArchive") == false) {
             $export_zip = false;
         }
     }
     if (!class_exists('ZipArchive')) {
         $export_zip = false;
     }
     if ($export_zip) {
         $zip = new ZipArchive();
         $success = $zip->open(RevSliderGlobals::$urlExportZip, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE);
         if ($success !== true) {
             throwError("Can't create zip file: " . RevSliderGlobals::$urlExportZip);
         }
         $this->validateInited();
         $sliderParams = $this->getParamsForExport();
         $arrSlides = $this->getSlidesForExport($useDummy);
         $arrStaticSlide = $this->getStaticSlideForExport($useDummy);
         $usedCaptions = array();
         $usedAnimations = array();
         $usedImages = array();
         $usedVideos = array();
         $cfw = array();
         if (!empty($arrSlides) && count($arrSlides) > 0) {
             $cfw = array_merge($cfw, $arrSlides);
         }
         if (!empty($arrStaticSlide) && count($arrStaticSlide) > 0) {
             $cfw = array_merge($cfw, $arrStaticSlide);
         }
         if (!empty($cfw) && count($cfw) > 0) {
             foreach ($cfw as $key => $slide) {
                 if (isset($slide['params']['image']) && $slide['params']['image'] != '') {
                     $usedImages[$slide['params']['image']] = true;
                 }
                 //['params']['image'] background url
                 if (isset($slide['params']['background_image']) && $slide['params']['background_image'] != '') {
                     $usedImages[$slide['params']['background_image']] = true;
                 }
                 //['params']['image'] background url
                 if (isset($slide['params']['slide_thumb']) && $slide['params']['slide_thumb'] != '') {
                     $usedImages[$slide['params']['slide_thumb']] = true;
                 }
                 //['params']['image'] background url
                 //html5 video
                 if (isset($slide['params']['background_type']) && $slide['params']['background_type'] == 'html5') {
                     if (isset($slide['params']['slide_bg_html_mpeg']) && $slide['params']['slide_bg_html_mpeg'] != '') {
                         $usedVideos[$slide['params']['slide_bg_html_mpeg']] = true;
                     }
                     if (isset($slide['params']['slide_bg_html_webm']) && $slide['params']['slide_bg_html_webm'] != '') {
                         $usedVideos[$slide['params']['slide_bg_html_webm']] = true;
                     }
                     if (isset($slide['params']['slide_bg_html_ogv']) && $slide['params']['slide_bg_html_ogv'] != '') {
                         $usedVideos[$slide['params']['slide_bg_html_ogv']] = true;
                     }
                 } else {
                     if (isset($slide['params']['slide_bg_html_mpeg']) && $slide['params']['slide_bg_html_mpeg'] != '') {
                         $slide['params']['slide_bg_html_mpeg'] = '';
                     }
                     if (isset($slide['params']['slide_bg_html_webm']) && $slide['params']['slide_bg_html_webm'] != '') {
                         $slide['params']['slide_bg_html_webm'] = '';
                     }
                     if (isset($slide['params']['slide_bg_html_ogv']) && $slide['params']['slide_bg_html_ogv'] != '') {
                         $slide['params']['slide_bg_html_ogv'] = '';
                     }
                 }
                 //image thumbnail
                 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 (isset($layer['type']) && $layer['type'] == 'video') {
                             $video_data = isset($layer['video_data']) ? (array) $layer['video_data'] : array();
                             if (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] == 'html5') {
                                 if (isset($video_data['urlPoster']) && $video_data['urlPoster'] != '') {
                                     $usedImages[$video_data['urlPoster']] = true;
                                 }
                                 if (isset($video_data['urlMp4']) && $video_data['urlMp4'] != '') {
                                     $usedVideos[$video_data['urlMp4']] = true;
                                 }
                                 if (isset($video_data['urlWebm']) && $video_data['urlWebm'] != '') {
                                     $usedVideos[$video_data['urlWebm']] = true;
                                 }
                                 if (isset($video_data['urlOgv']) && $video_data['urlOgv'] != '') {
                                     $usedVideos[$video_data['urlOgv']] = true;
                                 }
                             } elseif (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] != 'html5') {
                                 //video cover image
                                 if (isset($video_data['previewimage']) && $video_data['previewimage'] != '') {
                                     $usedImages[$video_data['previewimage']] = 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; //['params']['image'] background url
         					
         					//html5 video
         					if(isset($slide['params']['background_type']) && $slide['params']['background_type'] == 'html5'){
         						if(isset($slide['params']['slide_bg_html_mpeg']) && $slide['params']['slide_bg_html_mpeg'] != '') $usedVideos[$slide['params']['slide_bg_html_mpeg']] = true;
         						if(isset($slide['params']['slide_bg_html_webm']) && $slide['params']['slide_bg_html_webm'] != '') $usedVideos[$slide['params']['slide_bg_html_webm']] = true;
         						if(isset($slide['params']['slide_bg_html_ogv']) && $slide['params']['slide_bg_html_ogv'] != '') $usedVideos[$slide['params']['slide_bg_html_ogv']] = 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; //image_url if image caption
         							
         							if(isset($layer['type']) && $layer['type'] == 'video'){
         								
         								$video_data = (isset($layer['video_data'])) ? (array) $layer['video_data'] : array();
         								
         								if(!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] == 'html5'){
         
         									if(isset($video_data['urlPoster']) && $video_data['urlPoster'] != '') $usedImages[$video_data['urlPoster']] = true;
         									
         									if(isset($video_data['urlMp4']) && $video_data['urlMp4'] != '') $usedVideos[$video_data['urlMp4']] = true;
         									if(isset($video_data['urlWebm']) && $video_data['urlWebm'] != '') $usedVideos[$video_data['urlWebm']] = true;
         									if(isset($video_data['urlOgv']) && $video_data['urlOgv'] != '') $usedVideos[$video_data['urlOgv']] = true;
         									
         								}elseif(!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] != 'html5'){ //video cover image
         									if(isset($video_data['previewimage']) && $video_data['previewimage'] != '') $usedImages[$video_data['previewimage']] = true;
         								}
         							}
         						}
         					}
         				}
         			}*/
         $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides);
         if (!empty($arrStaticSlide)) {
             $arrSliderExport['static_slides'] = $arrStaticSlide;
         }
         $strExport = serialize($arrSliderExport);
         //$strExportAnim = serialize(RevSliderOperations::getFullCustomAnimations());
         $exportname = !empty($this->alias) ? $this->alias . '.zip' : "slider_export.zip";
         $styles = '';
         if (!empty($usedCaptions)) {
             $captions = array();
             foreach ($usedCaptions as $class => $val) {
                 $cap = RevSliderOperations::getCaptionsContentArray($class);
                 //set also advanced styles here...
                 if (!empty($cap)) {
                     $captions[] = $cap;
                 }
             }
             $styles = RevSliderCssParser::parseArrayToCss($captions, "\n", true);
         }
         $animations = '';
         if (!empty($usedAnimations)) {
             $animation = array();
             foreach ($usedAnimations as $anim => $val) {
                 $anima = RevSliderOperations::getFullCustomAnimationByID($anim);
                 if ($anima !== false) {
                     $animation[] = RevSliderOperations::getFullCustomAnimationByID($anim);
                 }
             }
             if (!empty($animation)) {
                 $animations = serialize($animation);
             }
         }
         $usedImages = array_merge($usedImages, $usedVideos);
         //add images to zip
         if (!empty($usedImages)) {
             $upload_dir = RevSliderFunctionsWP::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) {
                         $remove = 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);
                             $remove = true;
                         } elseif (is_file($upload_dir_multisiteless . $checkpath)) {
                             $zip->addFile($upload_dir_multisiteless . $checkpath, 'images/' . $checkpath);
                             $remove = true;
                         }
                         if ($remove) {
                             //as its http, remove this from strexport
                             $strExport = str_replace(array($cont_url . $checkpath, $cont_url_no_www . $checkpath), $checkpath, $strExport);
                         }
                     } 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 = RevSliderOperations::getStaticCss();
         $zip->addFromString("static-captions.css", $static_css);
         //add slider settings
         $enable_slider_pack = apply_filters('revslider_slider_pack_export', false);
         if ($enable_slider_pack) {
             //allow for slider packs the automatic creation of the info.cfg
             $zip->addFromString('info.cfg', md5($this->alias));
             //add slider settings
         }
         $zip->close();
         header("Content-type: application/zip");
         header("Content-Disposition: attachment; filename=" . $exportname);
         header("Pragma: no-cache");
         header("Expires: 0");
         readfile(RevSliderGlobals::$urlExportZip);
         @unlink(RevSliderGlobals::$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";
         }
         RevSliderFunctions::downloadFile($strExport, $filename);
     }
 }
    public function previewOutputMarkup($sliderID)
    {
        $export_real = true;
        //if false, then kriki export for JavaScript Standalone version
        if ($export_real) {
            //set all different file path's here
            $path_fonts = 'fonts/';
            $path_css = 'css/';
            $path_js = 'js/';
            $path_assets = 'assets';
            $path_assets_raw = 'assets';
            $path_assets_vid = 'assets';
            $path_assets_raw_vid = 'assets';
        } else {
            $path_fonts = '../../revolution/fonts/';
            $path_css = '../../revolution/css/';
            $path_js = '../../revolution/js/';
            $path_assets = '../../assets/images';
            $path_assets_raw = 'assets/images';
            $path_assets_vid = '../../assets/videos';
            $path_assets_raw_vid = 'assets/videos';
        }
        if (function_exists("unzip_file") == false && class_exists("ZipArchive") == false) {
            echo __('ZipArchive extension not available, please enable it to use this functionality.', REVSLIDER_TEXTDOMAIN);
            exit;
        }
        $zip = new ZipArchive();
        $success = $zip->open(RevSliderGlobals::$uploadsUrlExportZip, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE);
        if ($success !== true) {
            echo __("No write permissions. Can't create zip file: ", REVSLIDER_TEXTDOMAIN) . RevSliderGlobals::$uploadsUrlExportZip;
            exit;
        }
        if ($sliderID == "empty_output") {
            echo __("Wrong request!", REVSLIDER_TEXTDOMAIN);
            exit;
        }
        $output = new RevSliderOutput();
        $operations = new RevSliderOperations();
        $slider = new RevSlider();
        $slider->initByID($sliderID);
        $output->setPreviewMode();
        $http = is_ssl() ? 'https' : 'http';
        $arrValues = $operations->getGeneralSettingsValues();
        $set_diff_font = RevSliderFunctions::getVal($arrValues, "change_font_loading", '');
        if ($set_diff_font !== '') {
            $font_url = $set_diff_font;
        } else {
            $font_url = $http . '://fonts.googleapis.com/css?family=';
        }
        $static_css = RevSliderOperations::getStaticCss();
        ob_start();
        $output->putSliderBase($sliderID, array(), true);
        $content = ob_get_contents();
        ob_clean();
        ob_end_clean();
        $fonts = '';
        while (strpos($content, '<!-- FONT -->') !== false) {
            $temp_font = substr($content, strpos($content, '<!-- FONT -->'), strpos($content, '<!-- /FONT -->') + 14 - strpos($content, '<!-- FONT -->')) . "\n";
            $fonts .= $temp_font;
            $starthtml = substr($content, 0, strpos($content, '<!-- FONT -->'));
            $endhtml = substr($content, strpos($content, '<!-- /FONT -->') + 14);
            $content = $starthtml . $endhtml;
            //remove from html markup
        }
        $fonts = str_replace(array('<!-- FONT -->', '<!-- /FONT -->'), '', $fonts);
        //remove the tags
        $scripts = '';
        while (strpos($content, '<!-- SCRIPT -->') !== false) {
            $temp_script = substr($content, strpos($content, '<!-- SCRIPT -->'), strpos($content, '<!-- /SCRIPT -->') + 16 - strpos($content, '<!-- SCRIPT -->')) . "\n";
            $scripts .= $temp_script;
            $starthtml = substr($content, 0, strpos($content, '<!-- SCRIPT -->'));
            $endhtml = substr($content, strpos($content, '<!-- /SCRIPT -->') + 16);
            $content = $starthtml . $endhtml;
            //remove from html markup
        }
        $scripts = str_replace(array('<!-- SCRIPT -->', '<!-- /SCRIPT -->'), '', $scripts);
        //remove the tags
        $styles = '';
        while (strpos($content, '<!-- STYLE -->') !== false) {
            $temp_style = substr($content, strpos($content, '<!-- STYLE -->'), strpos($content, '<!-- /STYLE -->') + 15 - strpos($content, '<!-- STYLE -->')) . "\n";
            $styles .= $temp_style;
            $starthtml = substr($content, 0, strpos($content, '<!-- STYLE -->'));
            $endhtml = substr($content, strpos($content, '<!-- /STYLE -->') + 15);
            $content = $starthtml . $endhtml;
            //remove from html markup
        }
        $styles = str_replace(array('<!-- STYLE -->', '<!-- /STYLE -->'), '', $styles);
        //remove the tags
        $full_content = '';
        ob_start();
        ?>
<!DOCTYPE html>
	<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
	<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
	<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
	<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title><?php 
        echo $slider->getTitle();
        ?>
 - Slider Revolution</title>
		<meta name="description" content="Slider Revolution Example" />
		<meta name="keywords" content="fullscreen image, grid layout, flexbox grid, transition" />
		<meta name="author" content="ThemePunch" />
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<!-- LOAD JQUERY LIBRARY -->
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
		
		<!-- LOADING FONTS AND ICONS -->
		<?php 
        echo $fonts;
        ?>
		
		<link rel="stylesheet" type="text/css" href="<?php 
        echo $path_fonts;
        ?>
pe-icon-7-stroke/css/pe-icon-7-stroke.css">
		<link rel="stylesheet" type="text/css" href="<?php 
        echo $path_fonts;
        ?>
font-awesome/css/font-awesome.min.css">
		
		<!-- REVOLUTION STYLE SHEETS -->
		<link rel="stylesheet" type="text/css" href="<?php 
        echo $path_css;
        ?>
settings.css">
		<!-- REVOLUTION LAYERS STYLES -->
		<?php 
        if ($export_real) {
            echo $styles;
            if ($static_css !== '') {
                echo '<style type="text/css">';
                echo RevSliderCssParser::compress_css($static_css);
                echo '</style>' . "\n";
            }
        } else {
            ?>
			<link rel="stylesheet" type="text/css" href="<?php 
            echo $path_css;
            ?>
layers.css">
			
			<!-- REVOLUTION NAVIGATION STYLES -->
			<link rel="stylesheet" type="text/css" href="<?php 
            echo $path_css;
            ?>
navigation.css">
			
			<link rel="stylesheet" type="text/css" href="../../assets/css/noneed.css">
			<?php 
        }
        ?>
		<!-- REVOLUTION JS FILES -->
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
jquery.themepunch.tools.min.js"></script>
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
jquery.themepunch.revolution.min.js"></script>

		<!-- SLIDER REVOLUTION 5.0 EXTENSIONS  (Load Extensions only on Local File Systems !  The following part can be removed on Server for On Demand Loading) -->	
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
extensions/revolution.extension.actions.min.js"></script>
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
extensions/revolution.extension.carousel.min.js"></script>
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
extensions/revolution.extension.kenburn.min.js"></script>
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
extensions/revolution.extension.layeranimation.min.js"></script>
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
extensions/revolution.extension.migration.min.js"></script>
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
extensions/revolution.extension.navigation.min.js"></script>
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
extensions/revolution.extension.parallax.min.js"></script>
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
extensions/revolution.extension.slideanims.min.js"></script>
		<script type="text/javascript" src="<?php 
        echo $path_js;
        ?>
extensions/revolution.extension.video.min.js"></script>
	</head>
	
	<body>
		<?php 
        if (!$export_real) {
            ?>
		<!-- HEADER -->
		<article class="content">
			<!-- Add your site or application content here -->
			<section class="header">
				<span class="logo" style="float:left"></span>
				<a class="button" style="float:right" href="http://www.themepunch.com/revsliderjquery-doc/get-started/"><i class="pe-7s-help2"></i>Online Documentation</a>
				<div class="clearfix"></div>
			</section>
		</article>

		<article class="small-history"> 
			<h2 class="textaligncenter" style="margin-bottom:25px;">Slideshow Gallery</h2>
			<p>The Slider below is a classic slideshow with timer, bullet and arrow navigation. Slider Revolution offers millions of layout combinations.</p>
		</article>

		<!-- SLIDER EXAMPLE -->
		<section class="example">
			<article class="content">
		<?php 
        }
        ?>
	<?php 
        $head = ob_get_contents();
        ob_clean();
        ob_end_clean();
        ob_start();
        ?>
	<?php 
        if (!$export_real) {
            ?>
			</article>
		</section>
	<?php 
        }
        ?>
	</body>
</html>
<?php 
        $footer = ob_get_contents();
        ob_clean();
        ob_end_clean();
        $slider_html = $head . "\n" . $content . "\n" . $scripts . "\n" . $footer;
        $upload_dir = RevSliderFunctionsWP::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'] . '/';
        $search = array($cont_url, $cont_url_no_www, RS_PLUGIN_URL);
        $added = array();
        foreach ($search as $s) {
            preg_match_all("/(\"|')" . str_replace('/', '\\/', $s) . "\\S+(\"|')/", $slider_html, $_files);
            if (!empty($_files) && isset($_files[0]) && !empty($_files[0])) {
                //go through all files, check for existance and add to the zip file
                foreach ($_files[0] as $_file) {
                    $o = $_file;
                    $_file = str_replace(array('"', "'", $s), '', $_file);
                    //check if video or image
                    $use_path = $path_assets;
                    $use_path_raw = $path_assets_raw;
                    preg_match('/.*?.(?:jpg|jpeg|gif|png)/i', $_file, $match);
                    preg_match('/.*?.(?:ogv|webm|mp4)/i', $_file, $match2);
                    $f = false;
                    if (!empty($match) && isset($match[0]) && !empty($match[0])) {
                        //image
                        $use_path = $path_assets;
                        $use_path_raw = $path_assets_raw;
                        $f = true;
                    }
                    if (!empty($match2) && isset($match2[0]) && !empty($match2[0])) {
                        //video
                        $use_path = $path_assets_vid;
                        $use_path_raw = $path_assets_raw_vid;
                        $f = true;
                    }
                    if ($f == false) {
                        //no file, just a location. So change the location accordingly by removing base and add ../../revolution
                        if (strpos($o, 'public/assets/js/') !== false) {
                            //this will be the jsFileLocation script part
                            $slider_html = str_replace($o, '"' . $path_js . '"', $slider_html);
                        }
                        continue;
                        //no correct file, nothing to add
                    }
                    if (isset($added[$_file])) {
                        continue;
                    }
                    $add = '';
                    $__file = '';
                    $repl_to = explode('/', $_file);
                    $repl_to = end($repl_to);
                    $remove = false;
                    if (is_file($upload_dir . $_file)) {
                        $zip->addFile($upload_dir . $_file, $use_path_raw . '/' . $repl_to);
                        $remove = true;
                    } elseif (is_file($upload_dir_multisiteless . $_file)) {
                        $zip->addFile($upload_dir_multisiteless . $_file, $use_path_raw . '/' . $repl_to);
                        $remove = true;
                    } elseif (is_file(RS_PLUGIN_PATH . $_file)) {
                        //remove admin/assets/
                        $__file = str_replace('admin/assets/images/', '', $_file);
                        $zip->addFile(RS_PLUGIN_PATH . $_file, $use_path_raw . '/' . $__file);
                        $remove = true;
                        $add = '/';
                    }
                    if ($remove == true) {
                        $added[$_file] = true;
                        //set as added
                        //replace file with new path
                        if ($add !== '') {
                            $_file = $__file;
                        }
                        //set the different path here
                        $slider_html = str_replace($o, '"' . $use_path . '/' . $repl_to . '"', $slider_html);
                    }
                }
            }
        }
        if ($export_real) {
            //only include if real export
            //add common files to the zip
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/extensions/revolution.extension.actions.min.js', 'js/extensions/revolution.extension.actions.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/extensions/revolution.extension.carousel.min.js', 'js/extensions/revolution.extension.carousel.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/extensions/revolution.extension.kenburn.min.js', 'js/extensions/revolution.extension.kenburn.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/extensions/revolution.extension.layeranimation.min.js', 'js/extensions/revolution.extension.layeranimation.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/extensions/revolution.extension.migration.min.js', 'js/extensions/revolution.extension.migration.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/extensions/revolution.extension.navigation.min.js', 'js/extensions/revolution.extension.navigation.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/extensions/revolution.extension.parallax.min.js', 'js/extensions/revolution.extension.parallax.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/extensions/revolution.extension.slideanims.min.js', 'js/extensions/revolution.extension.slideanims.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/extensions/revolution.extension.video.min.js', 'js/extensions/revolution.extension.video.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/jquery.themepunch.enablelog.js', 'js/jquery.themepunch.enablelog.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/jquery.themepunch.revolution.min.js', 'js/jquery.themepunch.revolution.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/js/jquery.themepunch.tools.min.js', 'js/jquery.themepunch.tools.min.js');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/css/settings.css', 'css/settings.css');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/pe-icon-7-stroke/css/pe-icon-7-stroke.css', 'fonts/pe-icon-7-stroke/css/pe-icon-7-stroke.css');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/pe-icon-7-stroke/css/helper.css', 'fonts/pe-icon-7-stroke/css/helper.css');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/pe-icon-7-stroke/fonts/Pe-icon-7-stroke.eot', 'fonts/pe-icon-7-stroke/fonts/Pe-icon-7-stroke.eot');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/pe-icon-7-stroke/fonts/Pe-icon-7-stroke.svg', 'fonts/pe-icon-7-stroke/fonts/Pe-icon-7-stroke.svg');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/pe-icon-7-stroke/fonts/Pe-icon-7-stroke.ttf', 'fonts/pe-icon-7-stroke/fonts/Pe-icon-7-stroke.ttf');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/pe-icon-7-stroke/fonts/Pe-icon-7-stroke.woff', 'fonts/pe-icon-7-stroke/fonts/Pe-icon-7-stroke.woff');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/font-awesome/css/font-awesome.min.css', 'fonts/font-awesome/css/font-awesome.min.css');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/font-awesome/fonts/FontAwesome.otf', 'fonts/font-awesome/fonts/FontAwesome.otf');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/font-awesome/fonts/fontawesome-webfont.eot', 'fonts/font-awesome/fonts/fontawesome-webfont.eot');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/font-awesome/fonts/fontawesome-webfont.svg', 'fonts/font-awesome/fonts/fontawesome-webfont.svg');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/font-awesome/fonts/fontawesome-webfont.ttf', 'fonts/font-awesome/fonts/fontawesome-webfont.ttf');
            $zip->addFile(RS_PLUGIN_PATH . '/public/assets/fonts/font-awesome/fonts/fontawesome-webfont.woff', 'fonts/font-awesome/fonts/fontawesome-webfont.woff');
            $notice_text = "";
            $notice_text .= __('Using this data is only allowed with a valid licence of the jQuery Slider Revolution Plugin, which can be found at CodeCanyon: http://codecanyon.net/item/slider-revolution-responsive-jquery-plugin/2580848?ref=themepunch', REVSLIDER_TEXTDOMAIN);
            $zip->addFromString("NOTICE.txt", $notice_text);
            //add slider settings
        }
        $zip->addFromString("slider.html", $slider_html);
        //add slider settings
        $zip->close();
        header("Content-type: application/zip");
        header("Content-Disposition: attachment; filename=" . sanitize_title($slider->getAlias()) . ".zip");
        header("Pragma: no-cache");
        header("Expires: 0");
        readfile(RevSliderGlobals::$uploadsUrlExportZip);
        @unlink(RevSliderGlobals::$uploadsUrlExportZip);
        //delete file after sending it to user
        exit;
    }
Esempio n. 4
0
 /**
  * 
  * export slider from data, output a file for download
  */
 public function exportSlider($useDummy = false)
 {
     $this->validateInited();
     $sliderParams = $this->getParamsForExport();
     $arrSlides = $this->getSlidesForExport($useDummy);
     $arrStaticSlide = $this->getStaticSlideForExport($useDummy);
     $usedCaptions = array();
     $usedAnimations = array();
     $usedImages = array();
     $usedSVG = array();
     $usedVideos = array();
     $usedNavigations = array();
     $cfw = array();
     if (!empty($arrSlides) && count($arrSlides) > 0) {
         $cfw = array_merge($cfw, $arrSlides);
     }
     if (!empty($arrStaticSlide) && count($arrStaticSlide) > 0) {
         $cfw = array_merge($cfw, $arrStaticSlide);
     }
     //remove image_id as it is not needed in export
     //plus remove background image if solid color or transparent
     if (!empty($arrSlides)) {
         foreach ($arrSlides as $k => $s) {
             if (isset($arrSlides[$k]['params']['image_id'])) {
                 unset($arrSlides[$k]['params']['image_id']);
             }
             if (isset($arrSlides[$k]['params']["background_type"]) && ($arrSlides[$k]['params']["background_type"] == 'solid' || $arrSlides[$k]['params']["background_type"] == "trans" || $arrSlides[$k]['params']["background_type"] == "transparent")) {
                 if (isset($arrSlides[$k]['params']['background_image'])) {
                     $arrSlides[$k]['params']['background_image'] = '';
                 }
             }
         }
     }
     if (!empty($arrStaticSlide)) {
         foreach ($arrStaticSlide as $k => $s) {
             if (isset($arrStaticSlide[$k]['params']['image_id'])) {
                 unset($arrStaticSlide[$k]['params']['image_id']);
             }
             if (isset($arrStaticSlide[$k]['params']["background_type"]) && ($arrStaticSlide[$k]['params']["background_type"] == 'solid' || $arrStaticSlide[$k]['params']["background_type"] == "trans" || $arrStaticSlide[$k]['params']["background_type"] == "transparent")) {
                 if (isset($arrStaticSlide[$k]['params']['background_image'])) {
                     $arrStaticSlide[$k]['params']['background_image'] = '';
                 }
             }
         }
     }
     if (!empty($cfw) && count($cfw) > 0) {
         foreach ($cfw as $key => $slide) {
             //check if we are transparent and so on
             if (isset($slide['params']['image']) && $slide['params']['image'] != '') {
                 $usedImages[$slide['params']['image']] = true;
             }
             //['params']['image'] background url
             if (isset($slide['params']['background_image']) && $slide['params']['background_image'] != '') {
                 $usedImages[$slide['params']['background_image']] = true;
             }
             //['params']['image'] background url
             if (isset($slide['params']['slide_thumb']) && $slide['params']['slide_thumb'] != '') {
                 $usedImages[$slide['params']['slide_thumb']] = true;
             }
             //['params']['image'] background url
             //html5 video
             if (isset($slide['params']['background_type']) && $slide['params']['background_type'] == 'html5') {
                 if (isset($slide['params']['slide_bg_html_mpeg']) && $slide['params']['slide_bg_html_mpeg'] != '') {
                     $usedVideos[$slide['params']['slide_bg_html_mpeg']] = true;
                 }
                 if (isset($slide['params']['slide_bg_html_webm']) && $slide['params']['slide_bg_html_webm'] != '') {
                     $usedVideos[$slide['params']['slide_bg_html_webm']] = true;
                 }
                 if (isset($slide['params']['slide_bg_html_ogv']) && $slide['params']['slide_bg_html_ogv'] != '') {
                     $usedVideos[$slide['params']['slide_bg_html_ogv']] = true;
                 }
             } else {
                 if (isset($slide['params']['slide_bg_html_mpeg']) && $slide['params']['slide_bg_html_mpeg'] != '') {
                     $slide['params']['slide_bg_html_mpeg'] = '';
                 }
                 if (isset($slide['params']['slide_bg_html_webm']) && $slide['params']['slide_bg_html_webm'] != '') {
                     $slide['params']['slide_bg_html_webm'] = '';
                 }
                 if (isset($slide['params']['slide_bg_html_ogv']) && $slide['params']['slide_bg_html_ogv'] != '') {
                     $slide['params']['slide_bg_html_ogv'] = '';
                 }
             }
             //image thumbnail
             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 (isset($layer['type']) && ($layer['type'] == 'video' || $layer['type'] == 'audio')) {
                         $video_data = isset($layer['video_data']) ? (array) $layer['video_data'] : array();
                         if (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] == 'html5') {
                             if (isset($video_data['urlPoster']) && $video_data['urlPoster'] != '') {
                                 $usedImages[$video_data['urlPoster']] = true;
                             }
                             if (isset($video_data['urlMp4']) && $video_data['urlMp4'] != '') {
                                 $usedVideos[$video_data['urlMp4']] = true;
                             }
                             if (isset($video_data['urlWebm']) && $video_data['urlWebm'] != '') {
                                 $usedVideos[$video_data['urlWebm']] = true;
                             }
                             if (isset($video_data['urlOgv']) && $video_data['urlOgv'] != '') {
                                 $usedVideos[$video_data['urlOgv']] = true;
                             }
                         } elseif (!empty($video_data) && isset($video_data['video_type']) && $video_data['video_type'] != 'html5') {
                             //video cover image
                             if ($video_data['video_type'] == 'audio') {
                                 if (isset($video_data['urlAudio']) && $video_data['urlAudio'] != '') {
                                     $usedVideos[$video_data['urlAudio']] = true;
                                 }
                             } else {
                                 if (isset($video_data['previewimage']) && $video_data['previewimage'] != '') {
                                     $usedImages[$video_data['previewimage']] = true;
                                 }
                             }
                         }
                         if ($video_data['video_type'] != 'html5') {
                             $video_data['urlMp4'] = '';
                             $video_data['urlWebm'] = '';
                             $video_data['urlOgv'] = '';
                         }
                         if ($video_data['video_type'] != 'audio') {
                             $video_data['urlAudio'] = '';
                         }
                     }
                     if (isset($layer['type']) && $layer['type'] == 'svg') {
                         if (isset($layer['svg']) && isset($layer['svg']->src)) {
                             $usedSVG[$layer['svg']->src] = true;
                         }
                     }
                 }
             }
         }
     }
     $arrSliderExport = array("params" => $sliderParams, "slides" => $arrSlides);
     if (!empty($arrStaticSlide)) {
         $arrSliderExport['static_slides'] = $arrStaticSlide;
     }
     $strExport = serialize($arrSliderExport);
     //$strExportAnim = serialize(RevSliderOperations::getFullCustomAnimations());
     $exportname = !empty($this->alias) ? $this->alias . '.zip' : "slider_export.zip";
     //add navigations if not default animation
     if (isset($sliderParams['navigation_arrow_style'])) {
         $usedNavigations[$sliderParams['navigation_arrow_style']] = true;
     }
     if (isset($sliderParams['navigation_bullets_style'])) {
         $usedNavigations[$sliderParams['navigation_bullets_style']] = true;
     }
     if (isset($sliderParams['thumbnails_style'])) {
         $usedNavigations[$sliderParams['thumbnails_style']] = true;
     }
     if (isset($sliderParams['tabs_style'])) {
         $usedNavigations[$sliderParams['tabs_style']] = true;
     }
     $navs = false;
     if (!empty($usedNavigations)) {
         $navs = RevSliderNavigation::export_navigation($usedNavigations);
         if ($navs !== false) {
             $navs = serialize($navs);
         }
     }
     $styles = '';
     if (!empty($usedCaptions)) {
         $captions = array();
         foreach ($usedCaptions as $class => $val) {
             $cap = RevSliderOperations::getCaptionsContentArray($class);
             //set also advanced styles here...
             if (!empty($cap)) {
                 $captions[] = $cap;
             }
         }
         $styles = RevSliderCssParser::parseArrayToCss($captions, "\n", true);
     }
     $animations = '';
     if (!empty($usedAnimations)) {
         $animation = array();
         foreach ($usedAnimations as $anim => $val) {
             $anima = RevSliderOperations::getFullCustomAnimationByID($anim);
             if ($anima !== false) {
                 $animation[] = $anima;
             }
         }
         if (!empty($animation)) {
             $animations = serialize($animation);
         }
     }
     $usedImages = array_merge($usedImages, $usedVideos);
     $usepcl = false;
     if (class_exists('ZipArchive')) {
         $zip = new ZipArchive();
         $success = $zip->open(RevSliderGlobals::$uploadsUrlExportZip, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE);
         if ($success !== true) {
             throwError("Can't create zip file: " . RevSliderGlobals::$uploadsUrlExportZip);
         }
     } else {
         //fallback to pclzip
         require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
         $pclzip = new PclZip(RevSliderGlobals::$uploadsUrlExportZip);
         //either the function uses die() or all is cool
         $usepcl = true;
     }
     //add svg to the zip
     if (!empty($usedSVG)) {
         $content_url = content_url();
         $content_path = ABSPATH . 'wp-content';
         $ud = wp_upload_dir();
         $up_dir = $ud['baseurl'];
         foreach ($usedSVG as $file => $val) {
             if (strpos($file, 'http') !== false) {
                 //remove all up to wp-content folder
                 $checkpath = str_replace($content_url, '', $file);
                 $checkpath2 = str_replace($up_dir, '', $file);
                 if ($checkpath2 === $file) {
                     //we have an SVG like whiteboard, fallback to older export
                     $checkpath2 = $checkpath;
                 }
                 if (is_file($content_path . $checkpath)) {
                     $strExport = str_replace($file, str_replace('/revslider/assets/svg', '', $checkpath2), $strExport);
                 }
             }
         }
     }
     //add images to zip
     if (!empty($usedImages)) {
         $upload_dir = RevSliderFunctionsWP::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) {
                     $remove = false;
                     $checkpath = str_replace(array($cont_url, $cont_url_no_www), '', $file);
                     if (is_file($upload_dir . $checkpath)) {
                         if (!$usepcl) {
                             $zip->addFile($upload_dir . $checkpath, 'images/' . $checkpath);
                         } else {
                             $v_list = $pclzip->add($upload_dir . $checkpath, PCLZIP_OPT_REMOVE_PATH, $upload_dir, PCLZIP_OPT_ADD_PATH, 'images/');
                         }
                         $remove = true;
                     } elseif (is_file($upload_dir_multisiteless . $checkpath)) {
                         if (!$usepcl) {
                             $zip->addFile($upload_dir_multisiteless . $checkpath, 'images/' . $checkpath);
                         } else {
                             $v_list = $pclzip->add($upload_dir_multisiteless . $checkpath, PCLZIP_OPT_REMOVE_PATH, $upload_dir_multisiteless, PCLZIP_OPT_ADD_PATH, 'images/');
                         }
                         $remove = true;
                     }
                     if ($remove) {
                         //as its http, remove this from strexport
                         $strExport = str_replace(array($cont_url . $checkpath, $cont_url_no_www . $checkpath), $checkpath, $strExport);
                     }
                 } else {
                     if (is_file($upload_dir . $file)) {
                         if (!$usepcl) {
                             $zip->addFile($upload_dir . $file, 'images/' . $file);
                         } else {
                             $v_list = $pclzip->add($upload_dir . $file, PCLZIP_OPT_REMOVE_PATH, $upload_dir, PCLZIP_OPT_ADD_PATH, 'images/');
                         }
                     } elseif (is_file($upload_dir_multisiteless . $file)) {
                         if (!$usepcl) {
                             $zip->addFile($upload_dir_multisiteless . $file, 'images/' . $file);
                         } else {
                             $v_list = $pclzip->add($upload_dir_multisiteless . $file, PCLZIP_OPT_REMOVE_PATH, $upload_dir_multisiteless, PCLZIP_OPT_ADD_PATH, 'images/');
                         }
                     }
                 }
             }
         }
     }
     if (!$usepcl) {
         $zip->addFromString("slider_export.txt", $strExport);
         //add slider settings
     } else {
         $list = $pclzip->add(array(array(PCLZIP_ATT_FILE_NAME => 'slider_export.txt', PCLZIP_ATT_FILE_CONTENT => $strExport)));
         if ($list == 0) {
             die("ERROR : '" . $pclzip->errorInfo(true) . "'");
         }
     }
     if (strlen(trim($animations)) > 0) {
         if (!$usepcl) {
             $zip->addFromString("custom_animations.txt", $animations);
             //add custom animations
         } else {
             $list = $pclzip->add(array(array(PCLZIP_ATT_FILE_NAME => 'custom_animations.txt', PCLZIP_ATT_FILE_CONTENT => $animations)));
             if ($list == 0) {
                 die("ERROR : '" . $pclzip->errorInfo(true) . "'");
             }
         }
     }
     if (strlen(trim($styles)) > 0) {
         if (!$usepcl) {
             $zip->addFromString("dynamic-captions.css", $styles);
             //add dynamic styles
         } else {
             $list = $pclzip->add(array(array(PCLZIP_ATT_FILE_NAME => 'dynamic-captions.css', PCLZIP_ATT_FILE_CONTENT => $styles)));
             if ($list == 0) {
                 die("ERROR : '" . $pclzip->errorInfo(true) . "'");
             }
         }
     }
     if (strlen(trim($navs)) > 0) {
         if (!$usepcl) {
             $zip->addFromString("navigation.txt", $navs);
             //add dynamic styles
         } else {
             $list = $pclzip->add(array(array(PCLZIP_ATT_FILE_NAME => 'navigation.txt', PCLZIP_ATT_FILE_CONTENT => $navs)));
             if ($list == 0) {
                 die("ERROR : '" . $pclzip->errorInfo(true) . "'");
             }
         }
     }
     $static_css = RevSliderOperations::getStaticCss();
     if (trim($static_css) !== '') {
         if (!$usepcl) {
             $zip->addFromString("static-captions.css", $static_css);
             //add slider settings
         } else {
             $list = $pclzip->add(array(array(PCLZIP_ATT_FILE_NAME => 'static-captions.css', PCLZIP_ATT_FILE_CONTENT => $static_css)));
             if ($list == 0) {
                 die("ERROR : '" . $pclzip->errorInfo(true) . "'");
             }
         }
     }
     $enable_slider_pack = apply_filters('revslider_slider_pack_export', false);
     if ($enable_slider_pack) {
         //allow for slider packs the automatic creation of the info.cfg
         if (!$usepcl) {
             $zip->addFromString('info.cfg', md5($this->alias));
             //add slider settings
         } else {
             $list = $pclzip->add(array(array(PCLZIP_ATT_FILE_NAME => 'info.cfg', PCLZIP_ATT_FILE_CONTENT => md5($this->alias))));
             if ($list == 0) {
                 die("ERROR : '" . $pclzip->errorInfo(true) . "'");
             }
         }
     }
     if (!$usepcl) {
         $zip->close();
     } else {
         //do nothing
     }
     header("Content-type: application/zip");
     header("Content-Disposition: attachment; filename=" . $exportname);
     header("Pragma: no-cache");
     header("Expires: 0");
     readfile(RevSliderGlobals::$uploadsUrlExportZip);
     @unlink(RevSliderGlobals::$uploadsUrlExportZip);
     //delete file after sending it to user
     exit;
 }