Export Media Library - Version 2.2.0

Version Description

  • added support for PHP 7.0
Download this release

Release Info

Developer andrej.pavlovic
Plugin Icon wp plugin Export Media Library
Version 2.2.0
Comparing to
See all releases

Code changes from version 1.1.0 to 2.2.0

composer.json CHANGED
@@ -1,12 +1,16 @@
1
  {
2
  "name": "massedge/wordpress-plugin-export-media-library",
3
  "description": "Wordpress plugin that allows admins to export media library files as a compressed zip archive.",
4
- "version": "1.1.0",
5
  "type": "wordpress-plugin",
6
  "license": "GPL-3.0",
 
 
 
 
7
  "require": {
8
- "php": ">=5.6",
9
- "maennchen/zipstream-php": "0.4.1"
10
  },
11
  "autoload": {
12
  "psr-4": {"": "lib/"}
1
  {
2
  "name": "massedge/wordpress-plugin-export-media-library",
3
  "description": "Wordpress plugin that allows admins to export media library files as a compressed zip archive.",
4
+ "version": "2.2.0",
5
  "type": "wordpress-plugin",
6
  "license": "GPL-3.0",
7
+ "repositories": [{
8
+ "type": "vcs",
9
+ "url": "https://github.com/massedge/ZipStream-PHP"
10
+ }],
11
  "require": {
12
+ "php": ">=7.0",
13
+ "maennchen/zipstream-php": "dev-php-7.0-compatibility"
14
  },
15
  "autoload": {
16
  "psr-4": {"": "lib/"}
composer.lock CHANGED
@@ -4,28 +4,33 @@
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
  "This file is @generated automatically"
6
  ],
7
- "content-hash": "a853daad251f8773c406fcc9f1e7a7a0",
8
  "packages": [
9
  {
10
  "name": "maennchen/zipstream-php",
11
- "version": "v0.4.1",
12
  "source": {
13
  "type": "git",
14
- "url": "https://github.com/maennchen/ZipStream-PHP.git",
15
- "reference": "89e0cdb3c9ecabef4da988852003781a7802afb7"
16
  },
17
  "dist": {
18
  "type": "zip",
19
- "url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/89e0cdb3c9ecabef4da988852003781a7802afb7",
20
- "reference": "89e0cdb3c9ecabef4da988852003781a7802afb7",
21
  "shasum": ""
22
  },
23
  "require": {
24
  "ext-mbstring": "*",
25
- "php": ">= 5.6"
 
 
26
  },
27
  "require-dev": {
28
- "phpunit/phpunit": "4.3.*"
 
 
 
29
  },
30
  "type": "library",
31
  "autoload": {
@@ -33,7 +38,6 @@
33
  "ZipStream\\": "src/"
34
  }
35
  },
36
- "notification-url": "https://packagist.org/downloads/",
37
  "license": [
38
  "MIT"
39
  ],
@@ -42,13 +46,17 @@
42
  "name": "Paul Duncan",
43
  "email": "pabs@pablotron.org"
44
  },
 
 
 
 
45
  {
46
  "name": "Jesse Donat",
47
  "email": "donatj@gmail.com"
48
  },
49
  {
50
- "name": "Jonatan Männchen",
51
- "email": "jonatan@maennchen.ch"
52
  }
53
  ],
54
  "description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.",
@@ -56,17 +64,117 @@
56
  "stream",
57
  "zip"
58
  ],
59
- "time": "2016-09-13T10:29:17+00:00"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  }
61
  ],
62
  "packages-dev": [],
63
  "aliases": [],
64
  "minimum-stability": "stable",
65
- "stability-flags": [],
 
 
66
  "prefer-stable": false,
67
  "prefer-lowest": false,
68
  "platform": {
69
- "php": ">=5.6"
70
  },
71
  "platform-dev": []
72
  }
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
  "This file is @generated automatically"
6
  ],
7
+ "content-hash": "fe9624c85f0ff41a34d7c72e43c77f72",
8
  "packages": [
9
  {
10
  "name": "maennchen/zipstream-php",
11
+ "version": "dev-php-7.0-compatibility",
12
  "source": {
13
  "type": "git",
14
+ "url": "https://github.com/massedge/ZipStream-PHP.git",
15
+ "reference": "9b0f04a9f158454dd579d11bff191427e4de0525"
16
  },
17
  "dist": {
18
  "type": "zip",
19
+ "url": "https://api.github.com/repos/massedge/ZipStream-PHP/zipball/9b0f04a9f158454dd579d11bff191427e4de0525",
20
+ "reference": "9b0f04a9f158454dd579d11bff191427e4de0525",
21
  "shasum": ""
22
  },
23
  "require": {
24
  "ext-mbstring": "*",
25
+ "myclabs/php-enum": "^1.5",
26
+ "php": ">= 7.0",
27
+ "psr/http-message": "^1.0"
28
  },
29
  "require-dev": {
30
+ "ext-zip": "*",
31
+ "guzzlehttp/guzzle": ">= 6.3",
32
+ "mikey179/vfsstream": "^1.6",
33
+ "phpunit/phpunit": "^4.0"
34
  },
35
  "type": "library",
36
  "autoload": {
38
  "ZipStream\\": "src/"
39
  }
40
  },
 
41
  "license": [
42
  "MIT"
43
  ],
46
  "name": "Paul Duncan",
47
  "email": "pabs@pablotron.org"
48
  },
49
+ {
50
+ "name": "Jonatan Männchen",
51
+ "email": "jonatan@maennchen.ch"
52
+ },
53
  {
54
  "name": "Jesse Donat",
55
  "email": "donatj@gmail.com"
56
  },
57
  {
58
+ "name": "András Kolesár",
59
+ "email": "kolesar@kolesar.hu"
60
  }
61
  ],
62
  "description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.",
64
  "stream",
65
  "zip"
66
  ],
67
+ "support": {
68
+ "source": "https://github.com/massedge/ZipStream-PHP/tree/dev-php-7.0-compatibility"
69
+ },
70
+ "time": "2019-04-30T19:51:44+00:00"
71
+ },
72
+ {
73
+ "name": "myclabs/php-enum",
74
+ "version": "1.6.6",
75
+ "source": {
76
+ "type": "git",
77
+ "url": "https://github.com/myclabs/php-enum.git",
78
+ "reference": "32c4202886c51fbe5cc3a7c34ec5c9a4a790345e"
79
+ },
80
+ "dist": {
81
+ "type": "zip",
82
+ "url": "https://api.github.com/repos/myclabs/php-enum/zipball/32c4202886c51fbe5cc3a7c34ec5c9a4a790345e",
83
+ "reference": "32c4202886c51fbe5cc3a7c34ec5c9a4a790345e",
84
+ "shasum": ""
85
+ },
86
+ "require": {
87
+ "ext-json": "*",
88
+ "php": ">=5.4"
89
+ },
90
+ "require-dev": {
91
+ "phpunit/phpunit": "^4.8.35|^5.7|^6.0",
92
+ "squizlabs/php_codesniffer": "1.*"
93
+ },
94
+ "type": "library",
95
+ "autoload": {
96
+ "psr-4": {
97
+ "MyCLabs\\Enum\\": "src/"
98
+ }
99
+ },
100
+ "notification-url": "https://packagist.org/downloads/",
101
+ "license": [
102
+ "MIT"
103
+ ],
104
+ "authors": [
105
+ {
106
+ "name": "PHP Enum contributors",
107
+ "homepage": "https://github.com/myclabs/php-enum/graphs/contributors"
108
+ }
109
+ ],
110
+ "description": "PHP Enum implementation",
111
+ "homepage": "http://github.com/myclabs/php-enum",
112
+ "keywords": [
113
+ "enum"
114
+ ],
115
+ "time": "2019-02-04T21:18:49+00:00"
116
+ },
117
+ {
118
+ "name": "psr/http-message",
119
+ "version": "1.0.1",
120
+ "source": {
121
+ "type": "git",
122
+ "url": "https://github.com/php-fig/http-message.git",
123
+ "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
124
+ },
125
+ "dist": {
126
+ "type": "zip",
127
+ "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
128
+ "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
129
+ "shasum": ""
130
+ },
131
+ "require": {
132
+ "php": ">=5.3.0"
133
+ },
134
+ "type": "library",
135
+ "extra": {
136
+ "branch-alias": {
137
+ "dev-master": "1.0.x-dev"
138
+ }
139
+ },
140
+ "autoload": {
141
+ "psr-4": {
142
+ "Psr\\Http\\Message\\": "src/"
143
+ }
144
+ },
145
+ "notification-url": "https://packagist.org/downloads/",
146
+ "license": [
147
+ "MIT"
148
+ ],
149
+ "authors": [
150
+ {
151
+ "name": "PHP-FIG",
152
+ "homepage": "http://www.php-fig.org/"
153
+ }
154
+ ],
155
+ "description": "Common interface for HTTP messages",
156
+ "homepage": "https://github.com/php-fig/http-message",
157
+ "keywords": [
158
+ "http",
159
+ "http-message",
160
+ "psr",
161
+ "psr-7",
162
+ "request",
163
+ "response"
164
+ ],
165
+ "time": "2016-08-06T14:39:51+00:00"
166
  }
167
  ],
168
  "packages-dev": [],
169
  "aliases": [],
170
  "minimum-stability": "stable",
171
+ "stability-flags": {
172
+ "maennchen/zipstream-php": 20
173
+ },
174
  "prefer-stable": false,
175
  "prefer-lowest": false,
176
  "platform": {
177
+ "php": ">=7.0"
178
  },
179
  "platform-dev": []
180
  }
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Export Media Library
4
  Plugin URI: https://github.com/massedge/wordpress-plugin-export-media-library
5
  Description: Allows admins to export media library files as a compressed zip archive.
6
- Version: 1.1.0
7
  Author: Mass Edge Inc.
8
  Author URI: https://www.massedge.com/
9
  License: GPL3
3
  Plugin Name: Export Media Library
4
  Plugin URI: https://github.com/massedge/wordpress-plugin-export-media-library
5
  Description: Allows admins to export media library files as a compressed zip archive.
6
+ Version: 2.2.0
7
  Author: Mass Edge Inc.
8
  Author URI: https://www.massedge.com/
9
  License: GPL3
lib/DependencyCheck.php CHANGED
@@ -3,7 +3,7 @@
3
  class MassEdgeWordPressPluginExportMediaLibraryDependencyCheck {
4
  const PLUGIN_NAME = 'Export Media Library';
5
 
6
- const MINIMUM_PHP_VERSION_REQUIRED = '5.6';
7
 
8
  const MBSTRING_EXTENSION_NAME = 'mbstring';
9
 
3
  class MassEdgeWordPressPluginExportMediaLibraryDependencyCheck {
4
  const PLUGIN_NAME = 'Export Media Library';
5
 
6
+ const MINIMUM_PHP_VERSION_REQUIRED = '7.0';
7
 
8
  const MBSTRING_EXTENSION_NAME = 'mbstring';
9
 
lib/MassEdge/WordPress/Plugin/ExportMediaLibrary/API.php CHANGED
@@ -3,6 +3,10 @@
3
  namespace MassEdge\WordPress\Plugin\ExportMediaLibrary;
4
 
5
  use ZipStream\ZipStream;
 
 
 
 
6
 
7
  class API {
8
  const FOLDER_STRUCTURE_NESTED = 'nested';
@@ -42,11 +46,15 @@ class API {
42
  // ensure path doesn't end in slash
43
  if ($options['root_path']) $options['root_path'] = rtrim($options['root_path'], '/\\');
44
 
 
 
 
 
 
45
  // create a new zipstream object
46
- $zip = new ZipStream($options['filename'], [
47
- // WORKAROUND: treat each file as large in order to use STORE method, thereby avoiding compression
48
- ZipStream::OPTION_LARGE_FILE_SIZE => ($options['compress']) ? 20 * 1024 * 1024 : 1,
49
- ]);
50
 
51
  $query = new \WP_Query();
52
  $attachmentIds = $query->query($options['query_args']);
@@ -111,9 +119,17 @@ class API {
111
 
112
  // skip attachment if result not specified
113
  if (!$result || empty($result['name']) || empty($result['path'])) continue;
 
 
 
 
 
 
 
 
114
 
115
  try {
116
- $zip->addFileFromPath($result['name'], $result['path'], $result['options']);
117
  } catch (\Exception $ex) {
118
  $options['add_attachment_failed_callback']([
119
  'name' => $result['name'],
@@ -129,8 +145,16 @@ class API {
129
 
130
  // give opportunity to add extra files before finishing the stream
131
  $options['add_extra_files_callback']([
132
- 'add_file_callback' => function($name, $path, array $options = []) use ($zip) {
133
- return $zip->addFileFromPath($name, $path, $options);
 
 
 
 
 
 
 
 
134
  },
135
  ]);
136
 
3
  namespace MassEdge\WordPress\Plugin\ExportMediaLibrary;
4
 
5
  use ZipStream\ZipStream;
6
+ use ZipStream\File as ZipFile;
7
+ use ZipStream\Option\Archive as ArchiveOptions;
8
+ use ZipStream\Option\File as FileOptions;
9
+ use ZipStream\Option\Method as MethodOptions;
10
 
11
  class API {
12
  const FOLDER_STRUCTURE_NESTED = 'nested';
46
  // ensure path doesn't end in slash
47
  if ($options['root_path']) $options['root_path'] = rtrim($options['root_path'], '/\\');
48
 
49
+ // compression method
50
+ $compressionMethod = new MethodOptions(
51
+ ($options['compress']) ? MethodOptions::DEFLATE : MethodOptions::STORE
52
+ );
53
+
54
  // create a new zipstream object
55
+ $archiveOptions = new ArchiveOptions();
56
+ $archiveOptions->setSendHttpHeaders(true);
57
+ $zip = new ZipStream($options['filename'], $archiveOptions);
 
58
 
59
  $query = new \WP_Query();
60
  $attachmentIds = $query->query($options['query_args']);
119
 
120
  // skip attachment if result not specified
121
  if (!$result || empty($result['name']) || empty($result['path'])) continue;
122
+
123
+ $fileOptions = new FileOptions();
124
+ $fileOptions->defaultTo($archiveOptions);
125
+ if (!$options['compress']) $fileOptions->setMethod($compressionMethod);
126
+ if (!empty($result['options']['time'])) {
127
+ $date = new \DateTime('@' . $result['options']['time']);
128
+ $fileOptions->setTime($date);
129
+ }
130
 
131
  try {
132
+ $zip->addFileFromPath($result['name'], $result['path'], $fileOptions);
133
  } catch (\Exception $ex) {
134
  $options['add_attachment_failed_callback']([
135
  'name' => $result['name'],
145
 
146
  // give opportunity to add extra files before finishing the stream
147
  $options['add_extra_files_callback']([
148
+ 'add_file_callback' => function($name, $path, array $options = []) use ($zip, $archiveOptions, $compressionMethod) {
149
+ $fileOptions = new FileOptions();
150
+ $fileOptions->defaultTo($archiveOptions);
151
+ $fileOptions->setMethod($compressionMethod);
152
+ if (!empty($options['time'])) {
153
+ $date = new \DateTime('@' . $options['time']);
154
+ $fileOptions->setTime($date);
155
+ }
156
+
157
+ $zip->addFileFromPath($name, $path, $fileOptions);
158
  },
159
  ]);
160
 
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: andrej.pavlovic
3
  Tags: export media library, download media library, media library, export, download
4
  Requires at least: 4.7.10
5
- Tested up to: 4.9.6
6
- Requires PHP: 5.6
7
- Stable tag: 1.1.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -26,6 +26,16 @@ Allows users to export media library files as a compressed zip archive.
26
 
27
  == Changelog ==
28
 
 
 
 
 
 
 
 
 
 
 
29
  = 1.1.0 =
30
  * expose API::export function for easier reuse by 3rd-party code
31
  * set last modify time for each file in zip to match the timestamp on disk
2
  Contributors: andrej.pavlovic
3
  Tags: export media library, download media library, media library, export, download
4
  Requires at least: 4.7.10
5
+ Tested up to: 5.2
6
+ Requires PHP: 7.0
7
+ Stable tag: 2.2.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
26
 
27
  == Changelog ==
28
 
29
+ = 2.2.0 =
30
+ * added support for PHP 7.0
31
+
32
+ = 2.1.0 =
33
+ * composer - maennchen/zipstream-php - bumped to version 1.1
34
+
35
+ = 2.0.0 =
36
+ * bumped minimum php version to 7.1
37
+ * updated zipstream library
38
+
39
  = 1.1.0 =
40
  * expose API::export function for easier reuse by 3rd-party code
41
  * set last modify time for each file in zip to match the timestamp on disk