C:\xampp\htdocs\landing\wp-content\plugins\LayerSlider\classes\class.ls.exportutil.php


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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php

/**
 * Class for working with ZIP archives to export
 * sliders with images and other attachments.
 *
 * @package LS_ExportUtil
 * @since 5.0.3
 * @author John Gera
 * @copyright Copyright (c) 2013  John Gera, George Krupa, and Kreatura Media Kft.
 * @license http://codecanyon.net/licenses/faq Envato marketplace licenses
 */

class LS_ExportUtil {

    
/**
     * The managed ZipArchieve instance.
     */
    
private $zip;

    
/**
     * A temporary file in /wp-content/uploads/ to manipulate
     * ZIPs on the fly without permanently saving to file system.
     */
    
private $file;


    
/**
     * Holds used image URLs in slider to be exported
     */
    
private $imageList;


    
/**
     * Prepares a ZipArchieve instance and the file system
     * to work with the class.
     *
     * @since 5.0.3
     * @access public
     * @return void
     */
    
public function __construct() {

        
// Check for ZipArchieve
        
if(class_exists('ZipArchive')) {

            
// Temporary directory for file operations
            
$upload_dir wp_upload_dir();
            
$tmp_dir $upload_dir['basedir'];

            
// Prepare ZIP to work with
            
$this->file tempnam($tmp_dir"zip");
            
$this->zip = new ZipArchive;
            
$this->zip->open($this->fileZIPARCHIVE::CREATE ZIPARCHIVE::OVERWRITE);
        }
    }


    
/**
     * Adds slider settings .json file to ZIP
     *
     * @since 5.0.3
     * @access public
     * @param string $data Slider settings JSON
     * @return void
     */
    
public function addSettings($data$folder '') {
        
$folder = !empty($folder) ? $folder.'/' '';
        
$this->zip->addFromString($folder.'settings.json'$data);
    }


    
/**
     * Adds slider images to ZIP
     *
     * @since 5.0.3
     * @access public
     * @param mixed $files Image path or an array of image paths to be added
     * @param string $folder Sub-folder name
     * @param string $imgFolder Name of the folder that stores the images
     * @return void
     */
    
public function addImage($files$folder ''$imgFolder 'uploads') {

        
// Check file
        
if(empty($files)) { return false; }

        
// Check file type
        
if(!is_array($files)) { $files = array($files); }

        
// Check folder
        
$folder is_string($folder) ? $folder."/$imgFolder/" "$imgFolder/";

        
// Add contents to ZIP
        
foreach($files as $file) {
            if(!empty(
$file) && is_string($file)) {
                
$this->zip->addFile($file,
                    
$folder.sanitize_file_name(basename($file))
                );
            }
        }
    }


    
/**
     * Adds any kind of file to the export ZIP
     *
     * @since 6.6.3
     * @access public
     * @param mixed $file File path or an array of file paths to be added
     * @param string $path File location within the ZIP package
     * @return void
     */
    
public function addFile($files$path '/') {

        
// Check file
        
if(empty($files)) { return false; }

        
// Check file type
        
if(!is_array($files)) { $files = array($files); }

        
// Add contents to ZIP
        
foreach($files as $file) {
            if(!empty(
$file) && is_string($file)) {
                
$this->zip->addFile($file,
                    
$path.sanitize_file_name(basename($file))
                );
            }
        }
    }


    
/**
     * Adds any kind of file with the provided contents to the ZIP package.
     *
     * @since 5.0.3
     * @access public
     * @param string $data Slider settings JSON
     * @return void
     */
    
public function addFileFromString$path '/slider.html'$data '') {
        
$this->zip->addFromString($path$data);
    }


    
/**
     * Closes all pending operations and downloads the ZIP file.
     *
     * @since 5.0.3
     * @access public
     * @return void
     */
    
public function download$name false ) {

        
// Close ZIP operations
        
$this->zip->close();

        
// File name
        
if( empty( $name ) ) {
            
$name 'LayerSlider_Export_'.date('Y-m-d').'_at_'.date('H.i.s').'.zip';
        }

        
// Set headers and to user
        
header('Content-Type: application/zip');
        
header('Content-Disposition: attachment; filename="'.$name.'"');
        
header("Content-length: " filesize($this->file));
        
header('Pragma: no-cache');
        
header('Expires: 0');
        
readfile($this->file);

        
// Remove temporary file
        
unlink($this->file);
        die();
    }


    public function 
getImagesForSlider($data) {

        
// Array to hold image URLs
        
$this->imageList = array();

        
// Slider Preview
        
if( ! empty($data['meta'] ) ) {
            
$this->_addImageToList$data['meta'], 'previewId''preview' );
        }

        
$this->_addImageToList$data['properties'], 'backgroundimageId''backgroundimage' );
        
$this->_addImageToList$data['properties'], 'yourlogoId''yourlogo' );


        
// Slides
        
if(!empty($data['layers']) && is_array($data['layers'])) {
        foreach(
$data['layers'] as $slide) {

                if( ! empty( 
$slide['properties'] ) ) {
                    
$this->_addImageToList$slide['properties'], 'backgroundId''background' );
                    
$this->_addImageToList$slide['properties'], 'thumbnailId''thumbnail' );
                }


                
// Layers
                
if(!empty($slide['sublayers']) && is_array($slide['sublayers'])) {
                    foreach(
$slide['sublayers'] as $layer) {

                        
$this->_addImageToList$layer'imageId''image' );
                        
$this->_addImageToList$layer'posterId''poster' );
                        
$this->_addImageToList$layer'layerBackgroundId''layerBackground' );
                    }
                }
            }
        }

        return 
$this->imageList;
    }



    public function 
fontsForSlider$data ) {

        
$ret = array();
        
$usedFonts = array();
        
$googleFonts get_option('ls-google-fonts', array());

        if( !empty(
$data['layers']) && is_array($data['layers'])) {
            foreach(
$data['layers'] as $slide) {

                if( !empty(
$slide['sublayers']) && is_array($data['layers'])) {
                    foreach(
$slide['sublayers'] as $layer) {

                        if( !empty(
$layer['styles']) ) {

                            
// Ensure that magic quotes will not mess with JSON data
                            
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
                                
$layer['styles'] = stripslashes($layer['styles']);
                            }

                            
$styles = !empty($layer['styles']) ? json_decode(stripslashes($layer['styles']), true) : new stdClass;

                            if( !empty(
$styles['font-family']) ) {
                                
$families explode(','$styles['font-family']);
                                foreach( 
$families as $family ) {
                                    
$family trim$family" \"'\t\n\r\0\x0B");

                                    if( !empty(
$family) ) {
                                        
$usedFonts[] = strtolower($family);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        foreach( 
$googleFonts as $font ) {
            list(
$family$weights) = explode(':'$font['param']);
            
$family strtolowerstr_replace('+'' '$family) );

            if( 
array_search($family$usedFonts) !== false) {
                
$font['admin'] = false;
                
$ret[] = $font;
            }
        }

        return 
$ret;
    }


    public function 
getFSPaths($urls) {

        if(!empty(
$urls) && is_array($urls)) {

            
$paths         = array();
            
$upload     wp_upload_dir();
            
$uploadDir     basename($upload['basedir']);


            foreach(
$urls as $url) {

                
// Get URL relative to the uploads folder
                
$urlPath parse_url($urlPHP_URL_PATH);
                
$urlPath explode("/$uploadDir/"$urlPath);

                if( empty(
$urlPath[1]) ) {
                    continue;
                }

                
$urlPath $urlPath[1];

                
// Get file path
                
$filePath $upload['basedir'] .'/'$urlPath;
                
$filePath realpath($filePath);

                
// Add to array
                
if( file_exists($filePath) && is_file($filePath) ) {
                    
$paths[] = $filePath;
                }
            }

            return 
$paths;
        }

        return array();
    }

    protected function 
_addImageToList$data$idKey ''$urlKey '' ) {

        if( ! empty( 
$data$urlKey ] ) ) {
            
$src $data$urlKey ];
        }

        if( ! empty( 
$data$idKey ] ) ) {
            if( 
$result wp_get_attachment_image_url$data$idKey ], 'full' ) ) {
                
$src $result;
            }
        }

        if( ! empty( 
$src) ) {
            
$this->imageList[] = $src;
        }
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586