1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
<?php
// Check ZipArchive if( ! class_exists('ZipArchive') ) { wp_die( __('The PHP ZipArchive extension is required to export sliders.', 'LayerSlider') ); }
if( ! LS_Config::isActivatedSite() ) { wp_die( __('Product activation is required in order to use this feature.', 'LayerSlider') ); }
// Get dindent include LS_ROOT_PATH.'/static/dindent/Indenter.php'; $indenter = new \Gajus\Dindent\Indenter( array( 'indentation_character' => "\t" ));
include LS_ROOT_PATH.'/classes/class.ls.exportutil.php'; $zip = new LS_ExportUtil;
// Fetch slider data $slider = LS_Sliders::find( $sliderID );
// Override some slider settings $slider['data']['properties']['useSrcset'] = false;
// Use alternate image URLs add_filter('wp_get_attachment_image_attributes', function( $attrs ) { $attrs['src'] = 'images/'.basename($attrs['src']); return $attrs; });
// 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('<div class="ls-slide"', "\r\n\t\t".'<div class="ls-slide"', $markup);
// Capture slider settings from the init code preg_match('/.layerSlider\({(.*?)}/', $parts['init'], $matches);
// Format slider properties for use in the init code $init = implode(",\r\n\t\t\t\t", explode('[[LN]]', $matches[1]) );
// Google Fonts $googleFonts = ''; $fonts = $zip->fontsForSlider( $slider['data'] ); if( ! empty( $fonts ) ) {
foreach( $fonts as $font ) { $googleFont[] = htmlspecialchars( $font['param'] ); }
$fontFamily = implode('|', $googleFont ); $googleFonts = "\r\n\t<!-- Google Fonts -->\r\n\t".'<link rel="stylesheet" href="https://fonts.googleapis.com/css?family='.$fontFamily.'">'."\r\n\t";
}
// Icon Fonts $iconFonts = ''; if( ! empty( $parts['fonts'] ) ) { $tmp = array("\r\n\t<!-- Icon Fonts -->"); foreach( $parts['fonts'] as $font ) {
// FontAwesome if( $font === 'font-awesome' ) {
$tmp[] = '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">'."\r\n\t"; } }
$iconFonts = implode("\r\n\t", $tmp); }
// LayerSlider plugin files $pluginFiles = ''; if( ! empty( $parts['plugins'] ) ) {
$tmp = array("\r\n\t<!-- LayerSlider plugin files -->"); foreach( $parts['plugins'] as $plugin ) { $tmp[] = '<link rel="stylesheet" href="../../layerslider/plugins/'.$plugin.'/layerslider.'.$plugin.'.css">'; $tmp[] = '<script src="../../layerslider/plugins/'.$plugin.'/layerslider.'.$plugin.'.js"></script>'."\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( '{{google-fonts}}', $googleFonts, $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( '<div class="ls-slide"', "\r\n\t\t".'<div class="ls-slide"', $template );
// Add explanation comment before slides $count = 1; $template = preg_replace_callback('/<div class\=\"ls-slide\"/', function( $matches ) use (&$count) { return "<!-- Slide ".$count++."-->\r\n\t\t".'<div class="ls-slide"'; }, $template);
// Remove 'fitvidsignore' $template = str_replace( ' class="ls-wp-container fitvidsignore"', '', $template );
// Build ZIP
// Add slider folder $name = empty( $slider['name'] ) ? 'slider_' . $slider['id'] : $slider['name']; $name = sanitize_file_name( $name );
// Add images $images = $zip->getImagesForSlider( $slider['data'] ); $images = $zip->getFSPaths( $images ); $zip->addImage( $images, $name, 'images' );
// 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');
$zip->download( 'LayerSlider HTML - '.$name.' '.date('Y-m-d').' at '.date('H.i.s').'.zip'); die();
|