"\t"
]);
include LS_ROOT_PATH.'/classes/class.ls.exportutil.php';
$zip = new LS_ExportUtil;
// Fetch slider data
$slider = LS_Sliders::find( $sliderID );
// Get saved project draft if any
if( $draft = LS_Sliders::getDraft( $sliderID ) ) {
$slider['data'] = $draft['data'];
}
// Override some slider settings
$slider['data']['properties']['useSrcset'] = false;
// Use alternate image URLs
remove_all_filters('wp_get_attachment_image_src');
add_filter('wp_get_attachment_image_src', function( $image ) {
if( ! empty( $image[0] ) ) {
$image[0] = 'images/'.basename($image[0]);
}
return $image;
});
// Use alternate image URLs in the init code
add_filter('layerslider_init_props_image', function( $src ) {
return 'images/'.basename( $src );
});
add_filter('layerslider_skin_url', function( $url, $skin ) {
return '../../layerslider/skins/'.$skin;
}, 10, 2);
add_filter('layerslider_attr_list', function( $attrs ) {
return implode(' ', $attrs);
});
add_filter( 'layerslider_init_props_separator', function( $value ) {
return "[[LN]]";
});
// Generate the markup
$parts = LS_Shortcode::generateSliderMarkup( $slider );
$template = file_get_contents( LS_ROOT_PATH.'/templates/html-export/template.html' );
// Replace slider ID
$parts['container'] = str_replace('layerslider_'.$sliderID.'' , 'slider', $parts['container'] );
// Format the markup with perfect indentations to elimiate the
// effect of concatenation.
$markup = $indenter->indent( $parts['container'].$parts['markup'] );
// Add an extra tab for the formatted markup, so it matches
// perfectly to the template structure.
$markup = str_replace("\n", "\r\n\t", $markup);
// Add extra line breaks between slides
$markup = str_replace('
"];
foreach( $parts['fonts'] as $font ) {
// FontAwesome
if( $font === 'font-awesome-4' ) {
$tmp[] = '
'."\r\n\t";
}
}
$iconFonts = implode("\r\n\t", $tmp);
}
// LayerSlider plugin files
$pluginFiles = '';
if( ! empty( $parts['plugins'] ) ) {
$tmp = ["\r\n\t"];
foreach( $parts['plugins'] as $plugin ) {
$tmp[] = '
';
$tmp[] = ''."\r\n\t";
}
$pluginFiles = implode("\r\n\t", $tmp);
}
// LayerSlider API
$sliderAPI = '';
if( ! empty( $slider['data']['callbacks'] ) && is_array( $slider['data']['callbacks'] ) ) {
$apiPart[] = "$('#slider')";
foreach( $slider['data']['callbacks'] as $event => $function) {
$function = substr($function, 0, -1 ) . "\r\n}";
$function = preg_replace( '/^/m', "\t\t\t", stripslashes( $function ) );
$function = ltrim( $function );
$apiPart[] .= '.on(\''.$event.'\', '.$function.')';
}
$sliderAPI = implode('', $apiPart).";\r\n\r\n";
}
// Replace placeholders
$template = str_replace( '{{slider-title}}', $slider['name'], $template );
$template = str_replace( '{{icon-fonts}}', $iconFonts, $template );
$template = str_replace( '{{layerslider-plugins}}', $pluginFiles, $template );
$template = str_replace( '{{slider-markup}}', $markup, $template );
$template = str_replace( '{{slider-api}}', $sliderAPI, $template);
$template = str_replace( '{{slider-props}}', $init, $template );
// Add extra line breaks between slides
$template = str_replace( '
\r\n\t\t".'
getImagesForSlider( $slider['data'] );
$images = $zip->getFSPaths( $images );
$zip->addImage( $images, $name, 'images', true );
// Add slider HTML file
$zip->addFileFromString( "$name/slider.html", $template);
// Add instructions
$zip->addFile( LS_ROOT_PATH.'/templates/html-export/INSTRUCTIONS.html', "$name/" );
$zip->addImage( LS_ROOT_PATH.'/templates/html-export/ls-instructions.png', "$name", 'images', true);
$zip->download( 'LayerSlider HTML - '.$name.' '.ls_date('Y-m-d').' at '.ls_date('H.i.s').'.zip');
die();