PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / trunk
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel vtrunk
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / classes / zip.php
wp-all-export / classes Last commit date
partner-discount-sdk 2 months ago CdataStrategy.php 2 months ago CdataStrategyAlways.php 2 months ago CdataStrategyFactory.php 2 months ago CdataStrategyIllegalCharacters.php 2 months ago CdataStrategyIllegalCharactersHtmlEntities.php 2 months ago CdataStrategyNever.php 2 months ago XMLWriter.php 2 months ago chunk.php 2 months ago config.php 3 years ago download.php 2 months ago handler.php 2 months ago helper.php 2 months ago input.php 2 months ago installer.php 2 months ago session.php 11 years ago wpallimport.php 2 months ago zip.php 4 years ago
zip.php
73 lines
1 <?php
2
3 if ( ! class_exists('PMXE_Zip')){
4
5 class PMXE_Zip
6 {
7 /**
8 * Add files and sub-directories in a folder to zip file.
9 * @param string $folder
10 * @param ZipArchive|PclZip $zipFile
11 * @param int $exclusiveLength Number of text to be exclusived from the file path.
12 */
13 private static function folderToZip($folder, &$zipFile, $exclusiveLength, $type = 'zip', $removePath = '') {
14 $handle = opendir($folder);
15 if($handle !== false) {
16 while (false !== $f = readdir($handle)) {
17 if ($f != '.' && $f != '..') {
18 $filePath = "$folder/$f";
19 // Remove prefix from file path before add to zip.
20 $localPath = substr($filePath, $exclusiveLength);
21 // Fall back to PclZip if ZipArchive is unavailable.
22 if( 'zip' === $type ) {
23 if ( is_file( $filePath ) ) {
24 $zipFile->addFile( $filePath, $localPath );
25 } elseif ( is_dir( $filePath ) ) {
26 // Add sub-directory.
27 $zipFile->addEmptyDir( $localPath );
28 self::folderToZip( $filePath, $zipFile, $exclusiveLength );
29 }
30 }else{
31 if( is_file($filePath)) {
32 $zipFile->add( $filePath, '', $removePath );
33 }
34 }
35 }
36 }
37 closedir($handle);
38 }
39 }
40
41 /**
42 * Zip a folder (include itself).
43 * Usage:
44 * PMXE_Zip::zipDir('/path/to/sourceDir', '/path/to/out.zip');
45 *
46 * @param string $sourcePath Path of directory to be zip.
47 * @param string $outZipPath Path of output zip file.
48 */
49 public static function zipDir($sourcePath, $outZipPath)
50 {
51 $pathInfo = pathInfo($sourcePath);
52 $parentPath = $pathInfo['dirname'];
53 $dirName = $pathInfo['basename'];
54
55 // Fall back to PclZip if ZipArchive is unavailable.
56 if(class_exists('ZipArchive')){
57 $z = new ZipArchive();
58 $z->open($outZipPath, ZIPARCHIVE::CREATE);
59 $z->addEmptyDir($dirName);
60 self::folderToZip($sourcePath, $z, strlen("$parentPath/"));
61 $z->close();
62 }else{
63 require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
64
65 $z = new PclZip($outZipPath);
66 self::folderToZip($sourcePath, $z, strlen("$parentPath/"), 'pcl', $parentPath);
67
68
69 }
70 }
71 }
72
73 }