Version Description
- Show more information about compressed/uncompressed image sizes in details popup.
- Add compression details to image overview.
Download this release
Release Info
Developer | TinyPNG |
Plugin | Compress JPEG & PNG images |
Version | 1.7.2 |
Comparing to | |
See all releases |
Code changes from version 1.7.1 to 1.7.2
- README.md +1 -2
- config/Dockerfile-wordpress-37 +3 -3
- config/Dockerfile-wordpress-38 +3 -3
- config/Dockerfile-wordpress-39 +3 -3
- config/Dockerfile-wordpress-40 +3 -3
- config/Dockerfile-wordpress-41 +3 -3
- config/Dockerfile-wordpress-42 +3 -3
- config/Dockerfile-wordpress-43 +3 -3
- config/Dockerfile-wordpress-44 +15 -0
- readme.txt +7 -1
- src/class-tiny-metadata-image.php +121 -0
- src/class-tiny-metadata.php +100 -139
- src/class-tiny-plugin.php +26 -21
- src/class-tiny-settings.php +2 -2
- src/class-tiny-wp-base.php +4 -0
- src/scripts/admin.js +53 -40
- src/styles/admin.css +4 -0
- src/views/compress-details-processing.php +4 -3
- src/views/compress-details.php +97 -68
- test/helpers/setup.php +9 -14
- test/integration/BulkCompressIntegrationTest.php +1 -0
- test/integration/CompressIntegrationTest.php +76 -18
- test/integration/IntegrationTestCase.php +15 -1
- test/integration/SettingsIntegrationTest.php +25 -25
- test/unit/TinyMetadataImageTest.php +155 -0
- test/unit/TinyMetadataTest.php +27 -224
- test/unit/TinyPluginTest.php +10 -10
- test/unit/TinyTestCase.php +5 -0
- test/unit/TinyWpBaseTest.php +2 -1
- tiny-compress-images.php +2 -1
README.md
CHANGED
@@ -21,7 +21,6 @@ Got questions or feedback? Let us know! Contact us at support@tinypng.com.
|
|
21 |
* Composer (https://getcomposer.org/download/).
|
22 |
* PhantomJS 2.1 or greater (http://phantomjs.org).
|
23 |
* MySQL client and admin tools.
|
24 |
-
* Java runtime.
|
25 |
|
26 |
### Running the plugin in WordPress
|
27 |
1. Run `bin/run-wordpress <version>`. E.g. `bin/run-wordpress 41`.
|
@@ -31,7 +30,7 @@ Got questions or feedback? Let us know! Contact us at support@tinypng.com.
|
|
31 |
1. Run `bin/unit-tests`.
|
32 |
|
33 |
### Running the integration tests
|
34 |
-
1. Start PhantomJS server: `phantomjs --
|
35 |
2. Run `bin/integration-tests $version [$to_version]` (When $to_version is
|
36 |
added, all versions between $version and $to_version are tested). E.g.
|
37 |
`bin/integration-tests 41` or `bin/integration-tests 40 42`.
|
21 |
* Composer (https://getcomposer.org/download/).
|
22 |
* PhantomJS 2.1 or greater (http://phantomjs.org).
|
23 |
* MySQL client and admin tools.
|
|
|
24 |
|
25 |
### Running the plugin in WordPress
|
26 |
1. Run `bin/run-wordpress <version>`. E.g. `bin/run-wordpress 41`.
|
30 |
1. Run `bin/unit-tests`.
|
31 |
|
32 |
### Running the integration tests
|
33 |
+
1. Start PhantomJS server: `phantomjs --wd`. Tested with version 2.1.1.
|
34 |
2. Run `bin/integration-tests $version [$to_version]` (When $to_version is
|
35 |
added, all versions between $version and $to_version are tested). E.g.
|
36 |
`bin/integration-tests 41` or `bin/integration-tests 40 42`.
|
config/Dockerfile-wordpress-37
CHANGED
@@ -2,9 +2,9 @@ FROM wordpress:4
|
|
2 |
|
3 |
RUN docker-php-ext-install mysql
|
4 |
|
5 |
-
ENV WORDPRESS_VERSION 3.7.
|
6 |
-
ENV WORDPRESS_UPSTREAM_VERSION 3.7.
|
7 |
-
ENV WORDPRESS_SHA1
|
8 |
|
9 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
10 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
2 |
|
3 |
RUN docker-php-ext-install mysql
|
4 |
|
5 |
+
ENV WORDPRESS_VERSION 3.7.13
|
6 |
+
ENV WORDPRESS_UPSTREAM_VERSION 3.7.13
|
7 |
+
ENV WORDPRESS_SHA1 24759237f867b284f2bad1154eaff6362a81512f
|
8 |
|
9 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
10 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
config/Dockerfile-wordpress-38
CHANGED
@@ -2,9 +2,9 @@ FROM wordpress:4
|
|
2 |
|
3 |
RUN docker-php-ext-install mysql
|
4 |
|
5 |
-
ENV WORDPRESS_VERSION 3.8.
|
6 |
-
ENV WORDPRESS_UPSTREAM_VERSION 3.8.
|
7 |
-
ENV WORDPRESS_SHA1
|
8 |
|
9 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
10 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
2 |
|
3 |
RUN docker-php-ext-install mysql
|
4 |
|
5 |
+
ENV WORDPRESS_VERSION 3.8.13
|
6 |
+
ENV WORDPRESS_UPSTREAM_VERSION 3.8.13
|
7 |
+
ENV WORDPRESS_SHA1 9fc98b9ee30f9437984e1bbef96d75d6c23e6950
|
8 |
|
9 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
10 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
config/Dockerfile-wordpress-39
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
FROM wordpress:4
|
2 |
|
3 |
-
ENV WORDPRESS_VERSION 3.9.
|
4 |
-
ENV WORDPRESS_UPSTREAM_VERSION 3.9.
|
5 |
-
ENV WORDPRESS_SHA1
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
1 |
FROM wordpress:4
|
2 |
|
3 |
+
ENV WORDPRESS_VERSION 3.9.11
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 3.9.11
|
5 |
+
ENV WORDPRESS_SHA1 8af7829f203cd410d9946f736324ca154b987389
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
config/Dockerfile-wordpress-40
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
FROM wordpress:4
|
2 |
|
3 |
-
ENV WORDPRESS_VERSION 4.0.
|
4 |
-
ENV WORDPRESS_UPSTREAM_VERSION 4.0.
|
5 |
-
ENV WORDPRESS_SHA1
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
1 |
FROM wordpress:4
|
2 |
|
3 |
+
ENV WORDPRESS_VERSION 4.0.10
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 4.0.10
|
5 |
+
ENV WORDPRESS_SHA1 a9e4d8cd92e211d55b40de3afd09efc5068ad483
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
config/Dockerfile-wordpress-41
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
FROM wordpress:4
|
2 |
|
3 |
-
ENV WORDPRESS_VERSION 4.1.
|
4 |
-
ENV WORDPRESS_UPSTREAM_VERSION 4.1.
|
5 |
-
ENV WORDPRESS_SHA1
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
1 |
FROM wordpress:4
|
2 |
|
3 |
+
ENV WORDPRESS_VERSION 4.1.10
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 4.1.10
|
5 |
+
ENV WORDPRESS_SHA1 dae2e813e0f824c12d3c79df8f5783bc7fa9e312
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
config/Dockerfile-wordpress-42
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
FROM wordpress:4
|
2 |
|
3 |
-
ENV WORDPRESS_VERSION 4.2.
|
4 |
-
ENV WORDPRESS_UPSTREAM_VERSION 4.2.
|
5 |
-
ENV WORDPRESS_SHA1
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
1 |
FROM wordpress:4
|
2 |
|
3 |
+
ENV WORDPRESS_VERSION 4.2.7
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 4.2.7
|
5 |
+
ENV WORDPRESS_SHA1 7e39a7cfc93ef54e02b91e4d9344040911f4128f
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
config/Dockerfile-wordpress-43
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
FROM wordpress:4
|
2 |
|
3 |
-
ENV WORDPRESS_VERSION 4.3.
|
4 |
-
ENV WORDPRESS_UPSTREAM_VERSION 4.3.
|
5 |
-
ENV WORDPRESS_SHA1
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
1 |
FROM wordpress:4
|
2 |
|
3 |
+
ENV WORDPRESS_VERSION 4.3.3
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 4.3.3
|
5 |
+
ENV WORDPRESS_SHA1 bf7a9281762e978712c6ab64ffdf64523abd6a33
|
6 |
|
7 |
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
config/Dockerfile-wordpress-44
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM wordpress:4
|
2 |
+
|
3 |
+
ENV WORDPRESS_VERSION 4.4.2
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 4.4.2
|
5 |
+
ENV WORDPRESS_SHA1 7444099fec298b599eb026e83227462bcdf312a6
|
6 |
+
|
7 |
+
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
|
8 |
+
RUN curl -o wordpress.tar.gz -sSL https://wordpress.org/wordpress-${WORDPRESS_UPSTREAM_VERSION}.tar.gz \
|
9 |
+
&& echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c - \
|
10 |
+
&& tar -xzf wordpress.tar.gz -C /usr/src/ \
|
11 |
+
&& rm wordpress.tar.gz \
|
12 |
+
&& chown -R www-data:www-data /usr/src/wordpress
|
13 |
+
|
14 |
+
ENTRYPOINT ["/entrypoint.sh"]
|
15 |
+
CMD ["apache2-foreground"]
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://tinypng.com/
|
|
4 |
Tags: optimize, compress, shrink, resize, faster, fit, scale, improve, images, tinypng, tinyjpg, jpeg, jpg, png, lossy, jpegmini, crunch, minify, smush, save, bandwidth, website, speed, performance, panda, wordpress app
|
5 |
Requires at least: 3.0.6
|
6 |
Tested up to: 4.5
|
7 |
-
Stable tag: 1.7.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -20,8 +20,10 @@ Make your website faster by optimizing your JPEG and PNG images. This plugin aut
|
|
20 |
* Optimize individual images already in your media library.
|
21 |
* Easy bulk optimization of your existing media library.
|
22 |
* Resize large original images by setting a maximum width and/or height.
|
|
|
23 |
* Select which thumbnail sizes of an image may be optimized.
|
24 |
* Multisite support with a single API key.
|
|
|
25 |
* See your usage from the media settings and during bulk optimization.
|
26 |
* Color profiles are automatically translated to the standard RGB color space.
|
27 |
* Convert CMYK to RGB to save more space and maximize compatibility.
|
@@ -102,6 +104,10 @@ A: Yes! After installing the plugin, go to *Media > Compress All Images*, and cl
|
|
102 |
|
103 |
== Changelog ==
|
104 |
|
|
|
|
|
|
|
|
|
105 |
= 1.7.1 =
|
106 |
* Option to preserve gps location and original creation date and time in your original JPEG images.
|
107 |
* Option to preserve coyright information in your original PNG images.
|
4 |
Tags: optimize, compress, shrink, resize, faster, fit, scale, improve, images, tinypng, tinyjpg, jpeg, jpg, png, lossy, jpegmini, crunch, minify, smush, save, bandwidth, website, speed, performance, panda, wordpress app
|
5 |
Requires at least: 3.0.6
|
6 |
Tested up to: 4.5
|
7 |
+
Stable tag: 1.7.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
20 |
* Optimize individual images already in your media library.
|
21 |
* Easy bulk optimization of your existing media library.
|
22 |
* Resize large original images by setting a maximum width and/or height.
|
23 |
+
* Preserve copyright metadata, creation date and GPS location in the original images.
|
24 |
* Select which thumbnail sizes of an image may be optimized.
|
25 |
* Multisite support with a single API key.
|
26 |
+
* WooCommerce compatible.
|
27 |
* See your usage from the media settings and during bulk optimization.
|
28 |
* Color profiles are automatically translated to the standard RGB color space.
|
29 |
* Convert CMYK to RGB to save more space and maximize compatibility.
|
104 |
|
105 |
== Changelog ==
|
106 |
|
107 |
+
= 1.7.2 =
|
108 |
+
* Show more information about compressed/uncompressed image sizes in details popup.
|
109 |
+
* Add compression details to image overview.
|
110 |
+
|
111 |
= 1.7.1 =
|
112 |
* Option to preserve gps location and original creation date and time in your original JPEG images.
|
113 |
* Option to preserve coyright information in your original PNG images.
|
src/class-tiny-metadata-image.php
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* Tiny Compress Images - WordPress plugin.
|
4 |
+
* Copyright (C) 2015-2016 Voormedia B.V.
|
5 |
+
*
|
6 |
+
* This program is free software; you can redistribute it and/or modify it
|
7 |
+
* under the terms of the GNU General Public License as published by the Free
|
8 |
+
* Software Foundation; either version 2 of the License, or (at your option)
|
9 |
+
* any later version.
|
10 |
+
*
|
11 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
13 |
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
14 |
+
* more details.
|
15 |
+
*
|
16 |
+
* You should have received a copy of the GNU General Public License along
|
17 |
+
* with this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
+
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
19 |
+
*/
|
20 |
+
|
21 |
+
class Tiny_Metadata_Image {
|
22 |
+
public $filename;
|
23 |
+
public $url;
|
24 |
+
public $meta;
|
25 |
+
|
26 |
+
/* Used more than once and not trivial, so we are memoizing these */
|
27 |
+
private $_exists;
|
28 |
+
private $_same_size;
|
29 |
+
|
30 |
+
public function __construct($filename=null, $url=null) {
|
31 |
+
$this->filename = $filename;
|
32 |
+
$this->url = $url;
|
33 |
+
}
|
34 |
+
|
35 |
+
public function end_time() {
|
36 |
+
if (!is_array($this->meta))
|
37 |
+
return null;
|
38 |
+
elseif (isset($this->meta['end']))
|
39 |
+
return $this->meta['end'];
|
40 |
+
elseif (isset($this->meta['timestamp']))
|
41 |
+
return $this->meta['timestamp'];
|
42 |
+
else
|
43 |
+
return null;
|
44 |
+
}
|
45 |
+
|
46 |
+
public function add_request() {
|
47 |
+
$this->meta = array('start' => time());
|
48 |
+
}
|
49 |
+
|
50 |
+
public function add_response($response) {
|
51 |
+
if (is_array($this->meta)) {
|
52 |
+
$this->meta = $response;
|
53 |
+
$this->meta['end'] = time();
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
public function add_exception($exception) {
|
58 |
+
if (is_array($this->meta)) {
|
59 |
+
$this->meta = array(
|
60 |
+
'error' => $exception->get_error(),
|
61 |
+
'message' => $exception->getMessage(),
|
62 |
+
'timestamp' => time()
|
63 |
+
);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
public function has_been_compressed() {
|
68 |
+
return is_array($this->meta) && isset($this->meta['output']);
|
69 |
+
}
|
70 |
+
|
71 |
+
public function never_compressed() {
|
72 |
+
return !$this->has_been_compressed();
|
73 |
+
}
|
74 |
+
|
75 |
+
public function filesize() {
|
76 |
+
return filesize($this->filename);
|
77 |
+
}
|
78 |
+
|
79 |
+
public function exists() {
|
80 |
+
if (is_null($this->_exists)) {
|
81 |
+
$this->_exists = $this->filename && file_exists($this->filename);
|
82 |
+
}
|
83 |
+
return $this->_exists;
|
84 |
+
}
|
85 |
+
|
86 |
+
private function same_size() {
|
87 |
+
if (is_null($this->_same_size)) {
|
88 |
+
$this->_same_size = $this->filesize() == $this->meta['output']['size'];
|
89 |
+
}
|
90 |
+
return $this->_same_size;
|
91 |
+
}
|
92 |
+
|
93 |
+
public function still_exists() {
|
94 |
+
return $this->has_been_compressed() && $this->exists();
|
95 |
+
}
|
96 |
+
|
97 |
+
public function missing() {
|
98 |
+
return $this->has_been_compressed() && !$this->exists();
|
99 |
+
}
|
100 |
+
|
101 |
+
public function compressed() {
|
102 |
+
return $this->still_exists() && $this->same_size();
|
103 |
+
}
|
104 |
+
|
105 |
+
public function modified() {
|
106 |
+
return $this->still_exists() && !$this->same_size();
|
107 |
+
}
|
108 |
+
|
109 |
+
public function uncompressed() {
|
110 |
+
return $this->exists() && !(isset($this->meta['output']) && $this->same_size());
|
111 |
+
}
|
112 |
+
|
113 |
+
public function in_progress() {
|
114 |
+
return is_array($this->meta) && isset($this->meta['start']) && !isset($this->meta['output']);
|
115 |
+
}
|
116 |
+
|
117 |
+
public function resized() {
|
118 |
+
return is_array($this->meta) && isset($this->meta['output']) && isset($this->meta['output']['resized'])
|
119 |
+
&& $this->meta['output']['resized'];
|
120 |
+
}
|
121 |
+
}
|
src/class-tiny-metadata.php
CHANGED
@@ -24,9 +24,11 @@ class Tiny_Metadata {
|
|
24 |
|
25 |
private $id;
|
26 |
private $name;
|
27 |
-
private $
|
28 |
-
|
29 |
-
|
|
|
|
|
30 |
|
31 |
public function __construct($id, $wp_metadata=null) {
|
32 |
$this->id = $id;
|
@@ -35,15 +37,20 @@ class Tiny_Metadata {
|
|
35 |
$wp_metadata = wp_get_attachment_metadata($id);
|
36 |
}
|
37 |
$this->parse_wp_metadata($wp_metadata);
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
}
|
42 |
}
|
43 |
|
44 |
private function parse_wp_metadata($wp_metadata) {
|
45 |
-
$this->filenames = array();
|
46 |
-
$this->urls = array();
|
47 |
if (!is_array($wp_metadata)) {
|
48 |
return;
|
49 |
}
|
@@ -59,8 +66,9 @@ class Tiny_Metadata {
|
|
59 |
|
60 |
$this->name = $path_info['basename'];
|
61 |
|
62 |
-
$this->
|
63 |
-
|
|
|
64 |
|
65 |
$unique_sizes = array();
|
66 |
if (isset($wp_metadata['sizes']) && is_array($wp_metadata['sizes'])) {
|
@@ -68,44 +76,44 @@ class Tiny_Metadata {
|
|
68 |
$filename = $info['file'];
|
69 |
|
70 |
if (!isset($unique_sizes[$filename])) {
|
71 |
-
$this->
|
72 |
-
|
73 |
-
$unique_sizes[$filename] = true;
|
74 |
}
|
75 |
}
|
76 |
}
|
77 |
}
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
public function update_wp_metadata($wp_metadata) {
|
80 |
-
$
|
81 |
-
if (
|
82 |
-
$wp_metadata
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
84 |
}
|
85 |
return $wp_metadata;
|
86 |
}
|
87 |
|
88 |
public function update() {
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
);
|
96 |
-
}
|
97 |
-
|
98 |
-
public function add_response($response, $size=self::ORIGINAL) {
|
99 |
-
$response['end'] = time();
|
100 |
-
$this->values[$size] = array_merge($this->values[$size], $response);
|
101 |
-
}
|
102 |
-
|
103 |
-
public function add_exception($exception, $size=self::ORIGINAL) {
|
104 |
-
$this->values[$size] = array(
|
105 |
-
'error' => $exception->get_error(),
|
106 |
-
'message' => $exception->getMessage(),
|
107 |
-
'timestamp' => time()
|
108 |
-
);
|
109 |
}
|
110 |
|
111 |
public function get_id() {
|
@@ -124,110 +132,65 @@ class Tiny_Metadata {
|
|
124 |
return get_post_mime_type($this->id);
|
125 |
}
|
126 |
|
127 |
-
public function
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
$value = $this->get_value($size);
|
141 |
-
if (array_key_exists("end", $value)) {
|
142 |
-
return $value["end"];
|
143 |
-
} else if (array_key_exists("timestamp", $value)) {
|
144 |
-
return $value["timestamp"];
|
145 |
}
|
|
|
|
|
|
|
146 |
}
|
147 |
|
148 |
-
public function
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
return $this->has_been_compressed($size) && $this->still_exists($size)
|
162 |
-
&& filesize($this->get_filename($size)) == $this->values[$size]['output']['size'];
|
163 |
-
}
|
164 |
-
|
165 |
-
public function is_compressing($size=self::ORIGINAL) {
|
166 |
-
$meta = $this->values[$size];
|
167 |
-
return isset($meta) && isset($meta['start']) && !isset($meta['output']);
|
168 |
-
}
|
169 |
-
|
170 |
-
public function is_resized($size=self::ORIGINAL) {
|
171 |
-
$meta = $this->values[$size];
|
172 |
-
return isset($meta) && isset($meta['output']) && isset($meta['output']['resized'])
|
173 |
-
&& $meta['output']['resized'];
|
174 |
-
}
|
175 |
-
|
176 |
-
public function get_sizes() {
|
177 |
-
return array_keys($this->filenames);
|
178 |
-
}
|
179 |
-
|
180 |
-
public function get_compressed_sizes() {
|
181 |
-
return array_filter(array_keys($this->values), array($this, 'has_been_compressed'));
|
182 |
-
}
|
183 |
-
|
184 |
-
public function get_success_sizes() {
|
185 |
-
return array_filter(array_keys($this->values), array($this, 'is_compressed'));
|
186 |
-
}
|
187 |
-
|
188 |
-
public function get_uncompressed_sizes($active_tinify_sizes) {
|
189 |
-
$sizes = array_intersect($this->get_sizes(), $active_tinify_sizes);
|
190 |
-
$uncompressed = array_diff($sizes, $this->get_success_sizes());
|
191 |
-
return array_filter($uncompressed, array($this, 'exists'));
|
192 |
-
}
|
193 |
-
|
194 |
-
public function get_not_compressed_active_sizes($active_tinify_sizes) {
|
195 |
-
$sizes = array_intersect($this->get_sizes(), $active_tinify_sizes);
|
196 |
-
return array_diff($sizes, $this->get_compressed_sizes());
|
197 |
-
}
|
198 |
-
|
199 |
-
public function get_in_progress_sizes() {
|
200 |
-
return array_filter(array_keys($this->values), array($this, 'is_compressing'));
|
201 |
-
}
|
202 |
-
|
203 |
-
public function get_success_count() {
|
204 |
-
return count($this->get_success_sizes());
|
205 |
-
}
|
206 |
-
|
207 |
-
public function get_in_progress_count() {
|
208 |
-
return count($this->get_in_progress_sizes());
|
209 |
-
}
|
210 |
-
|
211 |
-
public function get_compressed_count() {
|
212 |
-
return count($this->get_compressed_sizes());
|
213 |
-
}
|
214 |
-
|
215 |
-
public function get_missing_count() {
|
216 |
-
return count($this->get_compressed_sizes()) -
|
217 |
-
count(array_filter($this->get_compressed_sizes(), array($this, 'still_exists')));
|
218 |
}
|
219 |
|
220 |
-
public function
|
221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
}
|
223 |
|
224 |
public function get_latest_error() {
|
225 |
$last_time = null;
|
226 |
$message = null;
|
227 |
-
foreach ($this->
|
228 |
-
if (
|
229 |
-
|
230 |
-
|
|
|
|
|
231 |
}
|
232 |
}
|
233 |
return $message;
|
@@ -239,17 +202,15 @@ class Tiny_Metadata {
|
|
239 |
'output' => 0,
|
240 |
'count' => 0
|
241 |
);
|
242 |
-
foreach ($this->
|
243 |
-
if (
|
|
|
|
|
244 |
$result['count']++;
|
245 |
-
$result['input'] += $
|
246 |
-
$result['output'] += $
|
247 |
}
|
248 |
}
|
249 |
return $result;
|
250 |
}
|
251 |
-
|
252 |
-
public function is_resizable($size) {
|
253 |
-
return $size === self::ORIGINAL;
|
254 |
-
}
|
255 |
}
|
24 |
|
25 |
private $id;
|
26 |
private $name;
|
27 |
+
private $images = array();
|
28 |
+
|
29 |
+
public static function is_original($size) {
|
30 |
+
return $size === self::ORIGINAL;
|
31 |
+
}
|
32 |
|
33 |
public function __construct($id, $wp_metadata=null) {
|
34 |
$this->id = $id;
|
37 |
$wp_metadata = wp_get_attachment_metadata($id);
|
38 |
}
|
39 |
$this->parse_wp_metadata($wp_metadata);
|
40 |
+
|
41 |
+
$values = get_post_meta($this->id, self::META_KEY, true);
|
42 |
+
if (!is_array($values)) {
|
43 |
+
$values = array();
|
44 |
+
}
|
45 |
+
foreach ($values as $size => $meta) {
|
46 |
+
if (!isset($this->images[$size])) {
|
47 |
+
$this->images[$size] = new Tiny_Metadata_Image();
|
48 |
+
}
|
49 |
+
$this->images[$size]->meta = $meta;
|
50 |
}
|
51 |
}
|
52 |
|
53 |
private function parse_wp_metadata($wp_metadata) {
|
|
|
|
|
54 |
if (!is_array($wp_metadata)) {
|
55 |
return;
|
56 |
}
|
66 |
|
67 |
$this->name = $path_info['basename'];
|
68 |
|
69 |
+
$this->images[self::ORIGINAL] = new Tiny_Metadata_Image(
|
70 |
+
"$path_prefix${path_info['basename']}",
|
71 |
+
"$url_prefix${path_info['basename']}");
|
72 |
|
73 |
$unique_sizes = array();
|
74 |
if (isset($wp_metadata['sizes']) && is_array($wp_metadata['sizes'])) {
|
76 |
$filename = $info['file'];
|
77 |
|
78 |
if (!isset($unique_sizes[$filename])) {
|
79 |
+
$this->images[$size] = new Tiny_Metadata_Image(
|
80 |
+
"$path_prefix$filename", "$url_prefix$filename");
|
|
|
81 |
}
|
82 |
}
|
83 |
}
|
84 |
}
|
85 |
|
86 |
+
public function get_image($size=self::ORIGINAL, $create=false) {
|
87 |
+
if (isset($this->images[$size]))
|
88 |
+
return $this->images[$size];
|
89 |
+
elseif ($create)
|
90 |
+
return new Tiny_Metadata_Image();
|
91 |
+
else
|
92 |
+
return null;
|
93 |
+
}
|
94 |
+
|
95 |
public function update_wp_metadata($wp_metadata) {
|
96 |
+
$original = $this->get_image();
|
97 |
+
if (is_null($original) || !is_array($original->meta)) {
|
98 |
+
return $wp_metadata;
|
99 |
+
}
|
100 |
+
|
101 |
+
$m = $original->meta;
|
102 |
+
if (isset($m['output']) && isset($m['output']['width']) && isset($m['output']['height'])) {
|
103 |
+
$wp_metadata['width'] = $m['output']['width'];
|
104 |
+
$wp_metadata['height'] = $m['output']['height'];
|
105 |
}
|
106 |
return $wp_metadata;
|
107 |
}
|
108 |
|
109 |
public function update() {
|
110 |
+
$values = array();
|
111 |
+
foreach ($this->images as $size => $image) {
|
112 |
+
if (is_array($image->meta)) {
|
113 |
+
$values[$size] = $image->meta;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
update_post_meta($this->id, self::META_KEY, $values);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
}
|
118 |
|
119 |
public function get_id() {
|
132 |
return get_post_mime_type($this->id);
|
133 |
}
|
134 |
|
135 |
+
public function get_images() {
|
136 |
+
$original = isset($this->images[self::ORIGINAL])
|
137 |
+
? array(self::ORIGINAL => $this->images[self::ORIGINAL])
|
138 |
+
: array();
|
139 |
+
$compressed = array();
|
140 |
+
$uncompressed = array();
|
141 |
+
foreach ($this->images as $size => $image) {
|
142 |
+
if (self::is_original($size)) continue;
|
143 |
+
if ($image->has_been_compressed()) {
|
144 |
+
$compressed[$size] = $image;
|
145 |
+
} else {
|
146 |
+
$uncompressed[$size] = $image;
|
147 |
+
}
|
|
|
|
|
|
|
|
|
|
|
148 |
}
|
149 |
+
ksort($compressed);
|
150 |
+
ksort($uncompressed);
|
151 |
+
return $original + $compressed + $uncompressed;
|
152 |
}
|
153 |
|
154 |
+
public function filter_images($method, $sizes=null) {
|
155 |
+
$selection = array();
|
156 |
+
if (is_null($sizes)) {
|
157 |
+
$sizes = array_keys($this->images);
|
158 |
+
}
|
159 |
+
foreach ($sizes as $size) {
|
160 |
+
if (!isset($this->images[$size])) continue;
|
161 |
+
$image = $this->images[$size];
|
162 |
+
if ($image->$method()) {
|
163 |
+
$selection[$size] = $image;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
return $selection;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
}
|
168 |
|
169 |
+
public function get_count($methods, $sizes=null) {
|
170 |
+
$stats = array_fill_keys($methods, 0);
|
171 |
+
if (is_null($sizes)) {
|
172 |
+
$sizes = array_keys($this->images);
|
173 |
+
}
|
174 |
+
foreach ($sizes as $size) {
|
175 |
+
if (!isset($this->images[$size])) continue;
|
176 |
+
foreach ($methods as $method) {
|
177 |
+
if ($this->images[$size]->$method()) {
|
178 |
+
$stats[$method]++;
|
179 |
+
}
|
180 |
+
}
|
181 |
+
}
|
182 |
+
return $stats;
|
183 |
}
|
184 |
|
185 |
public function get_latest_error() {
|
186 |
$last_time = null;
|
187 |
$message = null;
|
188 |
+
foreach ($this->images as $size => $image) {
|
189 |
+
if (!is_array($image->meta)) continue;
|
190 |
+
$m = $image->meta;
|
191 |
+
if (isset($m['error']) && isset($m['message']) && ($last_time === null || $last_time < $m['timestamp'])) {
|
192 |
+
$last_time = $m['timestamp'];
|
193 |
+
$message = $m['message'];
|
194 |
}
|
195 |
}
|
196 |
return $message;
|
202 |
'output' => 0,
|
203 |
'count' => 0
|
204 |
);
|
205 |
+
foreach ($this->images as $size => $image) {
|
206 |
+
if (!is_array($image->meta)) continue;
|
207 |
+
$m = $image->meta;
|
208 |
+
if (isset($m['input']) && isset($m['output'])) {
|
209 |
$result['count']++;
|
210 |
+
$result['input'] += $m['input']['size'];
|
211 |
+
$result['output'] += $m['output']['size'];
|
212 |
}
|
213 |
}
|
214 |
return $result;
|
215 |
}
|
|
|
|
|
|
|
|
|
216 |
}
|
src/class-tiny-plugin.php
CHANGED
@@ -33,9 +33,6 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
33 |
parent::__construct();
|
34 |
|
35 |
$this->settings = new Tiny_Settings();
|
36 |
-
if (is_admin()) {
|
37 |
-
add_action('admin_menu', $this->get_method('admin_menu'));
|
38 |
-
}
|
39 |
}
|
40 |
|
41 |
public function set_compressor($compressor) {
|
@@ -52,6 +49,7 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
52 |
public function admin_init() {
|
53 |
add_filter('manage_media_columns', $this->get_method('add_media_columns'));
|
54 |
add_action('manage_media_custom_column', $this->get_method('render_media_column'), 10, 2);
|
|
|
55 |
add_action('wp_ajax_tiny_compress_image', $this->get_method('compress_image'));
|
56 |
add_action('admin_action_tiny_bulk_compress', $this->get_method('bulk_compress'));
|
57 |
add_action('admin_enqueue_scripts', $this->get_method('enqueue_scripts'));
|
@@ -112,22 +110,22 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
112 |
|
113 |
$compressor = $this->settings->get_compressor();
|
114 |
$active_tinify_sizes = $this->settings->get_active_tinify_sizes();
|
115 |
-
$
|
116 |
|
117 |
-
foreach ($
|
118 |
try {
|
119 |
-
$
|
120 |
$tiny_metadata->update();
|
121 |
|
122 |
-
$resize =
|
123 |
$preserve = count($this->settings->get_preserve_options()) > 0 ? $this->settings->get_preserve_options() : false;
|
124 |
-
$response = $compressor->compress_file($
|
125 |
|
126 |
-
$
|
127 |
$tiny_metadata->update();
|
128 |
$success++;
|
129 |
} catch (Tiny_Exception $e) {
|
130 |
-
$
|
131 |
$tiny_metadata->update();
|
132 |
$failed++;
|
133 |
}
|
@@ -140,6 +138,8 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
140 |
if (!empty($metadata)) {
|
141 |
list($tiny_metadata, $result) = $this->compress($metadata, $attachment_id);
|
142 |
return $tiny_metadata->update_wp_metadata($metadata);
|
|
|
|
|
143 |
}
|
144 |
}
|
145 |
|
@@ -172,7 +172,7 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
172 |
if ($json) {
|
173 |
$result['message'] = $tiny_metadata->get_latest_error();
|
174 |
$result['status'] = $this->settings->get_status();
|
175 |
-
$result['thumbnail'] = $tiny_metadata->
|
176 |
echo json_encode($result);
|
177 |
} else {
|
178 |
echo $this->render_compress_details($tiny_metadata);
|
@@ -204,21 +204,26 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
204 |
|
205 |
public function render_media_column($column, $id) {
|
206 |
if ($column === self::MEDIA_COLUMN) {
|
|
|
207 |
$this->render_compress_details(new Tiny_Metadata($id));
|
|
|
208 |
}
|
209 |
}
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
private function render_compress_details($tiny_metadata) {
|
212 |
-
$
|
213 |
-
$
|
214 |
-
$
|
215 |
-
$
|
216 |
-
$error = $tiny_metadata->get_latest_error();
|
217 |
-
$missing = $tiny_metadata->get_missing_count();
|
218 |
-
$modified = $tiny_metadata->get_modified_count();
|
219 |
-
$compressing = (count($uncompressed) > 0) ? count($uncompressed) : count($active);
|
220 |
-
|
221 |
-
if ($tiny_metadata->get_in_progress_count() > 0) {
|
222 |
include(dirname(__FILE__) . '/views/compress-details-processing.php');
|
223 |
} else {
|
224 |
include(dirname(__FILE__) . '/views/compress-details.php');
|
33 |
parent::__construct();
|
34 |
|
35 |
$this->settings = new Tiny_Settings();
|
|
|
|
|
|
|
36 |
}
|
37 |
|
38 |
public function set_compressor($compressor) {
|
49 |
public function admin_init() {
|
50 |
add_filter('manage_media_columns', $this->get_method('add_media_columns'));
|
51 |
add_action('manage_media_custom_column', $this->get_method('render_media_column'), 10, 2);
|
52 |
+
add_action('attachment_submitbox_misc_actions', $this->get_method('show_media_info'));
|
53 |
add_action('wp_ajax_tiny_compress_image', $this->get_method('compress_image'));
|
54 |
add_action('admin_action_tiny_bulk_compress', $this->get_method('bulk_compress'));
|
55 |
add_action('admin_enqueue_scripts', $this->get_method('enqueue_scripts'));
|
110 |
|
111 |
$compressor = $this->settings->get_compressor();
|
112 |
$active_tinify_sizes = $this->settings->get_active_tinify_sizes();
|
113 |
+
$uncompressed_images = $tiny_metadata->filter_images('uncompressed', $active_tinify_sizes);
|
114 |
|
115 |
+
foreach ($uncompressed_images as $size => $image) {
|
116 |
try {
|
117 |
+
$image->add_request();
|
118 |
$tiny_metadata->update();
|
119 |
|
120 |
+
$resize = Tiny_Metadata::is_original($size) ? $this->settings->get_resize_options() : false;
|
121 |
$preserve = count($this->settings->get_preserve_options()) > 0 ? $this->settings->get_preserve_options() : false;
|
122 |
+
$response = $compressor->compress_file($image->filename, $resize, $preserve);
|
123 |
|
124 |
+
$image->add_response($response);
|
125 |
$tiny_metadata->update();
|
126 |
$success++;
|
127 |
} catch (Tiny_Exception $e) {
|
128 |
+
$image->add_exception($e);
|
129 |
$tiny_metadata->update();
|
130 |
$failed++;
|
131 |
}
|
138 |
if (!empty($metadata)) {
|
139 |
list($tiny_metadata, $result) = $this->compress($metadata, $attachment_id);
|
140 |
return $tiny_metadata->update_wp_metadata($metadata);
|
141 |
+
} else {
|
142 |
+
return $metadata;
|
143 |
}
|
144 |
}
|
145 |
|
172 |
if ($json) {
|
173 |
$result['message'] = $tiny_metadata->get_latest_error();
|
174 |
$result['status'] = $this->settings->get_status();
|
175 |
+
$result['thumbnail'] = $tiny_metadata->get_image('thumbnail', true)->url;
|
176 |
echo json_encode($result);
|
177 |
} else {
|
178 |
echo $this->render_compress_details($tiny_metadata);
|
204 |
|
205 |
public function render_media_column($column, $id) {
|
206 |
if ($column === self::MEDIA_COLUMN) {
|
207 |
+
echo '<div class="tiny-ajax-container">';
|
208 |
$this->render_compress_details(new Tiny_Metadata($id));
|
209 |
+
echo '</div>';
|
210 |
}
|
211 |
}
|
212 |
|
213 |
+
public function show_media_info() {
|
214 |
+
global $post;
|
215 |
+
echo '<div class="misc-pub-section tiny-compress-images">';
|
216 |
+
echo '<h4>' . __('Compress JPEG & PNG Images', 'tiny-compress-images') . '</h4>';
|
217 |
+
echo '<div class="tiny-ajax-container">';
|
218 |
+
$this->render_compress_details(new Tiny_Metadata($post->ID));
|
219 |
+
echo '</div></div>';
|
220 |
+
}
|
221 |
+
|
222 |
private function render_compress_details($tiny_metadata) {
|
223 |
+
$available_sizes = array_keys($this->settings->get_sizes());
|
224 |
+
$active_tinify_sizes = $this->settings->get_active_tinify_sizes();
|
225 |
+
$in_progress = count($tiny_metadata->filter_images('in_progress'));
|
226 |
+
if ($in_progress > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
include(dirname(__FILE__) . '/views/compress-details-processing.php');
|
228 |
} else {
|
229 |
include(dirname(__FILE__) . '/views/compress-details.php');
|
src/class-tiny-settings.php
CHANGED
@@ -268,7 +268,7 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
268 |
$id = self::get_prefixed_name("sizes_$size");
|
269 |
$name = self::get_prefixed_name("sizes[$size]");
|
270 |
$checked = ( $option['tinify'] ? ' checked="checked"' : '' );
|
271 |
-
if ($size
|
272 |
$label = esc_html__('original', 'tiny-compress-images') . ' (' . esc_html__('overwritten by compressed image', 'tiny-compress-images') . ')';
|
273 |
} else {
|
274 |
$label = $size . ' - ' . $option['width'] . 'x' . $option['height'];
|
@@ -322,7 +322,7 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
322 |
$id = self::get_prefixed_name("resize_original_enabled");
|
323 |
$name = self::get_prefixed_name("resize_original[enabled]");
|
324 |
$checked = ( $this->get_resize_enabled() ? ' checked="checked"' : '' );
|
325 |
-
$label = esc_html__('Resize and compress the
|
326 |
|
327 |
echo '<p class="tiny-resize-available">';
|
328 |
echo '<input type="checkbox" id="' . $id . '" name="' . $name . '" value="on" '. $checked . '/>';
|
268 |
$id = self::get_prefixed_name("sizes_$size");
|
269 |
$name = self::get_prefixed_name("sizes[$size]");
|
270 |
$checked = ( $option['tinify'] ? ' checked="checked"' : '' );
|
271 |
+
if (Tiny_Metadata::is_original($size)) {
|
272 |
$label = esc_html__('original', 'tiny-compress-images') . ' (' . esc_html__('overwritten by compressed image', 'tiny-compress-images') . ')';
|
273 |
} else {
|
274 |
$label = $size . ' - ' . $option['width'] . 'x' . $option['height'];
|
322 |
$id = self::get_prefixed_name("resize_original_enabled");
|
323 |
$name = self::get_prefixed_name("resize_original[enabled]");
|
324 |
$checked = ( $this->get_resize_enabled() ? ' checked="checked"' : '' );
|
325 |
+
$label = esc_html__('Resize and compress the original image', 'tiny-compress-images');
|
326 |
|
327 |
echo '<p class="tiny-resize-available">';
|
328 |
echo '<input type="checkbox" id="' . $id . '" name="' . $name . '" value="on" '. $checked . '/>';
|
src/class-tiny-wp-base.php
CHANGED
@@ -68,6 +68,7 @@ abstract class Tiny_WP_Base {
|
|
68 |
add_action('init', $this->get_method('xmlrpc_init'));
|
69 |
} elseif (is_admin()) {
|
70 |
add_action('admin_init', $this->get_method('admin_init'));
|
|
|
71 |
}
|
72 |
}
|
73 |
|
@@ -95,4 +96,7 @@ abstract class Tiny_WP_Base {
|
|
95 |
|
96 |
public function admin_init() {
|
97 |
}
|
|
|
|
|
|
|
98 |
}
|
68 |
add_action('init', $this->get_method('xmlrpc_init'));
|
69 |
} elseif (is_admin()) {
|
70 |
add_action('admin_init', $this->get_method('admin_init'));
|
71 |
+
add_action('admin_menu', $this->get_method('admin_menu'));
|
72 |
}
|
73 |
}
|
74 |
|
96 |
|
97 |
public function admin_init() {
|
98 |
}
|
99 |
+
|
100 |
+
public function admin_menu() {
|
101 |
+
}
|
102 |
}
|
src/scripts/admin.js
CHANGED
@@ -6,9 +6,11 @@
|
|
6 |
|
7 |
function compress_image(event) {
|
8 |
var element = jQuery(event.target)
|
|
|
|
|
9 |
element.attr('disabled', 'disabled')
|
10 |
-
|
11 |
-
|
12 |
jQuery.ajax({
|
13 |
url: ajaxurl,
|
14 |
type: "POST",
|
@@ -18,11 +20,11 @@
|
|
18 |
id: element.data('id') || element.attr('data-id')
|
19 |
},
|
20 |
success: function(data) {
|
21 |
-
|
22 |
},
|
23 |
error: function() {
|
24 |
element.removeAttr('disabled')
|
25 |
-
|
26 |
}
|
27 |
})
|
28 |
}
|
@@ -137,12 +139,52 @@
|
|
137 |
bulk_compress_item(items, 0)
|
138 |
}
|
139 |
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
if (typeof jQuery.fn.on === "function") {
|
142 |
-
jQuery(
|
143 |
} else {
|
144 |
-
jQuery(
|
145 |
}
|
|
|
|
|
|
|
|
|
146 |
|
147 |
if (typeof jQuery.fn.prop === "function") {
|
148 |
jQuery('button.tiny-compress').prop('disabled', null)
|
@@ -152,9 +194,9 @@
|
|
152 |
|
153 |
jQuery('<option>').val('tiny_bulk_compress').text(tinyCompress.L10nBulkAction).appendTo('select[name="action"]')
|
154 |
jQuery('<option>').val('tiny_bulk_compress').text(tinyCompress.L10nBulkAction).appendTo('select[name="action2"]')
|
155 |
-
}
|
156 |
-
|
157 |
-
if (
|
158 |
jQuery('#tiny-compress-status').load(ajaxurl + '?action=tiny_compress_status')
|
159 |
jQuery('#tiny-compress-savings').load(ajaxurl + '?action=tiny_compress_savings')
|
160 |
|
@@ -168,37 +210,8 @@
|
|
168 |
jQuery('#tiny-image-sizes-notice').load(image_count_url)
|
169 |
})
|
170 |
|
171 |
-
function update_resize_settings() {
|
172 |
-
if (jQuery('#tinypng_sizes_0').prop('checked')) {
|
173 |
-
jQuery('.tiny-resize-available').show()
|
174 |
-
jQuery('.tiny-resize-unavailable').hide()
|
175 |
-
} else {
|
176 |
-
jQuery('.tiny-resize-available').hide()
|
177 |
-
jQuery('.tiny-resize-unavailable').show()
|
178 |
-
}
|
179 |
-
|
180 |
-
var elements = jQuery('#tinypng_resize_original_width, #tinypng_resize_original_height')
|
181 |
-
for (var i = 0; i < elements.length; i++) {
|
182 |
-
elements[i].disabled = !jQuery('#tinypng_resize_original_enabled').prop('checked')
|
183 |
-
}
|
184 |
-
}
|
185 |
-
|
186 |
-
function update_preserve_settings() {
|
187 |
-
if (jQuery('#tinypng_sizes_0').prop('checked')) {
|
188 |
-
jQuery('.tiny-preserve').show()
|
189 |
-
} else {
|
190 |
-
jQuery('.tiny-preserve').hide()
|
191 |
-
jQuery('#tinypng_preserve_data_copyright').attr('checked', false)
|
192 |
-
}
|
193 |
-
}
|
194 |
-
|
195 |
-
function update_settings() {
|
196 |
-
update_resize_settings()
|
197 |
-
update_preserve_settings()
|
198 |
-
}
|
199 |
-
|
200 |
-
|
201 |
jQuery('#tinypng_sizes_0, #tinypng_resize_original_enabled').click(update_settings)
|
|
|
202 |
}
|
203 |
|
204 |
jQuery('.tiny-notice a.tiny-dismiss').click(dismiss_notice)
|
6 |
|
7 |
function compress_image(event) {
|
8 |
var element = jQuery(event.target)
|
9 |
+
var container = element.closest('.tiny-ajax-container')
|
10 |
+
|
11 |
element.attr('disabled', 'disabled')
|
12 |
+
container.find('.spinner').removeClass('hidden')
|
13 |
+
container.find('span.dashicons').addClass('hidden')
|
14 |
jQuery.ajax({
|
15 |
url: ajaxurl,
|
16 |
type: "POST",
|
20 |
id: element.data('id') || element.attr('data-id')
|
21 |
},
|
22 |
success: function(data) {
|
23 |
+
container.html(data)
|
24 |
},
|
25 |
error: function() {
|
26 |
element.removeAttr('disabled')
|
27 |
+
container.find('.spinner').addClass('hidden')
|
28 |
}
|
29 |
})
|
30 |
}
|
139 |
bulk_compress_item(items, 0)
|
140 |
}
|
141 |
|
142 |
+
function update_resize_settings() {
|
143 |
+
if (jQuery('#tinypng_sizes_0').prop('checked')) {
|
144 |
+
jQuery('.tiny-resize-available').show()
|
145 |
+
jQuery('.tiny-resize-unavailable').hide()
|
146 |
+
} else {
|
147 |
+
jQuery('.tiny-resize-available').hide()
|
148 |
+
jQuery('.tiny-resize-unavailable').show()
|
149 |
+
}
|
150 |
+
|
151 |
+
var original_enabled = jQuery('#tinypng_resize_original_enabled').prop('checked')
|
152 |
+
jQuery('#tinypng_resize_original_width, #tinypng_resize_original_height').each(function (i, el) {
|
153 |
+
el.disabled = !original_enabled
|
154 |
+
})
|
155 |
+
}
|
156 |
+
|
157 |
+
function update_preserve_settings() {
|
158 |
+
if (jQuery('#tinypng_sizes_0').prop('checked')) {
|
159 |
+
jQuery('.tiny-preserve').show()
|
160 |
+
} else {
|
161 |
+
jQuery('.tiny-preserve').hide()
|
162 |
+
jQuery('#tinypng_preserve_data_creation').attr('checked', false)
|
163 |
+
jQuery('#tinypng_preserve_data_copyright').attr('checked', false)
|
164 |
+
jQuery('#tinypng_preserve_data_location').attr('checked', false)
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
function update_settings() {
|
169 |
+
update_resize_settings()
|
170 |
+
update_preserve_settings()
|
171 |
+
}
|
172 |
+
|
173 |
+
var adminpage = ""
|
174 |
+
if (typeof window.adminpage !== "undefined") {
|
175 |
+
adminpage = window.adminpage
|
176 |
+
}
|
177 |
+
|
178 |
+
function eventOn(parentSelector, event, eventSelector, callback) {
|
179 |
if (typeof jQuery.fn.on === "function") {
|
180 |
+
jQuery(parentSelector).on(event, eventSelector, callback)
|
181 |
} else {
|
182 |
+
jQuery(eventSelector).live(event, callback)
|
183 |
}
|
184 |
+
}
|
185 |
+
|
186 |
+
if (adminpage === "upload-php") {
|
187 |
+
eventOn('table', 'click', 'button.tiny-compress', compress_image)
|
188 |
|
189 |
if (typeof jQuery.fn.prop === "function") {
|
190 |
jQuery('button.tiny-compress').prop('disabled', null)
|
194 |
|
195 |
jQuery('<option>').val('tiny_bulk_compress').text(tinyCompress.L10nBulkAction).appendTo('select[name="action"]')
|
196 |
jQuery('<option>').val('tiny_bulk_compress').text(tinyCompress.L10nBulkAction).appendTo('select[name="action2"]')
|
197 |
+
} else if (adminpage === "post-php") {
|
198 |
+
eventOn('div.postbox-container div.tiny-compress-images', 'click', 'button.tiny-compress', compress_image)
|
199 |
+
} else if (adminpage === "options-media-php") {
|
200 |
jQuery('#tiny-compress-status').load(ajaxurl + '?action=tiny_compress_status')
|
201 |
jQuery('#tiny-compress-savings').load(ajaxurl + '?action=tiny_compress_savings')
|
202 |
|
210 |
jQuery('#tiny-image-sizes-notice').load(image_count_url)
|
211 |
})
|
212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
jQuery('#tinypng_sizes_0, #tinypng_resize_original_enabled').click(update_settings)
|
214 |
+
update_settings()
|
215 |
}
|
216 |
|
217 |
jQuery('.tiny-notice a.tiny-dismiss').click(dismiss_notice)
|
src/styles/admin.css
CHANGED
@@ -92,6 +92,10 @@
|
|
92 |
display: none;
|
93 |
}
|
94 |
|
|
|
|
|
|
|
|
|
95 |
#tiny-bulk-compress #media-items .bar.failed {
|
96 |
background-color: #DD3D36;
|
97 |
}
|
92 |
display: none;
|
93 |
}
|
94 |
|
95 |
+
.tiny-compress-images h4 {
|
96 |
+
margin: 0.5em 0;
|
97 |
+
}
|
98 |
+
|
99 |
#tiny-bulk-compress #media-items .bar.failed {
|
100 |
background-color: #DD3D36;
|
101 |
}
|
src/views/compress-details-processing.php
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
-
|
|
|
2 |
<div class="details">
|
3 |
<span class="icon spinner"></span>
|
4 |
<span class="message">
|
5 |
-
<strong><?php echo $
|
6 |
-
<span><?php echo _n('size being compressed', 'sizes being compressed', $
|
7 |
</span>
|
8 |
</div>
|
9 |
</div>
|
1 |
+
<?php
|
2 |
+
?><div class="details-container">
|
3 |
<div class="details">
|
4 |
<span class="icon spinner"></span>
|
5 |
<span class="message">
|
6 |
+
<strong><?php echo $in_progress ?></strong>
|
7 |
+
<span><?php echo _n('size being compressed', 'sizes being compressed', $in_progress, 'tiny-compress-images') ?></span>
|
8 |
</span>
|
9 |
</div>
|
10 |
</div>
|
src/views/compress-details.php
CHANGED
@@ -1,44 +1,54 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
<div class="details" id="tinify-compress-details">
|
3 |
<?php if ($tiny_metadata->can_be_compressed()) { ?>
|
4 |
<?php if ($error) { ?>
|
5 |
<span class="icon dashicons dashicons-warning error"></span>
|
6 |
-
<?php } else if ($missing > 0 || $modified > 0) { ?>
|
7 |
<span class="icon dashicons dashicons-yes alert"></span>
|
8 |
-
<?php } else if ($
|
9 |
<span class="icon dashicons dashicons-yes alert"></span>
|
10 |
-
<?php } else if ($
|
11 |
<span class="icon dashicons dashicons-yes success"></span>
|
12 |
<?php } ?>
|
13 |
<span class="icon spinner hidden"></span>
|
14 |
|
15 |
-
<?php if ($
|
16 |
<span class="message">
|
17 |
-
<strong><?php echo $
|
18 |
<span>
|
19 |
-
<?php echo htmlspecialchars(_n('size compressed', 'sizes compressed', $
|
20 |
</span>
|
21 |
</span>
|
22 |
<br/>
|
23 |
<?php } ?>
|
24 |
|
25 |
-
<?php if ($
|
26 |
<span class="message">
|
27 |
-
<?php echo htmlspecialchars(sprintf(_n('%d size not compressed', '%d sizes not compressed', $
|
28 |
</span>
|
29 |
<br />
|
30 |
<?php } ?>
|
31 |
|
32 |
-
<?php if ($missing > 0) { ?>
|
33 |
<span class="message">
|
34 |
-
<?php echo htmlspecialchars(sprintf(_n('%d file removed', '%d files removed', $missing, 'tiny-compress-images'), $missing)) ?>
|
35 |
</span>
|
36 |
<br />
|
37 |
<?php } ?>
|
38 |
|
39 |
-
<?php if ($modified > 0) { ?>
|
40 |
<span class="message">
|
41 |
-
<?php echo htmlspecialchars(sprintf(_n('%d file modified after compression', '%d files modified after compression', $modified, 'tiny-compress-images'), $modified)) ?>
|
42 |
</span>
|
43 |
<br />
|
44 |
<?php } ?>
|
@@ -57,69 +67,88 @@
|
|
57 |
<br/>
|
58 |
<?php } ?>
|
59 |
|
60 |
-
<?php
|
61 |
-
<a class="thickbox message" href="#TB_inline?width=700&height=500&inlineId=modal_<?php echo $tiny_metadata->get_id() ?>">Details</a>
|
62 |
-
<?php } ?>
|
63 |
<?php } ?>
|
64 |
</div>
|
65 |
|
66 |
-
<?php if ($tiny_metadata->can_be_compressed() &&
|
67 |
<button type="button" class="tiny-compress button button-small button-primary" data-id="<?php echo $tiny_metadata->get_id() ?>">
|
68 |
<?php echo esc_html__('Compress', 'tiny-compress-images') ?>
|
69 |
</button>
|
70 |
<?php } ?>
|
71 |
</div>
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
<tr>
|
80 |
-
<
|
81 |
-
<
|
82 |
-
<
|
83 |
-
<
|
84 |
</tr>
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
echo ($size == "0" ? esc_html__('original', 'tiny-compress-images') : $size ) . ' ';
|
92 |
-
if ($tiny_metadata->still_exists($size)) {
|
93 |
-
if ($tiny_metadata->is_compressed($size)) {
|
94 |
-
if ($tiny_metadata->is_resized($size)) {
|
95 |
-
printf('<em>' . esc_html__('(resized to %dx%d)', 'tiny-compress-images') . '</em>', $meta['output']['width'], $meta['output']['height']);
|
96 |
-
}
|
97 |
-
} else {
|
98 |
-
echo '<em>' . esc_html__('(modified after compression)', 'tiny-compress-images') . '</em>';
|
99 |
-
}
|
100 |
-
} else {
|
101 |
-
echo '<em>' . esc_html__('(file removed)', 'tiny-compress-images') . '</em>';
|
102 |
-
}
|
103 |
-
?>
|
104 |
-
</td>
|
105 |
-
<td><?php echo size_format($meta["input"]["size"], 1) ?></td>
|
106 |
-
<td><?php echo size_format($meta["output"]["size"], 1) ?></td>
|
107 |
-
<td><?php echo human_time_diff($tiny_metadata->get_end_time($size)) . ' ' . esc_html__('ago', 'tiny-compress-images') ?></td>
|
108 |
-
</tr>
|
109 |
-
<?php $i++ ?>
|
110 |
-
<?php } ?>
|
111 |
-
<?php if ($savings['count'] > 0) { ?>
|
112 |
-
<tfoot>
|
113 |
-
<tr>
|
114 |
-
<td><?php esc_html_e('Combined', 'tiny-compress-images') ?></td>
|
115 |
-
<td><?php echo size_format($savings['input'], 1) ?></td>
|
116 |
-
<td><?php echo size_format($savings['output'], 1) ?></td>
|
117 |
-
<td></td>
|
118 |
-
</tr>
|
119 |
-
</tfoot>
|
120 |
-
<?php } ?>
|
121 |
-
</table>
|
122 |
-
<p><strong><?php printf(esc_html__('Total savings %s', 'tiny-compress-images'), size_format($savings["input"] - $savings["output"], 1)) ?></strong></p>
|
123 |
-
</div>
|
124 |
</div>
|
125 |
-
|
|
1 |
+
<?php
|
2 |
+
$error = $tiny_metadata->get_latest_error();
|
3 |
+
$total = $tiny_metadata->get_count(array('modified', 'missing', 'has_been_compressed', 'compressed'));
|
4 |
+
$active = $tiny_metadata->get_count(array('uncompressed', 'never_compressed'), $active_tinify_sizes);
|
5 |
+
$savings = $tiny_metadata->get_savings();
|
6 |
+
|
7 |
+
$size_active = array_fill_keys($active_tinify_sizes, true);
|
8 |
+
$size_exists = array_fill_keys($available_sizes, true);
|
9 |
+
ksort($size_exists);
|
10 |
+
|
11 |
+
?><div class="details-container">
|
12 |
<div class="details" id="tinify-compress-details">
|
13 |
<?php if ($tiny_metadata->can_be_compressed()) { ?>
|
14 |
<?php if ($error) { ?>
|
15 |
<span class="icon dashicons dashicons-warning error"></span>
|
16 |
+
<?php } else if ($total['missing'] > 0 || $total['modified'] > 0) { ?>
|
17 |
<span class="icon dashicons dashicons-yes alert"></span>
|
18 |
+
<?php } else if ($total['compressed'] > 0 && $active['uncompressed'] > 0) { ?>
|
19 |
<span class="icon dashicons dashicons-yes alert"></span>
|
20 |
+
<?php } else if ($total['compressed'] > 0) { ?>
|
21 |
<span class="icon dashicons dashicons-yes success"></span>
|
22 |
<?php } ?>
|
23 |
<span class="icon spinner hidden"></span>
|
24 |
|
25 |
+
<?php if ($total['has_been_compressed'] > 0 || ($total['has_been_compressed'] == 0 && $active['uncompressed'] == 0)) { ?>
|
26 |
<span class="message">
|
27 |
+
<strong><?php echo $total['has_been_compressed'] ?></strong>
|
28 |
<span>
|
29 |
+
<?php echo htmlspecialchars(_n('size compressed', 'sizes compressed', $total['has_been_compressed'], 'tiny-compress-images')) ?>
|
30 |
</span>
|
31 |
</span>
|
32 |
<br/>
|
33 |
<?php } ?>
|
34 |
|
35 |
+
<?php if ($active['never_compressed'] > 0) { ?>
|
36 |
<span class="message">
|
37 |
+
<?php echo htmlspecialchars(sprintf(_n('%d size not compressed', '%d sizes not compressed', $active['never_compressed'], 'tiny-compress-images'), $active['never_compressed'])) ?>
|
38 |
</span>
|
39 |
<br />
|
40 |
<?php } ?>
|
41 |
|
42 |
+
<?php if ($total['missing'] > 0) { ?>
|
43 |
<span class="message">
|
44 |
+
<?php echo htmlspecialchars(sprintf(_n('%d file removed', '%d files removed', $total['missing'], 'tiny-compress-images'), $total['missing'])) ?>
|
45 |
</span>
|
46 |
<br />
|
47 |
<?php } ?>
|
48 |
|
49 |
+
<?php if ($total['modified'] > 0) { ?>
|
50 |
<span class="message">
|
51 |
+
<?php echo htmlspecialchars(sprintf(_n('%d file modified after compression', '%d files modified after compression', $total['modified'], 'tiny-compress-images'), $total['modified'])) ?>
|
52 |
</span>
|
53 |
<br />
|
54 |
<?php } ?>
|
67 |
<br/>
|
68 |
<?php } ?>
|
69 |
|
70 |
+
<a class="thickbox message" href="#TB_inline?width=700&height=500&inlineId=modal_<?php echo $tiny_metadata->get_id() ?>">Details</a>
|
|
|
|
|
71 |
<?php } ?>
|
72 |
</div>
|
73 |
|
74 |
+
<?php if ($tiny_metadata->can_be_compressed() && $active['uncompressed'] > 0) { ?>
|
75 |
<button type="button" class="tiny-compress button button-small button-primary" data-id="<?php echo $tiny_metadata->get_id() ?>">
|
76 |
<?php echo esc_html__('Compress', 'tiny-compress-images') ?>
|
77 |
</button>
|
78 |
<?php } ?>
|
79 |
</div>
|
80 |
+
|
81 |
+
<div class="modal" id="modal_<?php echo $tiny_metadata->get_id() ?>">
|
82 |
+
<div class="tiny-compression-details">
|
83 |
+
<h3>
|
84 |
+
<?php printf(esc_html__('Compression details for %s', 'tiny-compress-images'), $tiny_metadata->get_name()) ?>
|
85 |
+
</h3>
|
86 |
+
<table>
|
87 |
+
<tr>
|
88 |
+
<th><?php esc_html_e('Size', 'tiny-compress-images') ?></th>
|
89 |
+
<th><?php esc_html_e('Original', 'tiny-compress-images') ?></th>
|
90 |
+
<th><?php esc_html_e('Compressed', 'tiny-compress-images') ?></th>
|
91 |
+
<th><?php esc_html_e('Date', 'tiny-compress-images') ?></th>
|
92 |
+
</tr>
|
93 |
+
<?php $i = 0 ?>
|
94 |
+
<?php
|
95 |
+
$images = $tiny_metadata->get_images() + $size_exists;
|
96 |
+
foreach ($images as $size => $image) {
|
97 |
+
if (!is_object($image)) $image = new Tiny_Metadata_Image();
|
98 |
+
$meta = $image->meta ? $image->meta : array() ?>
|
99 |
+
<tr class="<?php echo ($i % 2 == 0) ? 'even' : 'odd' ?>">
|
100 |
+
<td><?php
|
101 |
+
echo (Tiny_Metadata::is_original($size) ? esc_html__('original', 'tiny-compress-images') : $size ) . ' ';
|
102 |
+
if ($image->missing()) {
|
103 |
+
echo '<em>' . esc_html__('(file removed)', 'tiny-compress-images') . '</em>';
|
104 |
+
} else if ($image->modified()) {
|
105 |
+
echo '<em>' . esc_html__('(modified after compression)', 'tiny-compress-images') . '</em>';
|
106 |
+
} else if ($image->resized()) {
|
107 |
+
printf('<em>' . esc_html__('(resized to %dx%d)', 'tiny-compress-images') . '</em>', $meta['output']['width'], $meta['output']['height']);
|
108 |
+
}
|
109 |
+
?></td>
|
110 |
+
<td><?php
|
111 |
+
if ($image->has_been_compressed()) {
|
112 |
+
echo size_format($meta["input"]["size"], 1);
|
113 |
+
} else if ($image->exists()) {
|
114 |
+
echo size_format($image->filesize(), 1);
|
115 |
+
} else {
|
116 |
+
echo '-';
|
117 |
+
}
|
118 |
+
?></td>
|
119 |
+
<?php
|
120 |
+
if ($image->has_been_compressed()) {
|
121 |
+
echo '<td>';
|
122 |
+
echo size_format($meta["output"]["size"], 1);
|
123 |
+
echo '</td>';
|
124 |
+
echo '<td>' . human_time_diff($image->end_time($size)) . ' ' . esc_html__('ago', 'tiny-compress-images') .'</td>';
|
125 |
+
} elseif (!$image->exists()) {
|
126 |
+
echo '<td colspan=2><em>' . esc_html__('Size is not present', 'tiny-compress-images') . '</em></td>';
|
127 |
+
} elseif (isset($size_active[$size])) {
|
128 |
+
echo '<td colspan=2><em>' . esc_html__('Not compressed', 'tiny-compress-images') . '</em></td>';
|
129 |
+
} elseif (isset($size_exists[$size])) {
|
130 |
+
echo '<td colspan=2><em>' . esc_html__('Not configured to be compressed', 'tiny-compress-images') . '</em></td>';
|
131 |
+
} else {
|
132 |
+
echo '<td colspan=2><em>' . esc_html__('Size is no longer in use', 'tiny-compress-images') . '</em></td>';
|
133 |
+
}
|
134 |
+
?>
|
135 |
+
</tr>
|
136 |
+
<?php $i++ ?>
|
137 |
+
<?php } ?>
|
138 |
+
<?php if ($savings['count'] > 0) { ?>
|
139 |
+
<tfoot>
|
140 |
<tr>
|
141 |
+
<td><?php esc_html_e('Combined', 'tiny-compress-images') ?></td>
|
142 |
+
<td><?php echo size_format($savings['input'], 1) ?></td>
|
143 |
+
<td><?php echo size_format($savings['output'], 1) ?></td>
|
144 |
+
<td></td>
|
145 |
</tr>
|
146 |
+
</tfoot>
|
147 |
+
<?php } ?>
|
148 |
+
</table>
|
149 |
+
<?php if ($savings['input'] && $savings['output']) { ?>
|
150 |
+
<p><strong><?php printf(esc_html__('Total savings %s (%.0f%%)', 'tiny-compress-images'), size_format($savings["input"] - $savings["output"], 1), (1 - $savings['output'] / floatval($savings['input'])) * 100) ?></strong></p>
|
151 |
+
<?php } ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
</div>
|
153 |
+
</div>
|
154 |
+
|
test/helpers/setup.php
CHANGED
@@ -3,8 +3,9 @@
|
|
3 |
require 'vendor/autoload.php';
|
4 |
|
5 |
use Facebook\WebDriver;
|
6 |
-
use Facebook\WebDriver\WebDriverDimension;
|
7 |
use Facebook\WebDriver\WebDriverBy;
|
|
|
|
|
8 |
use Facebook\WebDriver\Remote;
|
9 |
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
10 |
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
@@ -117,22 +118,16 @@ function setup_wordpress_site($driver) {
|
|
117 |
|
118 |
function login($driver) {
|
119 |
print "Logging in to WordPress... ";
|
120 |
-
$driver->get(wordpress('/wp-login.php'));
|
121 |
-
$driver->findElement(WebDriverBy::tagName('body'))->click();
|
122 |
-
$driver->findElement(WebDriverBy::name('log'))->clear()->click()->sendKeys('admin');
|
123 |
-
$driver->findElement(WebDriverBy::name('pwd'))->clear()->click()->sendKeys('admin');
|
124 |
-
$driver->findElement(WebDriverBy::tagName('form'))->submit();
|
125 |
|
126 |
try {
|
127 |
-
$
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
} catch (Exception $e) {
|
135 |
-
// Fixme: sometimes we get a login error randomly. Perhaps it's caused by one of the tests.
|
136 |
var_dump($driver->getPageSource());
|
137 |
throw new UnexpectedValueException('Login failed.');
|
138 |
}
|
3 |
require 'vendor/autoload.php';
|
4 |
|
5 |
use Facebook\WebDriver;
|
|
|
6 |
use Facebook\WebDriver\WebDriverBy;
|
7 |
+
use Facebook\WebDriver\WebDriverDimension;
|
8 |
+
use Facebook\WebDriver\WebDriverExpectedCondition;
|
9 |
use Facebook\WebDriver\Remote;
|
10 |
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
11 |
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
118 |
|
119 |
function login($driver) {
|
120 |
print "Logging in to WordPress... ";
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
try {
|
123 |
+
$driver->get(wordpress('/wp-login.php'));
|
124 |
+
$driver->executeScript('document.getElementById("user_login").value = "admin"');
|
125 |
+
$driver->executeScript('document.getElementById("user_pass").value = "admin"');
|
126 |
+
$driver->findElement(WebDriverBy::id('loginform'))->submit();
|
127 |
+
|
128 |
+
$xpath = "//html/body//div[@class='wrap']/*[self::h1 or self::h2]";
|
129 |
+
$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::xpath($xpath)));
|
130 |
} catch (Exception $e) {
|
|
|
131 |
var_dump($driver->getPageSource());
|
132 |
throw new UnexpectedValueException('Login failed.');
|
133 |
}
|
test/integration/BulkCompressIntegrationTest.php
CHANGED
@@ -45,6 +45,7 @@ class BulkCompressIntegrationTest extends IntegrationTestCase {
|
|
45 |
$this->prepare(1, 2);
|
46 |
|
47 |
self::$driver->get(wordpress('/wp-admin/upload.php?orderby=title&order=asc'));
|
|
|
48 |
$checkboxes = self::$driver->findElements(WebDriverBy::cssSelector('tbody input[type="checkbox"]'));
|
49 |
$checkboxes[0]->click();
|
50 |
|
45 |
$this->prepare(1, 2);
|
46 |
|
47 |
self::$driver->get(wordpress('/wp-admin/upload.php?orderby=title&order=asc'));
|
48 |
+
|
49 |
$checkboxes = self::$driver->findElements(WebDriverBy::cssSelector('tbody input[type="checkbox"]'));
|
50 |
$checkboxes[0]->click();
|
51 |
|
test/integration/CompressIntegrationTest.php
CHANGED
@@ -96,12 +96,13 @@ class CompressIntegrationTest extends IntegrationTestCase {
|
|
96 |
}
|
97 |
|
98 |
public function testResizeFitShouldDisplayResizedTextInEditScreen() {
|
|
|
99 |
$this->set_api_key('PNG123');
|
100 |
$this->enable_resize(300, 200);
|
101 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
102 |
$this->view_edit_image();
|
103 |
$this->assertContains('Dimensions: 300 × 200',
|
104 |
-
self::$driver->findElement(WebDriverBy::cssSelector(
|
105 |
}
|
106 |
|
107 |
public function testResizeScaleShouldDisplayResizedTextInMediaLibrary() {
|
@@ -114,16 +115,16 @@ class CompressIntegrationTest extends IntegrationTestCase {
|
|
114 |
}
|
115 |
|
116 |
public function testResizeScaleShouldDisplayResizedTextInEditScreen() {
|
|
|
117 |
$this->set_api_key('PNG123');
|
118 |
$this->enable_resize(0, 200);
|
119 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
120 |
$this->view_edit_image();
|
121 |
$this->assertContains('Dimensions: 300 × 200',
|
122 |
-
self::$driver->findElement(WebDriverBy::cssSelector(
|
123 |
}
|
124 |
|
125 |
-
public function testResizeNotNeededShouldNotDisplayResizedTextInMediaLibrary()
|
126 |
-
{
|
127 |
$this->set_api_key('PNG123');
|
128 |
$this->enable_resize(30000, 20000);
|
129 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
@@ -132,18 +133,17 @@ class CompressIntegrationTest extends IntegrationTestCase {
|
|
132 |
self::$driver->findElement(WebDriverBy::cssSelector('div.tiny-compression-details'))->getText());
|
133 |
}
|
134 |
|
135 |
-
public function testResizeNotNeededShouldDisplayOriginalDimensionsInEditScreen()
|
136 |
-
|
137 |
$this->set_api_key('PNG123');
|
138 |
$this->enable_resize(30000, 20000);
|
139 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
140 |
$this->view_edit_image();
|
141 |
$this->assertContains('Dimensions: 1080 × 720',
|
142 |
-
self::$driver->findElement(WebDriverBy::cssSelector(
|
143 |
}
|
144 |
|
145 |
-
public function testResizeDisabledShouldNotDisplayResizedTextInMediaLibrary()
|
146 |
-
{
|
147 |
$this->set_api_key('PNG123');
|
148 |
$this->enable_resize(300, 200);
|
149 |
$this->disable_resize();
|
@@ -153,19 +153,18 @@ class CompressIntegrationTest extends IntegrationTestCase {
|
|
153 |
self::$driver->findElement(WebDriverBy::cssSelector('div.tiny-compression-details'))->getText());
|
154 |
}
|
155 |
|
156 |
-
public function testResizeDisabledShouldDisplayOriginalDimensionsInEditScreen()
|
157 |
-
|
158 |
$this->set_api_key('PNG123');
|
159 |
$this->enable_resize(300, 200);
|
160 |
$this->disable_resize();
|
161 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
162 |
$this->view_edit_image();
|
163 |
$this->assertContains('Dimensions: 1080 × 720',
|
164 |
-
self::$driver->findElement(WebDriverBy::cssSelector(
|
165 |
}
|
166 |
|
167 |
-
public function testPreserveCopyrightShouldDisplayCorrectImageSizeInMediaLibrary()
|
168 |
-
{
|
169 |
$this->set_api_key('PRESERVEJPG123');
|
170 |
$this->enable_preserve(array('copyright'));
|
171 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-copyright.jpg');
|
@@ -173,6 +172,67 @@ class CompressIntegrationTest extends IntegrationTestCase {
|
|
173 |
self::$driver->findElement(WebDriverBy::cssSelector('div#tinify-compress-details'))->getText());
|
174 |
}
|
175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
public function testDifferentImageFormatFileShouldNotShowCompressInfoInMediaLibrary()
|
177 |
{
|
178 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.gif');
|
@@ -198,22 +258,20 @@ class CompressIntegrationTest extends IntegrationTestCase {
|
|
198 |
|
199 |
public function testGatewayTimeoutShouldBeDetectedInOutput()
|
200 |
{
|
201 |
-
$this->enable_compression_sizes(array('medium'));
|
202 |
$this->enable_preserve(array('copyright'));
|
203 |
$this->set_api_key('PNG123_GATEWAYTIMEOUT');
|
204 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
205 |
-
self::$driver->takeScreenshot("/Users/jacobmiddag/Downloads/ss2.png");
|
206 |
$this->assertContains('Unexepected error in output',
|
207 |
self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images'))->getText());
|
208 |
}
|
209 |
|
210 |
public function testErrorShouldBeDetectedInOutput()
|
211 |
{
|
212 |
-
$this->enable_compression_sizes(array('medium'));
|
213 |
$this->enable_preserve(array('copyright'));
|
214 |
$this->set_api_key('PNG123_INVALID');
|
215 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
216 |
-
self::$driver->takeScreenshot("/Users/jacobmiddag/Downloads/ss3.png");
|
217 |
$this->assertContains("Metadata key 'author' not supported",
|
218 |
self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images'))->getText());
|
219 |
}
|
96 |
}
|
97 |
|
98 |
public function testResizeFitShouldDisplayResizedTextInEditScreen() {
|
99 |
+
if (!$this->has_postbox_container()) return;
|
100 |
$this->set_api_key('PNG123');
|
101 |
$this->enable_resize(300, 200);
|
102 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
103 |
$this->view_edit_image();
|
104 |
$this->assertContains('Dimensions: 300 × 200',
|
105 |
+
self::$driver->findElement(WebDriverBy::cssSelector($this->postbox_dimension_selector()))->getText());
|
106 |
}
|
107 |
|
108 |
public function testResizeScaleShouldDisplayResizedTextInMediaLibrary() {
|
115 |
}
|
116 |
|
117 |
public function testResizeScaleShouldDisplayResizedTextInEditScreen() {
|
118 |
+
if (!$this->has_postbox_container()) return;
|
119 |
$this->set_api_key('PNG123');
|
120 |
$this->enable_resize(0, 200);
|
121 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
122 |
$this->view_edit_image();
|
123 |
$this->assertContains('Dimensions: 300 × 200',
|
124 |
+
self::$driver->findElement(WebDriverBy::cssSelector($this->postbox_dimension_selector()))->getText());
|
125 |
}
|
126 |
|
127 |
+
public function testResizeNotNeededShouldNotDisplayResizedTextInMediaLibrary() {
|
|
|
128 |
$this->set_api_key('PNG123');
|
129 |
$this->enable_resize(30000, 20000);
|
130 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
133 |
self::$driver->findElement(WebDriverBy::cssSelector('div.tiny-compression-details'))->getText());
|
134 |
}
|
135 |
|
136 |
+
public function testResizeNotNeededShouldDisplayOriginalDimensionsInEditScreen() {
|
137 |
+
if (!$this->has_postbox_container()) return;
|
138 |
$this->set_api_key('PNG123');
|
139 |
$this->enable_resize(30000, 20000);
|
140 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
141 |
$this->view_edit_image();
|
142 |
$this->assertContains('Dimensions: 1080 × 720',
|
143 |
+
self::$driver->findElement(WebDriverBy::cssSelector($this->postbox_dimension_selector()))->getText());
|
144 |
}
|
145 |
|
146 |
+
public function testResizeDisabledShouldNotDisplayResizedTextInMediaLibrary() {
|
|
|
147 |
$this->set_api_key('PNG123');
|
148 |
$this->enable_resize(300, 200);
|
149 |
$this->disable_resize();
|
153 |
self::$driver->findElement(WebDriverBy::cssSelector('div.tiny-compression-details'))->getText());
|
154 |
}
|
155 |
|
156 |
+
public function testResizeDisabledShouldDisplayOriginalDimensionsInEditScreen() {
|
157 |
+
if (!$this->has_postbox_container()) return;
|
158 |
$this->set_api_key('PNG123');
|
159 |
$this->enable_resize(300, 200);
|
160 |
$this->disable_resize();
|
161 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
162 |
$this->view_edit_image();
|
163 |
$this->assertContains('Dimensions: 1080 × 720',
|
164 |
+
self::$driver->findElement(WebDriverBy::cssSelector($this->postbox_dimension_selector()))->getText());
|
165 |
}
|
166 |
|
167 |
+
public function testPreserveCopyrightShouldDisplayCorrectImageSizeInMediaLibrary() {
|
|
|
168 |
$this->set_api_key('PRESERVEJPG123');
|
169 |
$this->enable_preserve(array('copyright'));
|
170 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-copyright.jpg');
|
172 |
self::$driver->findElement(WebDriverBy::cssSelector('div#tinify-compress-details'))->getText());
|
173 |
}
|
174 |
|
175 |
+
public function testShouldShowDetailsInEditScreen() {
|
176 |
+
if (!$this->has_postbox_container()) return;
|
177 |
+
$this->set_api_key('PNG123');
|
178 |
+
$this->enable_compression_sizes(array());
|
179 |
+
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
180 |
+
$this->enable_compression_sizes(array('medium', 'large'));
|
181 |
+
$this->view_edit_image();
|
182 |
+
$this->assertContains("Compress JPEG & PNG Images\n2 sizes not compressed\nDetails\nCompress",
|
183 |
+
self::$driver->findElement(WebDriverBy::cssSelector('div.postbox-container div.tiny-compress-images'))->getText());
|
184 |
+
}
|
185 |
+
|
186 |
+
public function testButtonInEditScreenShouldCompressImages() {
|
187 |
+
if (!$this->has_postbox_container()) return;
|
188 |
+
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
189 |
+
$this->set_api_key('PNG123');
|
190 |
+
$this->enable_compression_sizes(array('medium', 'large'));
|
191 |
+
$this->view_edit_image();
|
192 |
+
self::$driver->findElement(WebDriverBy::cssSelector('div.tiny-compress-images button.tiny-compress'))->click();
|
193 |
+
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
194 |
+
WebDriverBy::cssSelector('div.tiny-compress-images'), '2 sizes compressed'));
|
195 |
+
}
|
196 |
+
|
197 |
+
public function testEditScreenShouldShowDetailsPopup() {
|
198 |
+
if (!$this->has_postbox_container()) return;
|
199 |
+
$this->set_api_key('PNG123');
|
200 |
+
$this->enable_compression_sizes(array('medium', 'large'));
|
201 |
+
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
202 |
+
$this->view_edit_image();
|
203 |
+
self::$driver->findElement(WebDriverBy::cssSelector('div.tiny-compress-images a.thickbox'))->click();
|
204 |
+
$this->assertContains('Compression details for input-example.jpg',
|
205 |
+
self::$driver->findElement(WebDriverBy::cssSelector('div.tiny-compression-details'))->getText());
|
206 |
+
}
|
207 |
+
|
208 |
+
public function testEditScreenShouldShowCorrectDetailsInPopup() {
|
209 |
+
if (!$this->has_postbox_container()) return;
|
210 |
+
$this->set_api_key('PNG123');
|
211 |
+
$this->enable_compression_sizes(array('medium', 'large'));
|
212 |
+
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
213 |
+
$this->view_edit_image();
|
214 |
+
|
215 |
+
self::$driver->findElement(WebDriverBy::cssSelector('div.tiny-compress-images a.thickbox'))->click();
|
216 |
+
$cells = self::$driver->findElements(WebDriverBy::cssSelector('div.tiny-compression-details td'));
|
217 |
+
$texts = array_map('innerText', $cells);
|
218 |
+
// Remove sizes that are version specific
|
219 |
+
for ($i = 0; $i < count($texts); ) {
|
220 |
+
$row_size = (substr($texts[$i+2], 0, 3) == 'Not') ? 3 : 4;
|
221 |
+
if (in_array($texts[$i], array('original', 'thumbnail', 'medium', 'large', 'Combined'))) {
|
222 |
+
$i += $row_size;
|
223 |
+
} else {
|
224 |
+
$texts = array_merge(array_slice($texts, 0, $i), array_slice($texts, $i + $row_size));
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
$this->assertEquals(array(
|
229 |
+
'original', '158.1 kB', 'Not configured to be compressed',
|
230 |
+
'large', '158.1 kB', '147.5 kB', '1 min ago',
|
231 |
+
'medium', '158.1 kB', '147.5 kB', '1 min ago',
|
232 |
+
'thumbnail', '11.8 kB', 'Not configured to be compressed',
|
233 |
+
'Combined', '316.2 kB', '295.0 kB', ''), $texts);
|
234 |
+
}
|
235 |
+
|
236 |
public function testDifferentImageFormatFileShouldNotShowCompressInfoInMediaLibrary()
|
237 |
{
|
238 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.gif');
|
258 |
|
259 |
public function testGatewayTimeoutShouldBeDetectedInOutput()
|
260 |
{
|
261 |
+
$this->enable_compression_sizes(array('0', 'medium'));
|
262 |
$this->enable_preserve(array('copyright'));
|
263 |
$this->set_api_key('PNG123_GATEWAYTIMEOUT');
|
264 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
|
|
265 |
$this->assertContains('Unexepected error in output',
|
266 |
self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images'))->getText());
|
267 |
}
|
268 |
|
269 |
public function testErrorShouldBeDetectedInOutput()
|
270 |
{
|
271 |
+
$this->enable_compression_sizes(array('0', 'medium'));
|
272 |
$this->enable_preserve(array('copyright'));
|
273 |
$this->set_api_key('PNG123_INVALID');
|
274 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
|
|
275 |
$this->assertContains("Metadata key 'author' not supported",
|
276 |
self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images'))->getText());
|
277 |
}
|
test/integration/IntegrationTestCase.php
CHANGED
@@ -16,6 +16,20 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase {
|
|
16 |
self::$driver = RemoteWebDriver::createBySessionId($GLOBALS['global_session_id'], $GLOBALS['global_webdriver_host']);
|
17 |
}
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
protected function upload_media($path) {
|
20 |
self::$driver->get(wordpress('/wp-admin/media-new.php?browser-uploader&flash=0'));
|
21 |
$links = self::$driver->findElements(WebDriverBy::xpath('//a[text()="browser uploader"]'));
|
@@ -30,7 +44,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase {
|
|
30 |
$file_input->setFileDetector(new UselessFileDetector());
|
31 |
$file_input->sendKeys($path);
|
32 |
self::$driver->findElement(WebDriverBy::xpath('//input[@value="Upload"]'))->click();
|
33 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::xpath('//h1[contains(text(),"Media Library")]')));
|
34 |
}
|
35 |
|
36 |
protected function set_api_key($api_key) {
|
16 |
self::$driver = RemoteWebDriver::createBySessionId($GLOBALS['global_session_id'], $GLOBALS['global_webdriver_host']);
|
17 |
}
|
18 |
|
19 |
+
protected function has_postbox_container() {
|
20 |
+
return wordpress_version() >= 35;
|
21 |
+
}
|
22 |
+
|
23 |
+
protected function postbox_dimension_selector() {
|
24 |
+
$version = wordpress_version();
|
25 |
+
if ($version < 37)
|
26 |
+
return 'div.misc-pub-section:nth-child(5)';
|
27 |
+
elseif ($version == 37)
|
28 |
+
return 'div.misc-pub-section:nth-child(6)';
|
29 |
+
else
|
30 |
+
return 'div.misc-pub-dimensions';
|
31 |
+
}
|
32 |
+
|
33 |
protected function upload_media($path) {
|
34 |
self::$driver->get(wordpress('/wp-admin/media-new.php?browser-uploader&flash=0'));
|
35 |
$links = self::$driver->findElements(WebDriverBy::xpath('//a[text()="browser uploader"]'));
|
44 |
$file_input->setFileDetector(new UselessFileDetector());
|
45 |
$file_input->sendKeys($path);
|
46 |
self::$driver->findElement(WebDriverBy::xpath('//input[@value="Upload"]'))->click();
|
47 |
+
self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::xpath('//h1[contains(text(),"Media Library")]|//h2[contains(text(),"Media Library")]')));
|
48 |
}
|
49 |
|
50 |
protected function set_api_key($api_key) {
|
test/integration/SettingsIntegrationTest.php
CHANGED
@@ -89,21 +89,19 @@ class SettingsIntegrationTest extends IntegrationTestCase {
|
|
89 |
}
|
90 |
|
91 |
public function testShouldShowTotalImagesInfo() {
|
92 |
-
$
|
93 |
-
$
|
94 |
-
$this->assertContains('With these settings you can compress at least
|
95 |
}
|
96 |
|
97 |
public function testShouldUpdateTotalImagesInfo() {
|
|
|
98 |
$element = self::$driver->findElement(
|
99 |
WebDriverBy::xpath('//input[@type="checkbox" and @name="tinypng_sizes[0]" and @checked="checked"]'));
|
100 |
$element->click();
|
101 |
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
102 |
-
WebDriverBy::cssSelector('#tiny-image-sizes-notice'),
|
103 |
-
|
104 |
-
$elements = self::$driver->findElement(WebDriverBy::id('tiny-image-sizes-notice'))->findElements(WebDriverBy::tagName('p'));
|
105 |
-
$statuses = array_map('innerText', $elements);
|
106 |
-
$this->assertContains('With these settings you can compress at least 125 images for free each month.', $statuses);
|
107 |
}
|
108 |
|
109 |
public function testShouldShowCorrectNoImageSizesInfo() {
|
@@ -145,6 +143,13 @@ class SettingsIntegrationTest extends IntegrationTestCase {
|
|
145 |
$this->assertNotContains('Resize and compress orginal images to fit within:', $texts);
|
146 |
}
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
public function testShouldPersistResizingSettings() {
|
149 |
$this->enable_resize(123, 456);
|
150 |
$this->assertEquals('123', self::$driver->findElement(WebDriverBy::id('tinypng_resize_original_width'))->getAttribute('value'));
|
@@ -154,27 +159,23 @@ class SettingsIntegrationTest extends IntegrationTestCase {
|
|
154 |
public function testStatusPresenceOK() {
|
155 |
reset_webservice();
|
156 |
$this->set_api_key('PNG123');
|
157 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::
|
158 |
-
|
159 |
-
|
160 |
-
$this->assertContains('API connection successful', $statuses);
|
161 |
-
$this->assertContains('You have made 0 compressions this month.', $statuses);
|
162 |
}
|
163 |
|
164 |
public function testStatusPresenseFail() {
|
165 |
$this->set_api_key('INVALID123');
|
166 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::
|
167 |
-
|
168 |
-
|
169 |
-
$this->assertContains('API connection unsuccessful', $statuses[0]);
|
170 |
}
|
171 |
|
172 |
public function testShouldShowBulkCompressionLink() {
|
173 |
reset_webservice();
|
174 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::
|
175 |
-
|
176 |
-
|
177 |
-
$this->assertContains('No images compressed yet. Use Compress All Images to compress existing images.', $statuses);
|
178 |
}
|
179 |
|
180 |
public function testShouldShowSavings() {
|
@@ -182,9 +183,8 @@ class SettingsIntegrationTest extends IntegrationTestCase {
|
|
182 |
$this->set_api_key('PNG123');
|
183 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
184 |
self::$driver->get(wordpress('/wp-admin/options-media.php'));
|
185 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::
|
186 |
-
|
187 |
-
|
188 |
-
$this->assertRegexp('/You have saved a total of .. kB on images!/', $statuses[0]);
|
189 |
}
|
190 |
}
|
89 |
}
|
90 |
|
91 |
public function testShouldShowTotalImagesInfo() {
|
92 |
+
$this->enable_compression_sizes(array('0', 'thumbnail', 'medium', 'large'));
|
93 |
+
$element = self::$driver->findElement(WebDriverBy::id('tiny-image-sizes-notice'));
|
94 |
+
$this->assertContains('With these settings you can compress at least 125 images for free each month.', $element->getText());
|
95 |
}
|
96 |
|
97 |
public function testShouldUpdateTotalImagesInfo() {
|
98 |
+
$this->enable_compression_sizes(array('0', 'thumbnail', 'medium', 'large'));
|
99 |
$element = self::$driver->findElement(
|
100 |
WebDriverBy::xpath('//input[@type="checkbox" and @name="tinypng_sizes[0]" and @checked="checked"]'));
|
101 |
$element->click();
|
102 |
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
103 |
+
WebDriverBy::cssSelector('#tiny-image-sizes-notice'),
|
104 |
+
'With these settings you can compress at least 166 images for free each month.'));
|
|
|
|
|
|
|
105 |
}
|
106 |
|
107 |
public function testShouldShowCorrectNoImageSizesInfo() {
|
143 |
$this->assertNotContains('Resize and compress orginal images to fit within:', $texts);
|
144 |
}
|
145 |
|
146 |
+
public function testShouldNotShowResizingWhenOriginalDisabledWhenShownFirst() {
|
147 |
+
$this->enable_compression_sizes(array('original'));
|
148 |
+
self::$driver->navigate()->refresh();
|
149 |
+
$this->assertEquals('Enable compression of the original image size for more options.',
|
150 |
+
self::$driver->findElement(WebDriverBy::cssSelector('.tiny-resize-unavailable'))->getText());
|
151 |
+
}
|
152 |
+
|
153 |
public function testShouldPersistResizingSettings() {
|
154 |
$this->enable_resize(123, 456);
|
155 |
$this->assertEquals('123', self::$driver->findElement(WebDriverBy::id('tinypng_resize_original_width'))->getAttribute('value'));
|
159 |
public function testStatusPresenceOK() {
|
160 |
reset_webservice();
|
161 |
$this->set_api_key('PNG123');
|
162 |
+
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
163 |
+
WebDriverBy::cssSelector('#tiny-compress-status'),
|
164 |
+
"API connection successful\nYou have made"));
|
|
|
|
|
165 |
}
|
166 |
|
167 |
public function testStatusPresenseFail() {
|
168 |
$this->set_api_key('INVALID123');
|
169 |
+
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
170 |
+
WebDriverBy::cssSelector('#tiny-compress-status'),
|
171 |
+
"API connection unsuccessful\nError: Credentials are invalid"));
|
|
|
172 |
}
|
173 |
|
174 |
public function testShouldShowBulkCompressionLink() {
|
175 |
reset_webservice();
|
176 |
+
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
177 |
+
WebDriverBy::cssSelector('#tiny-compress-savings p'),
|
178 |
+
'No images compressed yet. Use Compress All Images to compress existing images.'));
|
|
|
179 |
}
|
180 |
|
181 |
public function testShouldShowSavings() {
|
183 |
$this->set_api_key('PNG123');
|
184 |
$this->upload_media(dirname(__FILE__) . '/../fixtures/input-example.png');
|
185 |
self::$driver->get(wordpress('/wp-admin/options-media.php'));
|
186 |
+
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
187 |
+
WebDriverBy::cssSelector('#tiny-compress-savings p'),
|
188 |
+
'You have saved a total of'));
|
|
|
189 |
}
|
190 |
}
|
test/unit/TinyMetadataImageTest.php
ADDED
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once(dirname(__FILE__) . "/TinyTestCase.php");
|
4 |
+
|
5 |
+
class Tiny_Metadata_Image_Test extends TinyTestCase {
|
6 |
+
public function setUp() {
|
7 |
+
parent::setUp();
|
8 |
+
|
9 |
+
$meta = array(Tiny_Metadata::META_KEY => array(
|
10 |
+
Tiny_Metadata::ORIGINAL => array(
|
11 |
+
"input" => array("size" => 146480),
|
12 |
+
"output" => array("size" => 137856, "resized" => true),
|
13 |
+
'end' => 1447925138,
|
14 |
+
'start' => 1447925134),
|
15 |
+
"thumbnail" => array(
|
16 |
+
"input" => array("size" => 46480),
|
17 |
+
"output" => array("size" => 37856),
|
18 |
+
'timestamp' => 1447925244),
|
19 |
+
"medium" => array(
|
20 |
+
"input" => array("size" => 66480),
|
21 |
+
"output" => array("size" => 57856)),
|
22 |
+
"small" => array(
|
23 |
+
"input" => array("size" => 66480),
|
24 |
+
'start' => 1447925134),
|
25 |
+
));
|
26 |
+
$this->wp->setMetadata(1, $meta);
|
27 |
+
$this->wp->createImagesFromMeta($this->json("wp_meta_default_sizes"), $meta, 137856);
|
28 |
+
$metadata = new Tiny_Metadata(1, $this->json("wp_meta_default_sizes"));
|
29 |
+
$this->original = $metadata->get_image();
|
30 |
+
$this->thumbnail = $metadata->get_image('thumbnail');
|
31 |
+
$this->small = $metadata->get_image('small');
|
32 |
+
$this->medium = $metadata->get_image('medium');
|
33 |
+
$this->large = $metadata->get_image('large');
|
34 |
+
}
|
35 |
+
|
36 |
+
public function testEndTimeShouldReturnEndFromMeta() {
|
37 |
+
$this->assertEquals(1447925138, $this->original->end_time());
|
38 |
+
}
|
39 |
+
|
40 |
+
public function testEndTimeShouldReturnEndFromTimestampIfEndIsUnavailable() {
|
41 |
+
$this->assertEquals(1447925244, $this->thumbnail->end_time());
|
42 |
+
}
|
43 |
+
|
44 |
+
public function testEndTimeShouldReturnNullIfUnavailable() {
|
45 |
+
$this->assertEquals(null, $this->medium->end_time());
|
46 |
+
}
|
47 |
+
|
48 |
+
public function testAddRequestShouldAddStartTime() {
|
49 |
+
$this->large->add_request();
|
50 |
+
$this->assertEqualWithinDelta(time(), $this->large->meta['start'], 2);
|
51 |
+
}
|
52 |
+
|
53 |
+
public function testAddRequestShouldUnsetPreviousResponse() {
|
54 |
+
$this->medium->add_request();
|
55 |
+
$this->assertEqualWithinDelta(time(), $this->medium->meta['start'], 2);
|
56 |
+
}
|
57 |
+
|
58 |
+
public function testAddResponseShouldAddEndTime() {
|
59 |
+
$this->large->add_request();
|
60 |
+
$this->large->add_response(array('input' => array('size' => 1024), 'output' => array('size' => 1024)));
|
61 |
+
$this->assertEqualWithinDelta(time(), $this->large->meta['end'], 2);
|
62 |
+
}
|
63 |
+
|
64 |
+
public function testAddResponseShouldResponse() {
|
65 |
+
$this->large->add_request();
|
66 |
+
$this->large->add_response(array('input' => array('size' => 1024), 'output' => array('size' => 1024)));
|
67 |
+
$actual = $this->large->meta;
|
68 |
+
unset($actual['end']);
|
69 |
+
$this->assertEquals(array('input' => array('size' => 1024), 'output' => array('size' => 1024)), $actual);
|
70 |
+
}
|
71 |
+
|
72 |
+
public function testAddResponseShouldNotAddIfNoRequestWasMade() {
|
73 |
+
$this->large->add_response(array('input' => array('size' => 1024), 'output' => array('size' => 1024)));
|
74 |
+
$this->assertEquals(null, $this->large->meta);
|
75 |
+
}
|
76 |
+
|
77 |
+
public function testAddExceptionShouldAddMessageAndError() {
|
78 |
+
$this->large->add_request();
|
79 |
+
$this->large->add_exception(new Tiny_Exception("Image could not be found", "Not found"));
|
80 |
+
unset($this->large->meta['timestamp']);
|
81 |
+
$this->assertEquals(array('error' => 'Not found', 'message' => 'Image could not be found'), $this->large->meta);
|
82 |
+
}
|
83 |
+
|
84 |
+
public function testAddExceptionShouldAddTimestamp() {
|
85 |
+
$this->large->add_request();
|
86 |
+
$this->large->add_exception(new Tiny_Exception("Image could not be found", "Not found"));
|
87 |
+
$this->assertEqualWithinDelta(time(), $this->large->meta['timestamp'], 2);
|
88 |
+
}
|
89 |
+
|
90 |
+
public function testAddExceptionShouldNotAddIfNoRequestWasMade() {
|
91 |
+
$this->large->add_exception(new Tiny_Exception("Image could not be found", "Not found"));
|
92 |
+
unset($this->large->meta['timestamp']);
|
93 |
+
$this->assertEquals(null, $this->large->meta);
|
94 |
+
}
|
95 |
+
|
96 |
+
public function testImageHasBeenCompressedIfMetaHasOutput() {
|
97 |
+
$this->assertTrue($this->original->has_been_compressed());
|
98 |
+
}
|
99 |
+
|
100 |
+
public function testImageHasNotBeenCompressedIfMetaDoesNotHaveOutput() {
|
101 |
+
$this->assertFalse($this->large->has_been_compressed());
|
102 |
+
}
|
103 |
+
|
104 |
+
public function testImageDoesNotStillExistIfFileDoesNotExist() {
|
105 |
+
$image = new Tiny_Metadata_Image('does_not_exist');
|
106 |
+
$this->assertFalse($image->still_exists());
|
107 |
+
}
|
108 |
+
|
109 |
+
public function testImageStillExistsIfFileExists() {
|
110 |
+
$this->assertTrue($this->original->still_exists());
|
111 |
+
}
|
112 |
+
|
113 |
+
public function testImageCompressedShouldReturnTrueIfFileExistsAndSizeIsSame() {
|
114 |
+
$this->assertTrue($this->original->compressed());
|
115 |
+
}
|
116 |
+
|
117 |
+
public function testImageCompressedShouldReturnFalseIfSizeIsInequalToMeta() {
|
118 |
+
$this->wp->createImage(37857, "2015/09", "tinypng_gravatar-150x150.png");
|
119 |
+
$this->assertFalse($this->thumbnail->compressed());
|
120 |
+
}
|
121 |
+
|
122 |
+
public function testImageModifiedShouldReturnTrueIfSizeIsInequalToMeta() {
|
123 |
+
$this->wp->createImage(37857, "2015/09", "tinypng_gravatar-150x150.png");
|
124 |
+
$this->assertTrue($this->thumbnail->modified());
|
125 |
+
}
|
126 |
+
|
127 |
+
public function testImageModifiedShouldReturnFalseIfCompressedCorrectly() {
|
128 |
+
$this->assertFalse($this->original->modified());
|
129 |
+
}
|
130 |
+
|
131 |
+
public function testUncompressedShouldReturnTrueIfImageExistAndIsUncompressed() {
|
132 |
+
$this->wp->createImage(37857, "2015/09", "tinypng_gravatar-150x150.png");
|
133 |
+
$this->assertTrue($this->thumbnail->uncompressed());
|
134 |
+
}
|
135 |
+
|
136 |
+
public function testUncompressedShouldReturnFalseIfImageExistAndIsCompressed() {
|
137 |
+
$this->assertFalse($this->original->uncompressed());
|
138 |
+
}
|
139 |
+
|
140 |
+
public function testInProgressShouldReturnTrueIfMetaHaveStartAndNotOutput() {
|
141 |
+
$this->assertTrue($this->small->in_progress());
|
142 |
+
}
|
143 |
+
|
144 |
+
public function testInProgressShouldReturnFalseIfMetaHaveStartAndOutput() {
|
145 |
+
$this->assertFalse($this->original->in_progress());
|
146 |
+
}
|
147 |
+
|
148 |
+
public function testResizedShouldReturnTrueIfMetaHaveOutputAndResized() {
|
149 |
+
$this->assertTrue($this->original->resized());
|
150 |
+
}
|
151 |
+
|
152 |
+
public function testResizedShouldReturnFalseIfMetaHaveOutputAndNotResized() {
|
153 |
+
$this->assertFalse($this->thumbnail->resized());
|
154 |
+
}
|
155 |
+
}
|
test/unit/TinyMetadataTest.php
CHANGED
@@ -6,19 +6,16 @@ class Tiny_Metadata_Test extends TinyTestCase {
|
|
6 |
public function setUp() {
|
7 |
parent::setUp();
|
8 |
|
9 |
-
$this->wp->addOption("tinypng_api_key", "test123");
|
10 |
-
$this->wp->addOption("tinypng_sizes[0]", "on");
|
11 |
-
|
12 |
$meta = array(Tiny_Metadata::META_KEY => array(
|
13 |
Tiny_Metadata::ORIGINAL => array(
|
14 |
"input" => array("size" => 146480),
|
15 |
-
"output" => array("size" => 137856)),
|
16 |
"thumbnail" => array(
|
17 |
"input" => array("size" => 46480),
|
18 |
"output" => array("size" => 37856)),
|
19 |
"medium" => array(
|
20 |
"input" => array("size" => 66480),
|
21 |
-
"output" => array("size" => 57856))
|
22 |
));
|
23 |
$this->wp->setMetadata(1, $meta);
|
24 |
$this->wp->createImagesFromMeta($this->json("wp_meta_default_sizes"), $meta, 137856);
|
@@ -40,240 +37,46 @@ class Tiny_Metadata_Test extends TinyTestCase {
|
|
40 |
'width' => 2000,
|
41 |
'height' => 1000
|
42 |
);
|
43 |
-
$tiny_meta->add_request();
|
44 |
-
$tiny_meta->add_response(array('output' => array('width' => 200, 'height' => 100)));
|
45 |
$this->assertEquals(array('width' => 200, 'height' => 100), $tiny_meta->update_wp_metadata($wp_metadata));
|
46 |
}
|
47 |
|
48 |
-
public function
|
49 |
-
$
|
50 |
-
|
51 |
-
$this->assertEquals($processing_count + 1, $this->subject->get_in_progress_count());
|
52 |
-
}
|
53 |
-
|
54 |
-
public function testAddRequestShouldIncreaseProccessingCountEvenIfAlreadyCompressed() {
|
55 |
-
$processing_count = $this->subject->get_in_progress_count();
|
56 |
-
$this->subject->add_request("thumbnail");
|
57 |
-
$this->assertEquals($processing_count + 1, $this->subject->get_in_progress_count());
|
58 |
-
}
|
59 |
-
|
60 |
-
public function testAddRequestShouldNotIncreaseSuccessCount() {
|
61 |
-
$success_count = $this->subject->get_success_count();
|
62 |
-
$this->subject->add_request("large");
|
63 |
-
$this->assertEquals($success_count, $this->subject->get_success_count());
|
64 |
-
}
|
65 |
-
|
66 |
-
public function testAddResponseShouldIncreaseSuccessCountForCompression() {
|
67 |
-
$success_count = $this->subject->get_success_count();
|
68 |
-
$this->subject->add_request("large");
|
69 |
-
$this->subject->add_response(array("output" => array("size" => 137857)), "large");
|
70 |
-
$this->wp->createImage(137857, "2015/09", "tinypng_gravatar-600x600.png");
|
71 |
-
$this->assertEquals($success_count + 1, $this->subject->get_success_count());
|
72 |
-
}
|
73 |
-
|
74 |
-
public function testAddResponseShouldNotIncreaseSuccessCountIfPhysicalFileIsMissing() {
|
75 |
-
$success_count = $this->subject->get_success_count();
|
76 |
-
$this->subject->add_request("large");
|
77 |
-
$this->subject->add_response(array("output" => array("size" => 137857)), "large");
|
78 |
-
$this->assertEquals($success_count, $this->subject->get_success_count());
|
79 |
-
}
|
80 |
-
|
81 |
-
public function testAddResponseShouldIncreaseCompressedCount() {
|
82 |
-
$compressed_count = count($this->subject->get_compressed_sizes());
|
83 |
-
$this->subject->add_request("large");
|
84 |
-
$this->subject->add_response(array("output" => array("size" => 137857)), "large");
|
85 |
-
$this->wp->createImage(137857, "2015/09", "tinypng_gravatar-600x600.png");
|
86 |
-
$this->assertEquals($compressed_count + 1, count($this->subject->get_compressed_sizes()));
|
87 |
-
}
|
88 |
-
|
89 |
-
public function testAddResponseShouldIncreaseCompressedCountIfPhysicalFileIsMissing() {
|
90 |
-
$compressed_count = count($this->subject->get_compressed_sizes());
|
91 |
-
$this->subject->add_request("large");
|
92 |
-
$this->subject->add_response(array("output" => array("size" => 137857)), "large");
|
93 |
-
$this->assertEquals($compressed_count + 1, count($this->subject->get_compressed_sizes()));
|
94 |
-
}
|
95 |
-
|
96 |
-
public function testAddResponseShouldNotIncreaseProcessingCount() {
|
97 |
-
$processing_count = $this->subject->get_in_progress_count();
|
98 |
-
$this->subject->add_request("large");
|
99 |
-
$this->subject->add_response(array("output" => array("size" => 137857)), "large");
|
100 |
-
$this->wp->createImage(137857, "2015/09", "tinypng_gravatar-600x600.png");
|
101 |
-
$this->assertEquals($processing_count, $this->subject->get_in_progress_count());
|
102 |
}
|
103 |
|
104 |
-
public function
|
105 |
-
$
|
106 |
-
|
107 |
-
$this->subject->add_exception(new Tiny_Exception('Could not download output', 'OutputError'), "large");
|
108 |
-
$this->assertEquals($success_count, $this->subject->get_success_count());
|
109 |
}
|
110 |
|
111 |
-
public function
|
112 |
-
$
|
113 |
-
|
114 |
-
$this->subject->add_exception(new Tiny_Exception('Could not download output', 'OutputError'), "large");
|
115 |
-
$this->assertEquals($processing_count, $this->subject->get_in_progress_count());
|
116 |
-
}
|
117 |
-
|
118 |
-
public function testIsCompressedShouldReturnTrueForOriginal() {
|
119 |
-
$this->assertTrue($this->subject->is_compressed(Tiny_Metadata::ORIGINAL));
|
120 |
-
}
|
121 |
-
|
122 |
-
public function testIsCompressedShouldReturnTrueForCompressedSize() {
|
123 |
-
$this->assertTrue($this->subject->is_compressed("thumbnail"));
|
124 |
-
}
|
125 |
-
|
126 |
-
public function testIsCompressedShouldReturnFalseForUncompressedSize() {
|
127 |
-
$this->assertFalse($this->subject->is_compressed("large"));
|
128 |
-
}
|
129 |
-
|
130 |
-
public function testIsCompressedShouldReturnFalseWhenFilesizeOnFilesystemDoesNotMatchMeta() {
|
131 |
-
$meta = array(Tiny_Metadata::META_KEY => array(
|
132 |
-
"thumbnail" => array(
|
133 |
-
"input" => array("size" => 46480),
|
134 |
-
"output" => array("size" => 37856))
|
135 |
));
|
136 |
-
$this->wp->setMetadata(2, $meta);
|
137 |
-
$this->wp->createImage(37857, "2015/09", "tinypng_gravatar-150x150.png");
|
138 |
-
$tiny_meta = new Tiny_Metadata(2, $this->json("wp_meta_default_sizes"));
|
139 |
-
$this->assertFalse($tiny_meta->is_compressed("thumbnail"));
|
140 |
}
|
141 |
|
142 |
-
public function
|
143 |
-
$
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
)
|
148 |
-
$this->wp->setMetadata(3, $meta);
|
149 |
-
$tiny_meta = new Tiny_Metadata(3, $this->json("wp_meta_default_sizes"));
|
150 |
-
$this->assertFalse($tiny_meta->is_compressed("no_file"));
|
151 |
-
}
|
152 |
-
|
153 |
-
public function testIsCompressedShouldReturnFalseWhenNoMetadata() {
|
154 |
-
$this->wp->createImage(37856, "2015/09", "tinypng_gravatar-150x150.png");
|
155 |
-
$tiny_meta = new Tiny_Metadata(4, $this->json("wp_meta_default_sizes"));
|
156 |
-
$this->assertFalse($tiny_meta->is_compressed("thumbnail"));
|
157 |
-
}
|
158 |
-
|
159 |
-
public function testIsCompressingShouldReturnTrue() {
|
160 |
-
$meta = array(Tiny_Metadata::META_KEY => array(
|
161 |
-
"thumbnail" => array(
|
162 |
-
"start" => 1447925134,
|
163 |
-
"input" => array("size" => 46480))
|
164 |
-
));
|
165 |
-
$this->wp->setMetadata(5, $meta);
|
166 |
-
$this->wp->createImage(46480, "2015/09", "tinypng_gravatar-150x150.png");
|
167 |
-
$tiny_meta = new Tiny_Metadata(5, $this->json("wp_meta_default_sizes"));
|
168 |
-
$this->assertTrue($tiny_meta->is_compressing("thumbnail"));
|
169 |
-
}
|
170 |
-
|
171 |
-
public function testIsCompressingShouldReturnFalse() {
|
172 |
-
$this->assertFalse($this->subject->is_compressing("thumbnail"));
|
173 |
-
}
|
174 |
-
|
175 |
-
public function testIsResizedShouldReturnTrueForResizedImage() {
|
176 |
-
$meta = array(Tiny_Metadata::META_KEY => array(
|
177 |
-
Tiny_Metadata::ORIGINAL => array(
|
178 |
-
"output" => array("size" => 46480, "resized" => true))
|
179 |
-
));
|
180 |
-
$this->wp->setMetadata(7, $meta);
|
181 |
-
$tiny_meta = new Tiny_Metadata(7, $this->json("wp_meta_default_sizes"));
|
182 |
-
$this->assertTrue($tiny_meta->is_resized());
|
183 |
-
}
|
184 |
-
|
185 |
-
public function testIsResizedShouldReturnFalseForNotResizedSize() {
|
186 |
-
$this->assertFalse($this->subject->is_resized("thumbnail"));
|
187 |
-
}
|
188 |
-
|
189 |
-
public function testGetSizes() {
|
190 |
-
$this->assertEquals(
|
191 |
-
array(Tiny_Metadata::ORIGINAL, "thumbnail", "medium", "large"),
|
192 |
-
$this->subject->get_sizes());
|
193 |
-
}
|
194 |
-
|
195 |
-
public function testGetSizesWithDuplicates() {
|
196 |
-
$tiny_meta = new Tiny_Metadata(150, $this->json("wp_meta_sizes_with_same_files"));
|
197 |
-
$this->assertEquals(
|
198 |
-
array(Tiny_Metadata::ORIGINAL, "custom-size"),
|
199 |
-
$tiny_meta->get_sizes());
|
200 |
-
}
|
201 |
-
|
202 |
-
public function testGetSuccessSizes() {
|
203 |
-
$this->assertEquals(array(0, "thumbnail", "medium"), $this->subject->get_success_sizes());
|
204 |
-
}
|
205 |
-
|
206 |
-
public function testGetSuccessSizesShouldNotIncludeSizeIfNotOnFileSystem() {
|
207 |
-
$meta = array(Tiny_Metadata::META_KEY => array(
|
208 |
-
"additional_size" => array(
|
209 |
-
"start" => 1447925134,
|
210 |
-
"end" => 1447925138,
|
211 |
-
"input" => array("size" => 46480),
|
212 |
-
"output" => array("size" => 37856))
|
213 |
-
));
|
214 |
-
$this->wp->setMetadata(6, $meta);
|
215 |
-
$tiny_meta = new Tiny_Metadata(6, $this->json("wp_meta_default_sizes"));
|
216 |
-
$this->assertEquals(array(), $tiny_meta->get_success_sizes());
|
217 |
-
}
|
218 |
-
|
219 |
-
public function testGetCompressedSizes() {
|
220 |
-
$this->assertEquals(array(0, "thumbnail", "medium"), $this->subject->get_compressed_sizes());
|
221 |
-
}
|
222 |
-
|
223 |
-
public function testGetCompressedSizesShouldIncludeSizeEvenIfNotOnFileSystem() {
|
224 |
-
$meta = array(Tiny_Metadata::META_KEY => array(
|
225 |
-
"additional_size" => array(
|
226 |
-
"start" => 1447925134,
|
227 |
-
"end" => 1447925138,
|
228 |
-
"input" => array("size" => 46480),
|
229 |
-
"output" => array("size" => 37856))
|
230 |
-
));
|
231 |
-
$this->wp->setMetadata(6, $meta);
|
232 |
-
$tiny_meta = new Tiny_Metadata(6, $this->json("wp_meta_default_sizes"));
|
233 |
-
$this->assertEquals(array("additional_size"), $tiny_meta->get_compressed_sizes());
|
234 |
-
}
|
235 |
-
|
236 |
-
public function testGetUncompressedSizes() {
|
237 |
-
$this->wp->createImage(137857, "2015/09", "tinypng_gravatar-600x600.png");
|
238 |
-
$tinify_sizes = array(Tiny_Metadata::ORIGINAL, "thumbnail", "medium", "large");
|
239 |
-
$this->assertEquals(
|
240 |
-
array_values(array("large")),
|
241 |
-
array_values($this->subject->get_uncompressed_sizes($tinify_sizes)));
|
242 |
-
}
|
243 |
-
|
244 |
-
public function testGetUncompressedSizesShouldReturnOnlyUniqueSizes() {
|
245 |
-
$this->wp->addOption("tinypng_sizes[custom-size]", "on");
|
246 |
-
$this->wp->addOption("tinypng_sizes[custom-size-2]", "on");
|
247 |
-
$this->wp->addImageSize('custom-size', array('width' => 150, 'height' => 150));
|
248 |
-
$this->wp->addImageSize('custom-size-2', array('width' => 150, 'height' => 150));
|
249 |
-
$this->wp->createImages(array("150x150" => 37856), 146480, "2015/09", "panda");
|
250 |
-
|
251 |
-
$tiny_meta = new Tiny_Metadata(155, $this->json("wp_meta_sizes_with_same_files"));
|
252 |
-
|
253 |
-
$tinify_sizes = array(Tiny_Metadata::ORIGINAL, "custom-size", "custom-size-2");
|
254 |
-
$uncompressed_sizes = array(Tiny_Metadata::ORIGINAL, "custom-size");
|
255 |
-
$this->assertEquals($uncompressed_sizes, $tiny_meta->get_uncompressed_sizes($tinify_sizes));
|
256 |
-
}
|
257 |
-
|
258 |
-
public function testGetInProgressSizesShouldReturnEmptyArray() {
|
259 |
-
$this->assertEquals(array(), $this->subject->get_in_progress_sizes());
|
260 |
}
|
261 |
|
262 |
-
public function
|
263 |
-
$
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
)
|
268 |
-
$this->wp->setMetadata(5, $meta);
|
269 |
-
$tiny_meta = new Tiny_Metadata(5, $this->json("wp_meta_default_sizes"));
|
270 |
-
$this->assertEquals(array("thumbnail"), $tiny_meta->get_in_progress_sizes());
|
271 |
}
|
272 |
|
273 |
public function testGetLatestErrorShouldReturnMessage() {
|
274 |
-
$
|
275 |
-
$this->subject->
|
276 |
-
$this->subject->add_exception(new Tiny_Exception('Could not download output', 'OutputError'), "large");
|
277 |
$this->assertEquals("Could not download output", $this->subject->get_latest_error());
|
278 |
}
|
279 |
}
|
6 |
public function setUp() {
|
7 |
parent::setUp();
|
8 |
|
|
|
|
|
|
|
9 |
$meta = array(Tiny_Metadata::META_KEY => array(
|
10 |
Tiny_Metadata::ORIGINAL => array(
|
11 |
"input" => array("size" => 146480),
|
12 |
+
"output" => array("size" => 137856, "resized" => true)),
|
13 |
"thumbnail" => array(
|
14 |
"input" => array("size" => 46480),
|
15 |
"output" => array("size" => 37856)),
|
16 |
"medium" => array(
|
17 |
"input" => array("size" => 66480),
|
18 |
+
"output" => array("size" => 57856)),
|
19 |
));
|
20 |
$this->wp->setMetadata(1, $meta);
|
21 |
$this->wp->createImagesFromMeta($this->json("wp_meta_default_sizes"), $meta, 137856);
|
37 |
'width' => 2000,
|
38 |
'height' => 1000
|
39 |
);
|
40 |
+
$tiny_meta->get_image()->add_request();
|
41 |
+
$tiny_meta->get_image()->add_response(array('output' => array('width' => 200, 'height' => 100)));
|
42 |
$this->assertEquals(array('width' => 200, 'height' => 100), $tiny_meta->update_wp_metadata($wp_metadata));
|
43 |
}
|
44 |
|
45 |
+
public function testGetImagesShouldReturnAllImages() {
|
46 |
+
$this->assertEquals(array(Tiny_Metadata::ORIGINAL, 'medium', 'thumbnail', 'large'), array_keys(
|
47 |
+
$this->subject->get_images()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
|
50 |
+
public function testFilterImagesShouldFilterCorrectly() {
|
51 |
+
$this->assertEquals(array(Tiny_Metadata::ORIGINAL, 'thumbnail', 'medium'), array_keys(
|
52 |
+
$this->subject->filter_images('compressed')));
|
|
|
|
|
53 |
}
|
54 |
|
55 |
+
public function testFilterImagesShouldFilterCorrectlyWhenSizesAreGiven() {
|
56 |
+
$this->assertEquals(array(Tiny_Metadata::ORIGINAL), array_keys(
|
57 |
+
$this->subject->filter_images('compressed', array(Tiny_Metadata::ORIGINAL, 'invalid'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
));
|
|
|
|
|
|
|
|
|
59 |
}
|
60 |
|
61 |
+
public function testGetCountShouldAddCountCorrectly() {
|
62 |
+
$this->assertEquals(array(
|
63 |
+
'compressed' => 3,
|
64 |
+
'resized' => 1,
|
65 |
+
), $this->subject->get_count(array('compressed', 'resized'))
|
66 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
}
|
68 |
|
69 |
+
public function testGetCountShouldAddCountCorrectlyWhenSizesAreGiven() {
|
70 |
+
$this->assertEquals(array(
|
71 |
+
'compressed' => 1,
|
72 |
+
'resized' => 1,
|
73 |
+
), $this->subject->get_count(array('compressed', 'resized'), array(Tiny_Metadata::ORIGINAL, 'invalid'))
|
74 |
+
);
|
|
|
|
|
|
|
75 |
}
|
76 |
|
77 |
public function testGetLatestErrorShouldReturnMessage() {
|
78 |
+
$this->subject->get_image()->add_request("large");
|
79 |
+
$this->subject->get_image()->add_exception(new Tiny_Exception('Could not download output', 'OutputError'), "large");
|
|
|
80 |
$this->assertEquals("Could not download output", $this->subject->get_latest_error());
|
81 |
}
|
82 |
}
|
test/unit/TinyPluginTest.php
CHANGED
@@ -85,10 +85,10 @@ class Tiny_Plugin_Test extends TinyTestCase {
|
|
85 |
|
86 |
$testmeta = $this->wp->getTestMetadata();
|
87 |
$meta = new Tiny_Metadata(1, $testmeta);
|
88 |
-
$meta->add_request();
|
89 |
-
$meta->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test.png'));
|
90 |
-
$meta->
|
91 |
-
$meta->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test-large.png')
|
92 |
$meta->update();
|
93 |
|
94 |
$this->compressor->expects($this->once())->method('compress_file')->withConsecutive(
|
@@ -102,12 +102,12 @@ class Tiny_Plugin_Test extends TinyTestCase {
|
|
102 |
|
103 |
$testmeta = $this->wp->getTestMetadata();
|
104 |
$meta = new Tiny_Metadata(1, $testmeta);
|
105 |
-
$meta->add_request();
|
106 |
-
$meta->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test.png'));
|
107 |
-
$meta->
|
108 |
-
$meta->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test-large.png')
|
109 |
-
$meta->
|
110 |
-
$meta->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test-post-thumbnail.png')
|
111 |
$meta->update();
|
112 |
|
113 |
$this->vfs->getChild('wp-content/uploads/14/01/test-large.png')->truncate(100000);
|
85 |
|
86 |
$testmeta = $this->wp->getTestMetadata();
|
87 |
$meta = new Tiny_Metadata(1, $testmeta);
|
88 |
+
$meta->get_image()->add_request();
|
89 |
+
$meta->get_image()->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test.png'));
|
90 |
+
$meta->get_image('large')->add_request();
|
91 |
+
$meta->get_image('large')->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test-large.png'));
|
92 |
$meta->update();
|
93 |
|
94 |
$this->compressor->expects($this->once())->method('compress_file')->withConsecutive(
|
102 |
|
103 |
$testmeta = $this->wp->getTestMetadata();
|
104 |
$meta = new Tiny_Metadata(1, $testmeta);
|
105 |
+
$meta->get_image()->add_request();
|
106 |
+
$meta->get_image()->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test.png'));
|
107 |
+
$meta->get_image('large')->add_request();
|
108 |
+
$meta->get_image('large')->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test-large.png'));
|
109 |
+
$meta->get_image('post-thumbnail')->add_request();
|
110 |
+
$meta->get_image('post-thumbnail')->add_response(self::successCompress('vfs://root/wp-content/uploads/14/01/test-post-thumbnail.png'));
|
111 |
$meta->update();
|
112 |
|
113 |
$this->vfs->getChild('wp-content/uploads/14/01/test-large.png')->truncate(100000);
|
test/unit/TinyTestCase.php
CHANGED
@@ -33,6 +33,11 @@ abstract class TinyTestCase extends PHPUnit_Framework_TestCase {
|
|
33 |
$this->assertLessThanOrEqual($upper_bound, $actual, $message);
|
34 |
}
|
35 |
|
|
|
|
|
|
|
|
|
|
|
36 |
protected function json($file_name) {
|
37 |
return json_decode(file_get_contents(dirname(__FILE__) . "/../fixtures/json/" . $file_name . ".json"), true);
|
38 |
}
|
33 |
$this->assertLessThanOrEqual($upper_bound, $actual, $message);
|
34 |
}
|
35 |
|
36 |
+
protected function assertEqualWithinDelta($expected, $actual, $delta, $message='') {
|
37 |
+
$this->assertGreaterThanOrEqual($expected - $delta, $actual, $message);
|
38 |
+
$this->assertLessThanOrEqual($expected + $delta, $actual, $message);
|
39 |
+
}
|
40 |
+
|
41 |
protected function json($file_name) {
|
42 |
return json_decode(file_get_contents(dirname(__FILE__) . "/../fixtures/json/" . $file_name . ".json"), true);
|
43 |
}
|
test/unit/TinyWpBaseTest.php
CHANGED
@@ -15,7 +15,8 @@ class Tiny_WP_Base_Test extends TinyTestCase {
|
|
15 |
public function testShouldAddInitHooks() {
|
16 |
$this->assertEquals(array(
|
17 |
array('init', array($this->subject, 'init')),
|
18 |
-
array('admin_init', array($this->subject, 'admin_init'))
|
|
|
19 |
),
|
20 |
$this->wp->getCalls('add_action')
|
21 |
);
|
15 |
public function testShouldAddInitHooks() {
|
16 |
$this->assertEquals(array(
|
17 |
array('init', array($this->subject, 'init')),
|
18 |
+
array('admin_init', array($this->subject, 'admin_init')),
|
19 |
+
array('admin_menu', array($this->subject, 'admin_menu'))
|
20 |
),
|
21 |
$this->wp->getCalls('add_action')
|
22 |
);
|
tiny-compress-images.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* Plugin Name: Compress JPEG & PNG images
|
4 |
* Description: Speed up your website. Optimize your JPEG and PNG images automatically with TinyPNG.
|
5 |
-
* Version: 1.7.
|
6 |
* Author: TinyPNG
|
7 |
* Author URI: https://tinypng.com
|
8 |
* Text Domain: tiny-compress-images
|
@@ -16,6 +16,7 @@ require dirname(__FILE__) . '/src/class-tiny-exception.php';
|
|
16 |
require dirname(__FILE__) . '/src/class-tiny-compress.php';
|
17 |
require dirname(__FILE__) . '/src/class-tiny-compress-curl.php';
|
18 |
require dirname(__FILE__) . '/src/class-tiny-compress-fopen.php';
|
|
|
19 |
require dirname(__FILE__) . '/src/class-tiny-metadata.php';
|
20 |
require dirname(__FILE__) . '/src/class-tiny-settings.php';
|
21 |
require dirname(__FILE__) . '/src/class-tiny-plugin.php';
|
2 |
/**
|
3 |
* Plugin Name: Compress JPEG & PNG images
|
4 |
* Description: Speed up your website. Optimize your JPEG and PNG images automatically with TinyPNG.
|
5 |
+
* Version: 1.7.2
|
6 |
* Author: TinyPNG
|
7 |
* Author URI: https://tinypng.com
|
8 |
* Text Domain: tiny-compress-images
|
16 |
require dirname(__FILE__) . '/src/class-tiny-compress.php';
|
17 |
require dirname(__FILE__) . '/src/class-tiny-compress-curl.php';
|
18 |
require dirname(__FILE__) . '/src/class-tiny-compress-fopen.php';
|
19 |
+
require dirname(__FILE__) . '/src/class-tiny-metadata-image.php';
|
20 |
require dirname(__FILE__) . '/src/class-tiny-metadata.php';
|
21 |
require dirname(__FILE__) . '/src/class-tiny-settings.php';
|
22 |
require dirname(__FILE__) . '/src/class-tiny-plugin.php';
|