Version Description
- Media library now shows when files are in the process of being compressed.
Download this release
Release Info
Developer | TinyPNG |
Plugin | Compress JPEG & PNG images |
Version | 1.3.1 |
Comparing to | |
See all releases |
Code changes from version 1.5.0 to 1.3.1
- README.md +3 -3
- RELEASE +11 -13
- bin/docker-functions +1 -1
- bin/integration-tests +1 -7
- bin/restore-wordpress +1 -11
- bin/test-wordpress +2 -12
- config/Dockerfile-phantomjs +14 -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 +0 -15
- readme.txt +16 -35
- src/class-tiny-compress-curl.php +8 -19
- src/class-tiny-compress-fopen.php +13 -29
- src/class-tiny-compress.php +9 -45
- src/class-tiny-metadata.php +10 -26
- src/class-tiny-plugin.php +16 -43
- src/class-tiny-settings.php +7 -111
- src/class-tiny-wp-base.php +1 -10
- src/languages/tiny-compress-images-nl_NL.mo +0 -0
- src/languages/tiny-compress-images-nl_NL.po +14 -53
- src/languages/tiny-compress-images-ru_RU.mo +0 -0
- src/languages/tiny-compress-images-ru_RU.po +10 -1
- src/languages/tiny-compress-images-zh_TW.mo +0 -0
- src/languages/tiny-compress-images-zh_TW.po +0 -202
- src/scripts/admin.js +1 -28
- src/styles/admin.css +0 -12
- test/fixtures/input-large.jpg +0 -0
- test/helpers/setup.php +5 -11
- test/helpers/wordpress.php +1 -6
- test/integration/BulkCompressIntegrationTest.php +1 -1
- test/integration/CompressIntegrationTest.php +0 -60
- test/integration/IntegrationTestCase.php +0 -39
- test/integration/PluginIntegrationTest.php +0 -21
- test/integration/SettingsIntegrationTest.php +0 -66
- test/mock-tinypng-webservice/common.php +0 -45
- test/mock-tinypng-webservice/output-resized.jpg +0 -0
- test/mock-tinypng-webservice/output.php +1 -21
- test/mock-tinypng-webservice/reset.php +5 -2
- test/mock-tinypng-webservice/shrink.php +29 -22
- test/unit/TinyMetadataTest.php +0 -59
- test/unit/TinyPluginTest.php +11 -24
- test/unit/TinySettingsTest.php +0 -47
- test/unit/TinyTestCase.php +0 -5
- tiny-compress-images.php +3 -2
- trunk/tmp/.gitkeep +0 -0
README.md
CHANGED
@@ -28,9 +28,9 @@ Got questions or feedback? Let us know! Contact us at support@tinypng.com.
|
|
28 |
|
29 |
### Running the integration tests
|
30 |
1. Start Selenium server: `java -jar selenium-server-standalone-2.44.0.jar`.
|
31 |
-
2. Run `bin/integration-tests $version [$to_version]`
|
32 |
-
|
33 |
-
|
34 |
|
35 |
## License
|
36 |
Copyright (C) 2015 Voormedia B.V.
|
28 |
|
29 |
### Running the integration tests
|
30 |
1. Start Selenium server: `java -jar selenium-server-standalone-2.44.0.jar`.
|
31 |
+
2. Run `bin/integration-tests $version [$to_version]`. E.g. `bin/run-wordpress 41` or `bin/integration-tests 40 42`.
|
32 |
+
|
33 |
+
Note that when testing a different WordPress version, `bin/run-wordpress <version>` has to be run first.
|
34 |
|
35 |
## License
|
36 |
Copyright (C) 2015 Voormedia B.V.
|
RELEASE
CHANGED
@@ -2,16 +2,14 @@ In order to release a new version of the plugin to wordpress.org, perform the fo
|
|
2 |
|
3 |
1. Update the version in tiny-compress-images.php
|
4 |
2. Change the 'Stable tag' in readme.txt to the new release number.
|
5 |
-
3.
|
6 |
-
4.
|
7 |
-
5.
|
8 |
-
6.
|
9 |
-
7.
|
10 |
-
8.
|
11 |
-
9.
|
12 |
-
10.
|
13 |
-
11.
|
14 |
-
12.
|
15 |
-
13.
|
16 |
-
14. Commit the trunk to Subversion: `svn ci -m "<message>"`.
|
17 |
-
15. Tag the new release in Subversion and commit: `svn cp trunk tags/<version> && svn ci -m "<message>"`.
|
2 |
|
3 |
1. Update the version in tiny-compress-images.php
|
4 |
2. Change the 'Stable tag' in readme.txt to the new release number.
|
5 |
+
3. Commit and push to GitHub.
|
6 |
+
4. Create a new release in GitHub and pull it in.
|
7 |
+
5. Locally, checkout the new tag: `git checkout <tagged version>`.
|
8 |
+
6. If not already done so, checkout the plugin's Subversion repository: `svn co http://plugins.svn.wordpress.org/tiny-compress-images`.
|
9 |
+
7. Update svn:ignore property of trunk when .gitignore is updated: `svn propedit svn:ignore trunk`.
|
10 |
+
8. Delete everything in trunk `rm -rf <path-to-local-svn-repo/trunk/*`.
|
11 |
+
9. Manually copy the Git release to the local Subversion repo: `git ls-files | xargs tar c | tar x -C <path-to-local-svn-repo>/trunk/`.
|
12 |
+
10. Add new files `svn st | awk '/^\?/ { print $2; }' | xargs svn add`.
|
13 |
+
11. Delete deleted files: `svn st | awk '/^!/ { print $2; }' | xargs svn rm`.
|
14 |
+
12. Commit the trunk to Subversion: `svn ci -m "<message>"`.
|
15 |
+
13. Tag the new release in Subversion and commit: `svn cp trunk tags/<version> && svn ci -m "<message>"`.
|
|
|
|
bin/docker-functions
CHANGED
@@ -50,7 +50,7 @@ run_mysql() {
|
|
50 |
then
|
51 |
docker start "mysql-wordpress"
|
52 |
else
|
53 |
-
docker run --name mysql-wordpress -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql
|
54 |
fi
|
55 |
fi
|
56 |
}
|
50 |
then
|
51 |
docker start "mysql-wordpress"
|
52 |
else
|
53 |
+
docker run --name mysql-wordpress -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql
|
54 |
fi
|
55 |
fi
|
56 |
}
|
bin/integration-tests
CHANGED
@@ -7,13 +7,7 @@ use IO::Socket;
|
|
7 |
use Time::HiRes qw(usleep);
|
8 |
|
9 |
my $dir = dirname($0);
|
10 |
-
|
11 |
-
my $hostip;
|
12 |
-
if (`which docker-machine`) {
|
13 |
-
$hostip = `docker-machine ip $ENV{'DOCKER_MACHINE_NAME'}`;
|
14 |
-
} else {
|
15 |
-
$hostip = `boot2docker ip`;
|
16 |
-
}
|
17 |
|
18 |
sub check_port {
|
19 |
my ($ip, $port, $times, $sleep) = @_;
|
7 |
use Time::HiRes qw(usleep);
|
8 |
|
9 |
my $dir = dirname($0);
|
10 |
+
my $hostip = `boot2docker ip`;
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
sub check_port {
|
13 |
my ($ip, $port, $times, $sleep) = @_;
|
bin/restore-wordpress
CHANGED
@@ -19,17 +19,7 @@ source $DIR/docker-functions
|
|
19 |
export WORDPRESS_VERSION=$version
|
20 |
export WORDPRESS_DATABASE=wordpress_$version
|
21 |
export MYSQL_ROOT_PASSWORD=root
|
22 |
-
|
23 |
-
if hash docker-machine 2>/dev/null; then
|
24 |
-
export HOST_IP=$(docker-machine ip $DOCKER_MACHINE_NAME)
|
25 |
-
else
|
26 |
-
export HOST_IP=$(boot2docker ip)
|
27 |
-
fi
|
28 |
-
if [ -z "$HOST_IP" ]; then
|
29 |
-
echo "Could not find docker machine ip"
|
30 |
-
exit 2
|
31 |
-
fi
|
32 |
-
|
33 |
export MYSQL_DUMP_FILE=tmp/mysqldump_wordpress_$version.sql.gz
|
34 |
|
35 |
gunzip -c < $MYSQL_DUMP_FILE | mysql -h $HOST_IP -u root "-p$MYSQL_ROOT_PASSWORD" $WORDPRESS_DATABASE
|
19 |
export WORDPRESS_VERSION=$version
|
20 |
export WORDPRESS_DATABASE=wordpress_$version
|
21 |
export MYSQL_ROOT_PASSWORD=root
|
22 |
+
export HOST_IP=$(boot2docker ip)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
export MYSQL_DUMP_FILE=tmp/mysqldump_wordpress_$version.sql.gz
|
24 |
|
25 |
gunzip -c < $MYSQL_DUMP_FILE | mysql -h $HOST_IP -u root "-p$MYSQL_ROOT_PASSWORD" $WORDPRESS_DATABASE
|
bin/test-wordpress
CHANGED
@@ -26,17 +26,7 @@ fi
|
|
26 |
export WORDPRESS_VERSION=$version
|
27 |
export WORDPRESS_DATABASE=wordpress_$version
|
28 |
export MYSQL_ROOT_PASSWORD=root
|
29 |
-
|
30 |
-
if hash docker-machine 2>/dev/null; then
|
31 |
-
export HOST_IP=$(docker-machine ip $DOCKER_MACHINE_NAME)
|
32 |
-
else
|
33 |
-
export HOST_IP=$(boot2docker ip)
|
34 |
-
fi
|
35 |
-
if [ -z "$HOST_IP" ]; then
|
36 |
-
echo "Could not find docker machine ip"
|
37 |
-
exit 2
|
38 |
-
fi
|
39 |
-
|
40 |
export HOST_PORT=80$version
|
41 |
-
export WORDPRESS_URL=http://$
|
42 |
vendor/bin/phpunit "$PHPUNIT_ARG"
|
26 |
export WORDPRESS_VERSION=$version
|
27 |
export WORDPRESS_DATABASE=wordpress_$version
|
28 |
export MYSQL_ROOT_PASSWORD=root
|
29 |
+
export HOST_IP=$(boot2docker ip)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
export HOST_PORT=80$version
|
31 |
+
export WORDPRESS_URL=http://$(boot2docker ip):$HOST_PORT
|
32 |
vendor/bin/phpunit "$PHPUNIT_ARG"
|
config/Dockerfile-phantomjs
CHANGED
@@ -1,5 +1,17 @@
|
|
1 |
-
FROM
|
2 |
|
3 |
EXPOSE 8910
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM ubuntu:14.04
|
2 |
|
3 |
EXPOSE 8910
|
4 |
|
5 |
+
ENV PHANTOM_JS_VERSION 1.9.7-linux-x86_64
|
6 |
+
|
7 |
+
RUN apt-get update
|
8 |
+
RUN apt-get install -yqq curl libfreetype6 libfontconfig
|
9 |
+
# make ruby python git g++ flex bison gperf perl \
|
10 |
+
# libfontconfig1-dev libicu-dev libfreetype6 \
|
11 |
+
# libssl-dev libpng-dev libjpeg-dev
|
12 |
+
# RUN git clone git://github.com/ariya/phantomjs.git && cd phantomjs && ./build.sh && send "y\n"
|
13 |
+
|
14 |
+
RUN curl -sSL https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOM_JS_VERSION.tar.bz2 | tar xjC /
|
15 |
+
RUN ln -s phantomjs-$PHANTOM_JS_VERSION /phantomjs
|
16 |
+
|
17 |
+
CMD ["/phantomjs/bin/phantomjs", "--webdriver=8910"]
|
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.8
|
6 |
+
ENV WORDPRESS_UPSTREAM_VERSION 3.7.8
|
7 |
+
ENV WORDPRESS_SHA1 f6a326bc7fe8805a142d3c3e5db7857c336d8a75
|
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.8
|
6 |
+
ENV WORDPRESS_UPSTREAM_VERSION 3.8.8
|
7 |
+
ENV WORDPRESS_SHA1 8c5875ae76cdc9fb545e9e30591c67021bb1fafd
|
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.6
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 3.9.6
|
5 |
+
ENV WORDPRESS_SHA1 373c185080d0e3b2cd748277d013894e8a3af0d9
|
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.5
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 4.0.5
|
5 |
+
ENV WORDPRESS_SHA1 23de8e24ea68a19723b6ebc95f44c8d32df97a8e
|
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.5
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 4.1.5
|
5 |
+
ENV WORDPRESS_SHA1 85bc3f20d0ee8c98f9eabeba48eb37fe732eab33
|
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.2
|
4 |
+
ENV WORDPRESS_UPSTREAM_VERSION 4.2.2
|
5 |
+
ENV WORDPRESS_SHA1 d3a70d0f116e6afea5b850f793a81a97d2115039
|
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
DELETED
@@ -1,15 +0,0 @@
|
|
1 |
-
FROM wordpress:4
|
2 |
-
|
3 |
-
ENV WORDPRESS_VERSION 4.3.1
|
4 |
-
ENV WORDPRESS_UPSTREAM_VERSION 4.3.1
|
5 |
-
ENV WORDPRESS_SHA1 b2e5652a6d2333cabe7b37459362a3e5b8b66221
|
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
@@ -1,10 +1,10 @@
|
|
1 |
=== Compress JPEG & PNG images ===
|
2 |
Contributors: TinyPNG
|
3 |
Donate link: https://tinypng.com/
|
4 |
-
Tags: compress, optimize, shrink,
|
5 |
Requires at least: 3.0.6
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -16,17 +16,14 @@ Make your website faster by compressing your JPEG and PNG images. This plugin au
|
|
16 |
|
17 |
= Features =
|
18 |
|
19 |
-
* Automatically compress new images
|
20 |
-
* Resize large original images by setting a maximum width and/or height.
|
21 |
-
* Compress individual images already in your media library.
|
22 |
* Easy bulk compression of your existing media library.
|
23 |
-
*
|
24 |
* Multisite support with a single API key.
|
25 |
-
* Color profiles are translated to the standard RGB color space.
|
26 |
* See your usage directly from the media settings and during bulk compression.
|
27 |
-
*
|
28 |
-
*
|
29 |
-
* No file size
|
30 |
|
31 |
= How does it work? =
|
32 |
|
@@ -34,7 +31,7 @@ After you upload an image to your WordPress site, each resized image is uploaded
|
|
34 |
|
35 |
= Getting started =
|
36 |
|
37 |
-
Install this plugin and obtain your free API key from https://tinypng.com/developers.
|
38 |
|
39 |
= Multisite support =
|
40 |
|
@@ -94,39 +91,23 @@ A: No. There are no limitations on the size of the images you want to compress.
|
|
94 |
= Q: What happens when I reach my monthly compression limit? =
|
95 |
A: Everything will keep on working, but newly uploaded images will not be compressed. Of course we encourage everyone to sign up for a full subscription.
|
96 |
|
97 |
-
= Q: Can I compress all existing images in my media library? =
|
98 |
-
A: Yes! After installing the plugin, go to Tools > Compress JPEG & PNG images, and click on "Compress all images" to compress all uncompressed images in your media library.
|
99 |
-
|
100 |
== Changelog ==
|
101 |
|
102 |
-
= 1.5.0 =
|
103 |
-
* Resize original images when compressing. Set a maximum width and/or height and your original images will be scaled down in case they are bigger.
|
104 |
-
* Added support for the mobile WordPress app (thanks to David Goodwin).
|
105 |
-
|
106 |
-
= 1.4.0 =
|
107 |
-
* Indication of the number of images you can compress for free each month.
|
108 |
-
* Link to the settings page from the plugin listing.
|
109 |
-
* Clarification that original images will be overwritten when compressed.
|
110 |
-
|
111 |
-
= 1.3.2 =
|
112 |
-
* Detect different thumbnail sizes with the same dimensions so they will not be compressed again.
|
113 |
-
|
114 |
= 1.3.1 =
|
115 |
-
* Media library shows files
|
116 |
|
117 |
= 1.3.0 =
|
118 |
-
* Improved bulk
|
119 |
-
*
|
120 |
-
* Detection of image sizes modified after compression by other plugins.
|
121 |
|
122 |
= 1.2.1 =
|
123 |
-
*
|
124 |
|
125 |
= 1.2.0 =
|
126 |
* Display connection status and number of compressions this month on the settings page. This also allows you to check if you entered a valid API key.
|
127 |
-
* Show a notice to administrators when the limit
|
128 |
-
* The plugin now
|
129 |
-
*
|
130 |
|
131 |
= 1.1.0 =
|
132 |
* The API key can now be set with the TINY_API_KEY constant in wp-config.php. This will work for normal and multisite WordPress installations.
|
1 |
=== Compress JPEG & PNG images ===
|
2 |
Contributors: TinyPNG
|
3 |
Donate link: https://tinypng.com/
|
4 |
+
Tags: compress, optimize, shrink, improve, images, tinypng, tinyjpg, jpeg, jpg, png, lossy, jpegmini, crunch, minify, smush, save, bandwidth, website, speed, faster, performance, panda
|
5 |
Requires at least: 3.0.6
|
6 |
+
Tested up to: 4.2
|
7 |
+
Stable tag: 1.3.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
16 |
|
17 |
= Features =
|
18 |
|
19 |
+
* Automatically compress new images.
|
|
|
|
|
20 |
* Easy bulk compression of your existing media library.
|
21 |
+
* Compress individual images already in your media library.
|
22 |
* Multisite support with a single API key.
|
|
|
23 |
* See your usage directly from the media settings and during bulk compression.
|
24 |
+
* Select which thumbnail sizes of an image may be compressed.
|
25 |
+
* Automatic detection of images that can be recompressed.
|
26 |
+
* No file size limit.
|
27 |
|
28 |
= How does it work? =
|
29 |
|
31 |
|
32 |
= Getting started =
|
33 |
|
34 |
+
Install this plugin and obtain your free API key from https://tinypng.com/developers. The first 500 compressions per month are completely free, so roughly 100 images can be uploaded to WordPress for free, no strings attached! You can also change which of the generated thumbnail sizes should be compressed, because each one of them counts as a compression. And if you’re a heavy user, you can compress more than 500 images per month for a small additional fee per image.
|
35 |
|
36 |
= Multisite support =
|
37 |
|
91 |
= Q: What happens when I reach my monthly compression limit? =
|
92 |
A: Everything will keep on working, but newly uploaded images will not be compressed. Of course we encourage everyone to sign up for a full subscription.
|
93 |
|
|
|
|
|
|
|
94 |
== Changelog ==
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
= 1.3.1 =
|
97 |
+
* Media library now shows when files are in the process of being compressed.
|
98 |
|
99 |
= 1.3.0 =
|
100 |
+
* Improved bulk compressions from media library. You can now also bulk compress your whole media library in one step.
|
101 |
+
* Intelligent detection if file is already compressed or was altered by another plugin and should be recompressed.
|
|
|
102 |
|
103 |
= 1.2.1 =
|
104 |
+
* Bugfix that prevents recompressing the original when no additional image sizes can be found in the metadata. (introduced in 1.2.0)
|
105 |
|
106 |
= 1.2.0 =
|
107 |
* Display connection status and number of compressions this month on the settings page. This also allows you to check if you entered a valid API key.
|
108 |
+
* Show a notice to administrators when reaching the monthly compression limit (in case you're on a fixed or free plan).
|
109 |
+
* The plugin will now work when php's parse_ini_file is disabled on your host.
|
110 |
+
* Bugfix that avoids a warning when no additional image sizes can be found in the metadata.
|
111 |
|
112 |
= 1.1.0 =
|
113 |
* The API key can now be set with the TINY_API_KEY constant in wp-config.php. This will work for normal and multisite WordPress installations.
|
src/class-tiny-compress-curl.php
CHANGED
@@ -47,48 +47,37 @@ class Tiny_Compress_Curl extends Tiny_Compress {
|
|
47 |
|
48 |
$output_url = null;
|
49 |
$response = curl_exec($request);
|
50 |
-
if ($response === false
|
51 |
return array(array(
|
52 |
'error' => 'CurlError',
|
53 |
-
'message' => sprintf("
|
54 |
), null
|
55 |
);
|
56 |
}
|
57 |
|
58 |
$header_size = curl_getinfo($request, CURLINFO_HEADER_SIZE);
|
59 |
-
$status_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
|
60 |
$headers = self::parse_headers(substr($response, 0, $header_size));
|
61 |
curl_close($request);
|
62 |
|
63 |
-
return array(self::decode(substr($response, $header_size)), $headers
|
64 |
}
|
65 |
|
66 |
-
protected function output_options($url
|
67 |
-
|
68 |
CURLOPT_URL => $url,
|
69 |
CURLOPT_RETURNTRANSFER => true,
|
70 |
-
CURLOPT_HEADER => true,
|
71 |
CURLOPT_CAINFO => self::get_ca_file(),
|
72 |
CURLOPT_SSL_VERIFYPEER => true
|
73 |
);
|
74 |
-
if ($resize) {
|
75 |
-
$options[CURLOPT_USERPWD] = 'api:' . $this->api_key;
|
76 |
-
$options[CURLOPT_HTTPHEADER] = array('Content-Type: application/json');
|
77 |
-
$options[CURLOPT_POSTFIELDS] = json_encode(array('resize' => $resize));
|
78 |
-
}
|
79 |
-
return $options;
|
80 |
}
|
81 |
|
82 |
-
protected function output($url
|
83 |
$request = curl_init();
|
84 |
-
$
|
85 |
-
curl_setopt_array($request, $options);
|
86 |
|
87 |
$response = curl_exec($request);
|
88 |
-
$header_size = curl_getinfo($request, CURLINFO_HEADER_SIZE);
|
89 |
-
$headers = self::parse_headers(substr($response, 0, $header_size));
|
90 |
curl_close($request);
|
91 |
|
92 |
-
return
|
93 |
}
|
94 |
}
|
47 |
|
48 |
$output_url = null;
|
49 |
$response = curl_exec($request);
|
50 |
+
if ($response === false) {
|
51 |
return array(array(
|
52 |
'error' => 'CurlError',
|
53 |
+
'message' => sprintf("%s [%d]", curl_error($request), curl_errno($request))
|
54 |
), null
|
55 |
);
|
56 |
}
|
57 |
|
58 |
$header_size = curl_getinfo($request, CURLINFO_HEADER_SIZE);
|
|
|
59 |
$headers = self::parse_headers(substr($response, 0, $header_size));
|
60 |
curl_close($request);
|
61 |
|
62 |
+
return array(self::decode(substr($response, $header_size)), $headers);
|
63 |
}
|
64 |
|
65 |
+
protected function output_options($url) {
|
66 |
+
return array(
|
67 |
CURLOPT_URL => $url,
|
68 |
CURLOPT_RETURNTRANSFER => true,
|
|
|
69 |
CURLOPT_CAINFO => self::get_ca_file(),
|
70 |
CURLOPT_SSL_VERIFYPEER => true
|
71 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
|
74 |
+
protected function output($url) {
|
75 |
$request = curl_init();
|
76 |
+
curl_setopt_array($request, $this->output_options($url));
|
|
|
77 |
|
78 |
$response = curl_exec($request);
|
|
|
|
|
79 |
curl_close($request);
|
80 |
|
81 |
+
return $response;
|
82 |
}
|
83 |
}
|
src/class-tiny-compress-fopen.php
CHANGED
@@ -41,21 +41,11 @@ class Tiny_Compress_Fopen extends Tiny_Compress {
|
|
41 |
$context = stream_context_create($this->shrink_options($input));
|
42 |
$request = @fopen(Tiny_Config::URL, 'r', false, $context);
|
43 |
|
44 |
-
$status_code = null;
|
45 |
-
if ($http_response_header && count($http_response_header) > 0) {
|
46 |
-
$http_code_values = explode(' ', $http_response_header[0]);
|
47 |
-
if (count($http_code_values) > 1) {
|
48 |
-
$status_code = intval($http_code_values[1]);
|
49 |
-
}
|
50 |
-
}
|
51 |
-
|
52 |
if (!$request) {
|
53 |
-
$headers = self::parse_headers($http_response_header);
|
54 |
-
|
55 |
return array(array(
|
56 |
'error' => 'FopenError',
|
57 |
-
'message' => 'Could not compress, enable cURL for detailed error'
|
58 |
-
),
|
59 |
);
|
60 |
}
|
61 |
|
@@ -64,11 +54,11 @@ class Tiny_Compress_Fopen extends Tiny_Compress {
|
|
64 |
$headers = self::parse_headers($meta_data['wrapper_data']);
|
65 |
fclose($request);
|
66 |
|
67 |
-
return array(self::decode($response), $headers
|
68 |
}
|
69 |
|
70 |
-
protected function output_options(
|
71 |
-
|
72 |
'http' => array(
|
73 |
'method' => 'GET',
|
74 |
),
|
@@ -77,29 +67,23 @@ class Tiny_Compress_Fopen extends Tiny_Compress {
|
|
77 |
'verify_peer' => true
|
78 |
)
|
79 |
);
|
80 |
-
if ($resize) {
|
81 |
-
$options['http']['header'] = array(
|
82 |
-
'Authorization: Basic ' . base64_encode('api:' . $this->api_key),
|
83 |
-
'Content-Type: application/json'
|
84 |
-
);
|
85 |
-
$options['http']['content'] = json_encode(array('resize' => $resize));
|
86 |
-
}
|
87 |
-
return $options;
|
88 |
}
|
89 |
|
90 |
-
protected function output($url
|
91 |
-
$context = stream_context_create($this->output_options(
|
92 |
$request = @fopen($url, 'rb', false, $context);
|
93 |
|
94 |
if ($request) {
|
95 |
$response = stream_get_contents($request);
|
96 |
-
$meta_data = stream_get_meta_data($request);
|
97 |
-
$headers = self::parse_headers($meta_data['wrapper_data']);
|
98 |
fclose($request);
|
99 |
} else {
|
100 |
$response = '';
|
101 |
-
$headers = array();
|
102 |
}
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
}
|
41 |
$context = stream_context_create($this->shrink_options($input));
|
42 |
$request = @fopen(Tiny_Config::URL, 'r', false, $context);
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
if (!$request) {
|
|
|
|
|
45 |
return array(array(
|
46 |
'error' => 'FopenError',
|
47 |
+
'message' => 'Could not compress, enable cURL for detailed error'
|
48 |
+
), null
|
49 |
);
|
50 |
}
|
51 |
|
54 |
$headers = self::parse_headers($meta_data['wrapper_data']);
|
55 |
fclose($request);
|
56 |
|
57 |
+
return array(self::decode($response), $headers);
|
58 |
}
|
59 |
|
60 |
+
protected function output_options() {
|
61 |
+
return array(
|
62 |
'http' => array(
|
63 |
'method' => 'GET',
|
64 |
),
|
67 |
'verify_peer' => true
|
68 |
)
|
69 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
|
72 |
+
protected function output($url) {
|
73 |
+
$context = stream_context_create($this->output_options());
|
74 |
$request = @fopen($url, 'rb', false, $context);
|
75 |
|
76 |
if ($request) {
|
77 |
$response = stream_get_contents($request);
|
|
|
|
|
78 |
fclose($request);
|
79 |
} else {
|
80 |
$response = '';
|
|
|
81 |
}
|
82 |
+
|
83 |
+
return $response;
|
84 |
+
}
|
85 |
+
|
86 |
+
public function get_status(&$details) {
|
87 |
+
return null;
|
88 |
}
|
89 |
}
|
src/class-tiny-compress.php
CHANGED
@@ -41,20 +41,20 @@ abstract class Tiny_Compress {
|
|
41 |
}
|
42 |
|
43 |
abstract protected function shrink($input);
|
44 |
-
abstract protected function output($url
|
45 |
|
46 |
public function get_status(&$details) {
|
47 |
-
list($details, $headers
|
48 |
|
49 |
$this->call_after_compress_callback($details, $headers);
|
50 |
-
if ($
|
51 |
return true;
|
52 |
} else {
|
53 |
return false;
|
54 |
}
|
55 |
}
|
56 |
|
57 |
-
public function compress($input
|
58 |
list($details, $headers) = $this->shrink($input);
|
59 |
$this->call_after_compress_callback($details, $headers);
|
60 |
$outputUrl = isset($headers['location']) ? $headers['location'] : null;
|
@@ -63,31 +63,19 @@ abstract class Tiny_Compress {
|
|
63 |
} else if ($outputUrl === null) {
|
64 |
throw new Tiny_Exception('Could not find output url', 'OutputNotFound');
|
65 |
}
|
66 |
-
|
67 |
-
$this->call_after_compress_callback(null, $headers);
|
68 |
if (strlen($output) == 0) {
|
69 |
throw new Tiny_Exception('Could not download output', 'OutputError');
|
70 |
}
|
71 |
-
|
72 |
return array($output, $details);
|
73 |
}
|
74 |
|
75 |
-
public function compress_file($file
|
76 |
if (!file_exists($file)) {
|
77 |
-
throw new Tiny_Exception('File does not
|
78 |
-
}
|
79 |
-
|
80 |
-
if (!self::needs_resize($file, $resize_options)) {
|
81 |
-
$resize_options = false;
|
82 |
}
|
83 |
-
|
84 |
-
list($output, $details) = $this->compress(file_get_contents($file), $resize_options);
|
85 |
file_put_contents($file, $output);
|
86 |
-
|
87 |
-
if ($resize_options) {
|
88 |
-
$details['output'] = self::update_details($file, $details) + $details['output'];
|
89 |
-
}
|
90 |
-
|
91 |
return $details;
|
92 |
}
|
93 |
|
@@ -114,33 +102,9 @@ abstract class Tiny_Compress {
|
|
114 |
protected static function decode($text) {
|
115 |
$result = json_decode($text, true);
|
116 |
if ($result === null) {
|
117 |
-
throw new Tiny_Exception(
|
118 |
-
PHP_VERSION_ID >= 50500 ? json_last_error_msg() : 'Error',
|
119 |
-
json_last_error()),
|
120 |
-
'JsonError');
|
121 |
}
|
122 |
return $result;
|
123 |
}
|
124 |
-
|
125 |
-
protected static function needs_resize($file, $resize_options) {
|
126 |
-
if (!$resize_options) {
|
127 |
-
return false;
|
128 |
-
}
|
129 |
-
|
130 |
-
list($width, $height) = getimagesize($file);
|
131 |
-
return $width > $resize_options['width'] || $height > $resize_options['height'];
|
132 |
-
}
|
133 |
-
|
134 |
-
protected static function update_details($file, $details) {
|
135 |
-
$size = filesize($file);
|
136 |
-
list($width, $height) = getimagesize($file);
|
137 |
-
return array(
|
138 |
-
'size' => $size,
|
139 |
-
'width' => $width,
|
140 |
-
'height' => $height,
|
141 |
-
'ratio' => round($size / $details['input']['size'], 4),
|
142 |
-
'resized' => true
|
143 |
-
);
|
144 |
-
}
|
145 |
}
|
146 |
|
41 |
}
|
42 |
|
43 |
abstract protected function shrink($input);
|
44 |
+
abstract protected function output($url);
|
45 |
|
46 |
public function get_status(&$details) {
|
47 |
+
list($details, $headers) = $this->shrink(null);
|
48 |
|
49 |
$this->call_after_compress_callback($details, $headers);
|
50 |
+
if (!isset($details['error']) || $details["error"] == 'InputMissing' || $details["error"] == 'TooManyRequests') {
|
51 |
return true;
|
52 |
} else {
|
53 |
return false;
|
54 |
}
|
55 |
}
|
56 |
|
57 |
+
public function compress($input) {
|
58 |
list($details, $headers) = $this->shrink($input);
|
59 |
$this->call_after_compress_callback($details, $headers);
|
60 |
$outputUrl = isset($headers['location']) ? $headers['location'] : null;
|
63 |
} else if ($outputUrl === null) {
|
64 |
throw new Tiny_Exception('Could not find output url', 'OutputNotFound');
|
65 |
}
|
66 |
+
$output = $this->output($outputUrl);
|
|
|
67 |
if (strlen($output) == 0) {
|
68 |
throw new Tiny_Exception('Could not download output', 'OutputError');
|
69 |
}
|
|
|
70 |
return array($output, $details);
|
71 |
}
|
72 |
|
73 |
+
public function compress_file($file) {
|
74 |
if (!file_exists($file)) {
|
75 |
+
throw new Tiny_Exception('File does not exists', 'FileError');
|
|
|
|
|
|
|
|
|
76 |
}
|
77 |
+
list($output, $details) = $this->compress(file_get_contents($file));
|
|
|
78 |
file_put_contents($file, $output);
|
|
|
|
|
|
|
|
|
|
|
79 |
return $details;
|
80 |
}
|
81 |
|
102 |
protected static function decode($text) {
|
103 |
$result = json_decode($text, true);
|
104 |
if ($result === null) {
|
105 |
+
throw new Tiny_Exception('Could not decode JSON', 'JsonError');
|
|
|
|
|
|
|
106 |
}
|
107 |
return $result;
|
108 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
|
src/class-tiny-metadata.php
CHANGED
@@ -58,37 +58,25 @@ class Tiny_Metadata {
|
|
58 |
|
59 |
$this->filenames[self::ORIGINAL] = "$path_prefix${path_info['basename']}";
|
60 |
$this->urls[self::ORIGINAL] = "$url_prefix${path_info['basename']}";
|
61 |
-
|
62 |
-
$unique_sizes = array();
|
63 |
if (isset($wp_metadata['sizes']) && is_array($wp_metadata['sizes'])) {
|
64 |
foreach ($wp_metadata['sizes'] as $size => $info) {
|
65 |
-
$
|
66 |
-
|
67 |
-
if (!isset($unique_sizes[$filename])) {
|
68 |
-
$this->filenames[$size] = "$path_prefix$filename";
|
69 |
-
$this->urls[$size] = "$url_prefix$filename";
|
70 |
-
$unique_sizes[$filename] = true;
|
71 |
-
}
|
72 |
}
|
73 |
}
|
74 |
}
|
75 |
|
76 |
-
public function update_wp_metadata($wp_metadata) {
|
77 |
-
$tiny_metadata = $this->get_value();
|
78 |
-
if (isset($tiny_metadata) && isset($tiny_metadata['output']) && isset($tiny_metadata['output']['width']) && isset($tiny_metadata['output']['height'])) {
|
79 |
-
$wp_metadata['width'] = $tiny_metadata['output']['width'];
|
80 |
-
$wp_metadata['height'] = $tiny_metadata['output']['height'];
|
81 |
-
}
|
82 |
-
return $wp_metadata;
|
83 |
-
}
|
84 |
-
|
85 |
public function update() {
|
86 |
update_post_meta($this->id, self::META_KEY, $this->values);
|
87 |
}
|
88 |
|
89 |
public function add_response($response, $size=self::ORIGINAL) {
|
90 |
-
$
|
91 |
-
|
|
|
|
|
|
|
|
|
92 |
}
|
93 |
|
94 |
public function add_request($size=self::ORIGINAL) {
|
@@ -140,8 +128,8 @@ class Tiny_Metadata {
|
|
140 |
return array_filter(array_keys($this->values), array($this, 'is_compressed'));
|
141 |
}
|
142 |
|
143 |
-
public function
|
144 |
-
$sizes = array_intersect($this->get_sizes(), $
|
145 |
return array_diff($sizes, $this->get_success_sizes());
|
146 |
}
|
147 |
|
@@ -176,8 +164,4 @@ class Tiny_Metadata {
|
|
176 |
}
|
177 |
return $result;
|
178 |
}
|
179 |
-
|
180 |
-
public function is_resizable($size) {
|
181 |
-
return $size === self::ORIGINAL;
|
182 |
-
}
|
183 |
}
|
58 |
|
59 |
$this->filenames[self::ORIGINAL] = "$path_prefix${path_info['basename']}";
|
60 |
$this->urls[self::ORIGINAL] = "$url_prefix${path_info['basename']}";
|
|
|
|
|
61 |
if (isset($wp_metadata['sizes']) && is_array($wp_metadata['sizes'])) {
|
62 |
foreach ($wp_metadata['sizes'] as $size => $info) {
|
63 |
+
$this->filenames[$size] = "$path_prefix${info['file']}";
|
64 |
+
$this->urls[$size] = "$url_prefix${info['file']}";
|
|
|
|
|
|
|
|
|
|
|
65 |
}
|
66 |
}
|
67 |
}
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
public function update() {
|
70 |
update_post_meta($this->id, self::META_KEY, $this->values);
|
71 |
}
|
72 |
|
73 |
public function add_response($response, $size=self::ORIGINAL) {
|
74 |
+
$data = array(
|
75 |
+
'input' => array('size' => $response['input']['size']),
|
76 |
+
'output' => array('size' => $response['output']['size']),
|
77 |
+
'end' => time()
|
78 |
+
);
|
79 |
+
$this->values[$size] = array_merge($this->values[$size], $data);
|
80 |
}
|
81 |
|
82 |
public function add_request($size=self::ORIGINAL) {
|
128 |
return array_filter(array_keys($this->values), array($this, 'is_compressed'));
|
129 |
}
|
130 |
|
131 |
+
public function get_missing_sizes($tinify_sizes) {
|
132 |
+
$sizes = array_intersect($this->get_sizes(), $tinify_sizes);
|
133 |
return array_diff($sizes, $this->get_success_sizes());
|
134 |
}
|
135 |
|
164 |
}
|
165 |
return $result;
|
166 |
}
|
|
|
|
|
|
|
|
|
167 |
}
|
src/class-tiny-plugin.php
CHANGED
@@ -54,8 +54,6 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
54 |
add_action('wp_ajax_tiny_compress_image', $this->get_method('compress_image'));
|
55 |
add_action('admin_action_tiny_bulk_compress', $this->get_method('bulk_compress'));
|
56 |
add_action('admin_enqueue_scripts', $this->get_method('enqueue_scripts'));
|
57 |
-
$plugin = plugin_basename(dirname(dirname(__FILE__)) . '/tiny-compress-images.php');
|
58 |
-
add_filter("plugin_action_links_$plugin", $this->get_method('add_plugin_links'));
|
59 |
}
|
60 |
|
61 |
public function admin_menu() {
|
@@ -66,12 +64,6 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
66 |
|
67 |
}
|
68 |
|
69 |
-
public function add_plugin_links($current_links) {
|
70 |
-
$additional[] = sprintf('<a href="options-media.php#%s">%s</a>', self::NAME,
|
71 |
-
self::translate_escape('Settings'));
|
72 |
-
return array_merge($additional, $current_links);
|
73 |
-
}
|
74 |
-
|
75 |
public function enqueue_scripts($hook) {
|
76 |
wp_enqueue_style(self::NAME .'_admin', plugins_url('/styles/admin.css', __FILE__),
|
77 |
array(), self::plugin_version());
|
@@ -102,26 +94,25 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
102 |
$tiny_metadata = new Tiny_Metadata($attachment_id, $metadata);
|
103 |
|
104 |
if ($this->settings->get_compressor() === null || strpos($mime_type, 'image/') !== 0) {
|
105 |
-
return
|
106 |
}
|
107 |
|
108 |
$success = 0;
|
109 |
$failed = 0;
|
110 |
|
111 |
$compressor = $this->settings->get_compressor();
|
112 |
-
$
|
113 |
-
$
|
114 |
-
|
115 |
-
foreach ($uncompressed_sizes as $uncompressed_size) {
|
116 |
try {
|
117 |
-
$tiny_metadata->add_request($
|
118 |
$tiny_metadata->update();
|
119 |
-
|
120 |
-
$response = $compressor->compress_file($tiny_metadata->get_filename($
|
121 |
-
$tiny_metadata->add_response($response, $
|
122 |
$success++;
|
123 |
} catch (Tiny_Exception $e) {
|
124 |
-
$tiny_metadata->add_exception($e, $
|
125 |
$failed++;
|
126 |
}
|
127 |
}
|
@@ -131,8 +122,8 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
131 |
}
|
132 |
|
133 |
public function compress_attachment($metadata, $attachment_id) {
|
134 |
-
|
135 |
-
return $
|
136 |
}
|
137 |
|
138 |
public function compress_image() {
|
@@ -159,8 +150,6 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
159 |
}
|
160 |
|
161 |
list($tiny_metadata, $result) = $this->compress($metadata, $id);
|
162 |
-
wp_update_attachment_metadata($id, $tiny_metadata->update_wp_metadata($metadata));
|
163 |
-
|
164 |
if ($json) {
|
165 |
$result['message'] = $tiny_metadata->get_latest_error();
|
166 |
$result['status'] = $this->settings->get_status();
|
@@ -201,22 +190,13 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
201 |
}
|
202 |
|
203 |
private function render_compress_details($tiny_metadata) {
|
204 |
-
$missing = $tiny_metadata->
|
205 |
$success = count($tiny_metadata->get_success_sizes());
|
206 |
$total = count($missing) + $success;
|
207 |
$progress = count($tiny_metadata->get_in_progress_sizes());
|
208 |
|
209 |
-
$duplicates = count($this->settings->get_active_tinify_sizes()) - $total;
|
210 |
-
$success += $duplicates;
|
211 |
-
$total += $duplicates;
|
212 |
-
|
213 |
if (count($missing) > 0) {
|
214 |
printf(self::translate_escape('Compressed %d out of %d sizes'), $success, $total);
|
215 |
-
$original = $tiny_metadata->get_value();
|
216 |
-
if (isset($original['output']['resized'])) {
|
217 |
-
echo '<br/>';
|
218 |
-
printf(self::translate_escape('Resized original to %dx%d'), $original['output']['width'], $original['output']['height']);
|
219 |
-
}
|
220 |
echo '<br/>';
|
221 |
if (($error = $tiny_metadata->get_latest_error())) {
|
222 |
echo '<span class="error">' . self::translate_escape('Latest error') . ': '. self::translate_escape($error) .'</span><br/>';
|
@@ -225,14 +205,9 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
225 |
self::translate_escape('Compress') . '</button>';
|
226 |
echo '<div class="spinner hidden"></div>';
|
227 |
} elseif ($progress > 0) {
|
228 |
-
printf(self::translate_escape('Compressing %d sizes...'), count($this->settings->
|
229 |
} else {
|
230 |
printf(self::translate_escape('Compressed %d out of %d sizes'), $success, $total);
|
231 |
-
$original = $tiny_metadata->get_value();
|
232 |
-
if (isset($original['output']['resized'])) {
|
233 |
-
echo '<br/>';
|
234 |
-
printf(self::translate_escape('Resized original to %dx%d'), $original['output']['width'], $original['output']['height']);
|
235 |
-
}
|
236 |
$savings = $tiny_metadata->get_savings();
|
237 |
if ($savings['count'] > 0) {
|
238 |
echo '<br/>';
|
@@ -249,14 +224,12 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
249 |
echo '<h2>' . self::translate('Compress JPEG & PNG Images') . '</h2>';
|
250 |
if (empty($_POST['tiny-bulk-compress']) && empty($_REQUEST['ids'])) {
|
251 |
$result = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' ORDER BY ID DESC", ARRAY_A);
|
252 |
-
$
|
253 |
-
$sizes_count = count($this->settings->get_active_tinify_sizes());
|
254 |
|
255 |
echo '<p>' . self::translate_escape("Use this tool to compress all images in your media library") . '. ';
|
256 |
echo self::translate_escape("Only images that have not been compressed will be compressed") . '.</p>';
|
257 |
-
echo '<p>' . sprintf(self::translate_escape("We have found %d images in your media library
|
258 |
-
echo
|
259 |
-
echo '<p>' . self::translate_escape("To begin, just press the button below") . '.</p>';
|
260 |
|
261 |
echo '<form method="POST" action="?page=tiny-bulk-compress">';
|
262 |
echo '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce('tiny-bulk-compress') . '">';
|
54 |
add_action('wp_ajax_tiny_compress_image', $this->get_method('compress_image'));
|
55 |
add_action('admin_action_tiny_bulk_compress', $this->get_method('bulk_compress'));
|
56 |
add_action('admin_enqueue_scripts', $this->get_method('enqueue_scripts'));
|
|
|
|
|
57 |
}
|
58 |
|
59 |
public function admin_menu() {
|
64 |
|
65 |
}
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
public function enqueue_scripts($hook) {
|
68 |
wp_enqueue_style(self::NAME .'_admin', plugins_url('/styles/admin.css', __FILE__),
|
69 |
array(), self::plugin_version());
|
94 |
$tiny_metadata = new Tiny_Metadata($attachment_id, $metadata);
|
95 |
|
96 |
if ($this->settings->get_compressor() === null || strpos($mime_type, 'image/') !== 0) {
|
97 |
+
return $metadata;
|
98 |
}
|
99 |
|
100 |
$success = 0;
|
101 |
$failed = 0;
|
102 |
|
103 |
$compressor = $this->settings->get_compressor();
|
104 |
+
$sizes = $this->settings->get_tinify_sizes();
|
105 |
+
$missing = $tiny_metadata->get_missing_sizes($sizes);
|
106 |
+
foreach ($missing as $size) {
|
|
|
107 |
try {
|
108 |
+
$tiny_metadata->add_request($size);
|
109 |
$tiny_metadata->update();
|
110 |
+
|
111 |
+
$response = $compressor->compress_file($tiny_metadata->get_filename($size));
|
112 |
+
$tiny_metadata->add_response($response, $size);
|
113 |
$success++;
|
114 |
} catch (Tiny_Exception $e) {
|
115 |
+
$tiny_metadata->add_exception($e, $size);
|
116 |
$failed++;
|
117 |
}
|
118 |
}
|
122 |
}
|
123 |
|
124 |
public function compress_attachment($metadata, $attachment_id) {
|
125 |
+
$this->compress($metadata, $attachment_id);
|
126 |
+
return $metadata;
|
127 |
}
|
128 |
|
129 |
public function compress_image() {
|
150 |
}
|
151 |
|
152 |
list($tiny_metadata, $result) = $this->compress($metadata, $id);
|
|
|
|
|
153 |
if ($json) {
|
154 |
$result['message'] = $tiny_metadata->get_latest_error();
|
155 |
$result['status'] = $this->settings->get_status();
|
190 |
}
|
191 |
|
192 |
private function render_compress_details($tiny_metadata) {
|
193 |
+
$missing = $tiny_metadata->get_missing_sizes($this->settings->get_tinify_sizes());
|
194 |
$success = count($tiny_metadata->get_success_sizes());
|
195 |
$total = count($missing) + $success;
|
196 |
$progress = count($tiny_metadata->get_in_progress_sizes());
|
197 |
|
|
|
|
|
|
|
|
|
198 |
if (count($missing) > 0) {
|
199 |
printf(self::translate_escape('Compressed %d out of %d sizes'), $success, $total);
|
|
|
|
|
|
|
|
|
|
|
200 |
echo '<br/>';
|
201 |
if (($error = $tiny_metadata->get_latest_error())) {
|
202 |
echo '<span class="error">' . self::translate_escape('Latest error') . ': '. self::translate_escape($error) .'</span><br/>';
|
205 |
self::translate_escape('Compress') . '</button>';
|
206 |
echo '<div class="spinner hidden"></div>';
|
207 |
} elseif ($progress > 0) {
|
208 |
+
printf(self::translate_escape('Compressing %d sizes...'), count($this->settings->get_tinify_sizes()));
|
209 |
} else {
|
210 |
printf(self::translate_escape('Compressed %d out of %d sizes'), $success, $total);
|
|
|
|
|
|
|
|
|
|
|
211 |
$savings = $tiny_metadata->get_savings();
|
212 |
if ($savings['count'] > 0) {
|
213 |
echo '<br/>';
|
224 |
echo '<h2>' . self::translate('Compress JPEG & PNG Images') . '</h2>';
|
225 |
if (empty($_POST['tiny-bulk-compress']) && empty($_REQUEST['ids'])) {
|
226 |
$result = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' ORDER BY ID DESC", ARRAY_A);
|
227 |
+
$count = $result[0]['count'];
|
|
|
228 |
|
229 |
echo '<p>' . self::translate_escape("Use this tool to compress all images in your media library") . '. ';
|
230 |
echo self::translate_escape("Only images that have not been compressed will be compressed") . '.</p>';
|
231 |
+
echo '<p>' . sprintf(self::translate_escape("We have found %d images in your media library"), $count) . '. ';
|
232 |
+
echo self::translate_escape("To begin, just press the button below") . '.</p>';
|
|
|
233 |
|
234 |
echo '<form method="POST" action="?page=tiny-bulk-compress">';
|
235 |
echo '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce('tiny-bulk-compress') . '">';
|
src/class-tiny-settings.php
CHANGED
@@ -20,7 +20,6 @@
|
|
20 |
|
21 |
class Tiny_Settings extends Tiny_WP_Base {
|
22 |
const DUMMY_SIZE = '_tiny_dummy';
|
23 |
-
const MONTHLY_FREE_COMPRESSIONS = 500;
|
24 |
|
25 |
private $sizes;
|
26 |
private $tinify_sizes;
|
@@ -32,25 +31,14 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
32 |
$this->notices = new Tiny_Notices();
|
33 |
}
|
34 |
|
35 |
-
private function init_compressor() {
|
36 |
-
$this->compressor = Tiny_Compress::get_compressor($this->get_api_key(), $this->get_method('after_compress_callback'));
|
37 |
-
}
|
38 |
-
|
39 |
-
public function xmlrpc_init() {
|
40 |
-
try {
|
41 |
-
$this->init_compressor();
|
42 |
-
} catch (Tiny_Exception $e) {
|
43 |
-
}
|
44 |
-
}
|
45 |
-
|
46 |
public function admin_init() {
|
47 |
if (current_user_can('manage_options') && !$this->get_api_key()) {
|
48 |
$link = sprintf('<a href="options-media.php#%s">%s</a>', self::NAME,
|
49 |
self::translate_escape('Please fill in an API key to start compressing images'));
|
50 |
$this->notices->show('setting', $link, 'error', false);
|
51 |
}
|
52 |
-
|
53 |
-
$this->
|
54 |
} catch (Tiny_Exception $e) {
|
55 |
$this->notices->show('compressor_exception', self::translate_escape($e->getMessage()), 'error', false);
|
56 |
}
|
@@ -66,23 +54,13 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
66 |
register_setting('media', $field);
|
67 |
add_settings_field($field, self::translate('File compression'), $this->get_method('render_sizes'), 'media', $section);
|
68 |
|
69 |
-
$field = self::get_prefixed_name('resize_original');
|
70 |
-
register_setting('media', $field);
|
71 |
-
add_settings_field($field, self::translate('Resize original'), $this->get_method('render_resize'), 'media', $section);
|
72 |
-
|
73 |
$field = self::get_prefixed_name('status');
|
74 |
register_setting('media', $field);
|
75 |
add_settings_field($field, self::translate('Connection status'), $this->get_method('render_pending_status'), 'media', $section);
|
76 |
|
77 |
-
add_action('wp_ajax_tiny_image_sizes_notice', $this->get_method('image_sizes_notice'));
|
78 |
add_action('wp_ajax_tiny_compress_status', $this->get_method('connection_status'));
|
79 |
}
|
80 |
|
81 |
-
public function image_sizes_notice() {
|
82 |
-
$this->render_image_sizes_notice($_GET["image_sizes_selected"], isset($_GET["resize_original"]));
|
83 |
-
exit();
|
84 |
-
}
|
85 |
-
|
86 |
public function connection_status() {
|
87 |
$this->render_status();
|
88 |
exit();
|
@@ -156,7 +134,7 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
156 |
return $this->sizes;
|
157 |
}
|
158 |
|
159 |
-
public function
|
160 |
if (is_array($this->tinify_sizes)) {
|
161 |
return $this->tinify_sizes;
|
162 |
}
|
@@ -170,32 +148,6 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
170 |
return $this->tinify_sizes;
|
171 |
}
|
172 |
|
173 |
-
public function get_resize_enabled() {
|
174 |
-
$setting = get_option(self::get_prefixed_name('resize_original'));
|
175 |
-
return isset($setting['enabled']) && $setting['enabled'] === 'on';
|
176 |
-
}
|
177 |
-
|
178 |
-
public function get_resize_options() {
|
179 |
-
$setting = get_option(self::get_prefixed_name('resize_original'));
|
180 |
-
if (!$this->get_resize_enabled()) {
|
181 |
-
return false;
|
182 |
-
}
|
183 |
-
|
184 |
-
$width = intval($setting['width']);
|
185 |
-
$height = intval($setting['height']);
|
186 |
-
$method = $width > 0 && $height > 0 ? 'fit' : 'scale';
|
187 |
-
|
188 |
-
$options['method'] = $method;
|
189 |
-
if ($width > 0) {
|
190 |
-
$options['width'] = $width;
|
191 |
-
}
|
192 |
-
if ($height > 0) {
|
193 |
-
$options['height'] = $height;
|
194 |
-
}
|
195 |
-
|
196 |
-
return sizeof($options) >= 2 ? $options : false;
|
197 |
-
}
|
198 |
-
|
199 |
public function render_section() {
|
200 |
echo '<span id="' . self::NAME . '"></span>';
|
201 |
}
|
@@ -220,23 +172,20 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
220 |
}
|
221 |
|
222 |
public function render_sizes() {
|
223 |
-
echo '<p>' . self::translate_escape('
|
|
|
224 |
<input type="hidden" name="<?php echo self::get_prefixed_name('sizes[' . self::DUMMY_SIZE .']'); ?>" value="on"/></p>
|
225 |
<?php
|
226 |
foreach ($this->get_sizes() as $size => $option) {
|
227 |
$this->render_size_checkbox($size, $option);
|
228 |
}
|
229 |
-
|
230 |
-
echo '<div id="tiny-image-sizes-notice">';
|
231 |
-
$this->render_image_sizes_notice(count(self::get_active_tinify_sizes()), self::get_resize_enabled());
|
232 |
-
echo '</div>';
|
233 |
}
|
234 |
|
235 |
private function render_size_checkbox($size, $option) {
|
236 |
$id = self::get_prefixed_name("sizes_$size");
|
237 |
$field = self::get_prefixed_name("sizes[$size]");
|
238 |
if ($size === Tiny_Metadata::ORIGINAL) {
|
239 |
-
$label = self::translate_escape("original")
|
240 |
} else {
|
241 |
$label = $size . " - ${option['width']}x${option['height']}";
|
242 |
}?>
|
@@ -245,59 +194,6 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
245 |
<?php
|
246 |
}
|
247 |
|
248 |
-
public function render_image_sizes_notice($active_image_sizes_count, $resize_original_enabled) {
|
249 |
-
echo '<br>';
|
250 |
-
echo '<p>' . self::translate_escape('Each selected size counts as a compression') . '. ';
|
251 |
-
|
252 |
-
if ($resize_original_enabled) {
|
253 |
-
$active_image_sizes_count++;
|
254 |
-
}
|
255 |
-
if ($active_image_sizes_count < 1) {
|
256 |
-
echo self::translate_escape('With these settings no images will be compressed') . '.';
|
257 |
-
} else {
|
258 |
-
$free_images_per_month = floor(self::MONTHLY_FREE_COMPRESSIONS / $active_image_sizes_count);
|
259 |
-
echo self::translate_escape('With these settings you can compress');
|
260 |
-
echo ' <strong>';
|
261 |
-
printf(self::translate_escape('at least %s images'), $free_images_per_month);
|
262 |
-
echo '</strong> ';
|
263 |
-
echo self::translate_escape('for free each month') . '.';
|
264 |
-
}
|
265 |
-
echo '</p>';
|
266 |
-
}
|
267 |
-
|
268 |
-
public function render_resize() {
|
269 |
-
echo '<p class="tiny-resize-unavailable" style="display: none">' . self::translate_escape("Enable the compression of the original image size to configure resizing") . '.</p>';
|
270 |
-
|
271 |
-
$id = self::get_prefixed_name("resize_original_enabled");
|
272 |
-
$field = self::get_prefixed_name("resize_original[enabled]");
|
273 |
-
$label = self::translate_escape('Resize and compress orginal images to fit within');
|
274 |
-
|
275 |
-
echo '<p class="tiny-resize-available">';
|
276 |
-
?>
|
277 |
-
<input type="checkbox" id="<?php echo $id ?>" name="<?php echo $field ?>" value="on" <?php if ($this->get_resize_enabled()) { echo ' checked="checked"'; } ?>/>
|
278 |
-
<label for="<?php echo $id; ?>"><?php echo $label; ?>:</label><br>
|
279 |
-
<?php
|
280 |
-
|
281 |
-
echo '</p>';
|
282 |
-
echo '<p class="tiny-resize-available tiny-resize-resolution">';
|
283 |
-
|
284 |
-
printf("%s: ", self::translate_escape('Max Width'));
|
285 |
-
$this->render_resize_input('width');
|
286 |
-
printf("%s: ", self::translate_escape('Max Height'));
|
287 |
-
$this->render_resize_input('height');
|
288 |
-
echo '</p>';
|
289 |
-
|
290 |
-
echo '<p class="tiny-resize-available">' . sprintf(self::translate_escape("Resizing takes %s per image larger than the specified resolution"), '<strong>' . self::translate_escape('1 additional compression') . '</strong>') . '.</p>';
|
291 |
-
}
|
292 |
-
|
293 |
-
public function render_resize_input($name) {
|
294 |
-
$id = sprintf(self::get_prefixed_name('resize_original_%s'), $name);
|
295 |
-
$field = sprintf(self::get_prefixed_name('resize_original[%s]'), $name);
|
296 |
-
$settings = get_option(self::get_prefixed_name('resize_original'));
|
297 |
-
$value = isset($settings[$name]) ? $settings[$name] : "2048";
|
298 |
-
echo '<input type="number" id="'. $id .'" name="' . $field . '" value="' . $value . '" size="5" />';
|
299 |
-
}
|
300 |
-
|
301 |
public function get_compression_count() {
|
302 |
$field = self::get_prefixed_name('status');
|
303 |
return get_option($field);
|
@@ -345,7 +241,7 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
345 |
$compressions = self::get_compression_count();
|
346 |
echo '<p>';
|
347 |
// We currently have no way to check if a user is free or flexible.
|
348 |
-
if ($compressions ==
|
349 |
$link = '<a href="https://tinypng.com/developers" target="_blank">' . self::translate_escape('TinyPNG API account') . '</a>';
|
350 |
printf(self::translate_escape('You have reached your limit of %s compressions this month') . '.', $compressions);
|
351 |
echo '<br>';
|
20 |
|
21 |
class Tiny_Settings extends Tiny_WP_Base {
|
22 |
const DUMMY_SIZE = '_tiny_dummy';
|
|
|
23 |
|
24 |
private $sizes;
|
25 |
private $tinify_sizes;
|
31 |
$this->notices = new Tiny_Notices();
|
32 |
}
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
public function admin_init() {
|
35 |
if (current_user_can('manage_options') && !$this->get_api_key()) {
|
36 |
$link = sprintf('<a href="options-media.php#%s">%s</a>', self::NAME,
|
37 |
self::translate_escape('Please fill in an API key to start compressing images'));
|
38 |
$this->notices->show('setting', $link, 'error', false);
|
39 |
}
|
40 |
+
try {
|
41 |
+
$this->compressor = Tiny_Compress::get_compressor($this->get_api_key(), $this->get_method('after_compress_callback'));
|
42 |
} catch (Tiny_Exception $e) {
|
43 |
$this->notices->show('compressor_exception', self::translate_escape($e->getMessage()), 'error', false);
|
44 |
}
|
54 |
register_setting('media', $field);
|
55 |
add_settings_field($field, self::translate('File compression'), $this->get_method('render_sizes'), 'media', $section);
|
56 |
|
|
|
|
|
|
|
|
|
57 |
$field = self::get_prefixed_name('status');
|
58 |
register_setting('media', $field);
|
59 |
add_settings_field($field, self::translate('Connection status'), $this->get_method('render_pending_status'), 'media', $section);
|
60 |
|
|
|
61 |
add_action('wp_ajax_tiny_compress_status', $this->get_method('connection_status'));
|
62 |
}
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
public function connection_status() {
|
65 |
$this->render_status();
|
66 |
exit();
|
134 |
return $this->sizes;
|
135 |
}
|
136 |
|
137 |
+
public function get_tinify_sizes() {
|
138 |
if (is_array($this->tinify_sizes)) {
|
139 |
return $this->tinify_sizes;
|
140 |
}
|
148 |
return $this->tinify_sizes;
|
149 |
}
|
150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
public function render_section() {
|
152 |
echo '<span id="' . self::NAME . '"></span>';
|
153 |
}
|
172 |
}
|
173 |
|
174 |
public function render_sizes() {
|
175 |
+
echo '<p>' . self::translate_escape('You can choose to compress different image sizes created by WordPress here') . '.<br/>';
|
176 |
+
echo self::translate_escape('Remember each additional image size will affect your TinyPNG monthly usage') . "!";?>
|
177 |
<input type="hidden" name="<?php echo self::get_prefixed_name('sizes[' . self::DUMMY_SIZE .']'); ?>" value="on"/></p>
|
178 |
<?php
|
179 |
foreach ($this->get_sizes() as $size => $option) {
|
180 |
$this->render_size_checkbox($size, $option);
|
181 |
}
|
|
|
|
|
|
|
|
|
182 |
}
|
183 |
|
184 |
private function render_size_checkbox($size, $option) {
|
185 |
$id = self::get_prefixed_name("sizes_$size");
|
186 |
$field = self::get_prefixed_name("sizes[$size]");
|
187 |
if ($size === Tiny_Metadata::ORIGINAL) {
|
188 |
+
$label = self::translate_escape("original");
|
189 |
} else {
|
190 |
$label = $size . " - ${option['width']}x${option['height']}";
|
191 |
}?>
|
194 |
<?php
|
195 |
}
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
public function get_compression_count() {
|
198 |
$field = self::get_prefixed_name('status');
|
199 |
return get_option($field);
|
241 |
$compressions = self::get_compression_count();
|
242 |
echo '<p>';
|
243 |
// We currently have no way to check if a user is free or flexible.
|
244 |
+
if ($compressions == 500) {
|
245 |
$link = '<a href="https://tinypng.com/developers" target="_blank">' . self::translate_escape('TinyPNG API account') . '</a>';
|
246 |
printf(self::translate_escape('You have reached your limit of %s compressions this month') . '.', $compressions);
|
247 |
echo '<br>';
|
src/class-tiny-wp-base.php
CHANGED
@@ -42,10 +42,6 @@ abstract class Tiny_WP_Base {
|
|
42 |
return floatval(self::wp_version()) >= $version;
|
43 |
}
|
44 |
|
45 |
-
protected function is_xmlrpc_request() {
|
46 |
-
return defined('XMLRPC_REQUEST') && XMLRPC_REQUEST;
|
47 |
-
}
|
48 |
-
|
49 |
public static function plugin_version() {
|
50 |
if (is_null(self::$plugin_version)) {
|
51 |
$plugin_data = get_plugin_data(dirname(__FILE__) . '/../tiny-compress-images.php');
|
@@ -72,9 +68,7 @@ abstract class Tiny_WP_Base {
|
|
72 |
|
73 |
public function __construct() {
|
74 |
add_action('init', $this->get_method('init'));
|
75 |
-
if (
|
76 |
-
add_action('init', $this->get_method('xmlrpc_init'));
|
77 |
-
} elseif (is_admin()) {
|
78 |
add_action('admin_init', $this->get_method('admin_init'));
|
79 |
}
|
80 |
}
|
@@ -98,9 +92,6 @@ abstract class Tiny_WP_Base {
|
|
98 |
public function init() {
|
99 |
}
|
100 |
|
101 |
-
public function xmlrpc_init() {
|
102 |
-
}
|
103 |
-
|
104 |
public function admin_init() {
|
105 |
}
|
106 |
}
|
42 |
return floatval(self::wp_version()) >= $version;
|
43 |
}
|
44 |
|
|
|
|
|
|
|
|
|
45 |
public static function plugin_version() {
|
46 |
if (is_null(self::$plugin_version)) {
|
47 |
$plugin_data = get_plugin_data(dirname(__FILE__) . '/../tiny-compress-images.php');
|
68 |
|
69 |
public function __construct() {
|
70 |
add_action('init', $this->get_method('init'));
|
71 |
+
if (is_admin()) {
|
|
|
|
|
72 |
add_action('admin_init', $this->get_method('admin_init'));
|
73 |
}
|
74 |
}
|
92 |
public function init() {
|
93 |
}
|
94 |
|
|
|
|
|
|
|
95 |
public function admin_init() {
|
96 |
}
|
97 |
}
|
src/languages/tiny-compress-images-nl_NL.mo
CHANGED
Binary file
|
src/languages/tiny-compress-images-nl_NL.po
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
msgid "PNG and JPEG compression"
|
2 |
msgstr "PNG- en JPEG-compressie"
|
3 |
|
|
|
|
|
|
|
4 |
msgid "Visit %s to get an API key"
|
5 |
msgstr "Bezoek de %s om een API-sleutel te krijgen"
|
6 |
|
@@ -13,14 +16,17 @@ msgstr "TinyPNG Developer pagina"
|
|
13 |
msgid "TinyPNG API key"
|
14 |
msgstr "TinyPNG API-sleutel"
|
15 |
|
|
|
|
|
|
|
16 |
msgid "File compression"
|
17 |
msgstr "Bestandscompressie"
|
18 |
|
19 |
msgid "original"
|
20 |
msgstr "origineel"
|
21 |
|
22 |
-
msgid "
|
23 |
-
msgstr "
|
24 |
|
25 |
msgid "Remember each additional image size will affect your TinyPNG monthly usage"
|
26 |
msgstr "Elke afmetingen zal apart worden gecomprimeerd en telt mee voor je verbruik"
|
@@ -85,9 +91,12 @@ msgstr "Kon geen outputlocatie vinden"
|
|
85 |
msgid "Could not download output"
|
86 |
msgstr "Kon output niet downloaden"
|
87 |
|
88 |
-
msgid "File does not
|
89 |
msgstr "Bestand bestaat niet"
|
90 |
|
|
|
|
|
|
|
91 |
msgid "Could not compress, enable cURL for detailed error"
|
92 |
msgstr "Kon niet comprimeren, schakel cURL in voor een preciezere foutmelding"
|
93 |
|
@@ -133,24 +142,6 @@ msgstr "Als je meer afbeeldingen wilt comprimeren kun je je %s aanpassen"
|
|
133 |
msgid "Upgrade your %s if you like to compress more images"
|
134 |
msgstr "Upgrade je %s als je meer afbeeldingen wilt comprimeren"
|
135 |
|
136 |
-
msgid "Each selected size counts as a compression"
|
137 |
-
msgstr "Elke geselecteerde afmeting telt als een compressie"
|
138 |
-
|
139 |
-
msgid "With these settings you can compress"
|
140 |
-
msgstr "Met deze instellingen kun je elke maand"
|
141 |
-
|
142 |
-
msgid "at least %s images"
|
143 |
-
msgstr "minimaal %s afbeeldingen"
|
144 |
-
|
145 |
-
msgid "for free each month"
|
146 |
-
msgstr "gratis comprimeren"
|
147 |
-
|
148 |
-
msgid "With these settings no images will be compressed"
|
149 |
-
msgstr "Met deze instellingen worden geen afbeeldingen gecomprimeerd"
|
150 |
-
|
151 |
-
msgid "overwritten by compressed image"
|
152 |
-
msgstr "overschreven door gecomprimeerde afbeelding"
|
153 |
-
|
154 |
msgid "Please fill in an API key to start compressing images"
|
155 |
msgstr "Vul een API-sleutel in om te starten met comprimeren"
|
156 |
|
@@ -187,11 +178,8 @@ msgstr "Deze tool comprimeert alle afbeeldingen in je media-bibliotheek"
|
|
187 |
msgid "Only images that have not been compressed will be compressed"
|
188 |
msgstr "Dit geldt alleen voor de afbeeldingen die nog niet zijn gecomprimeerd"
|
189 |
|
190 |
-
msgid "We have found %d images in your media library
|
191 |
-
msgstr "We hebben %d afbeeldingen in de media-bibliotheek gevonden
|
192 |
-
|
193 |
-
msgid "This results in %d compressions at most"
|
194 |
-
msgstr "Dit resulteert in een maximaal verbruik van %d compressies"
|
195 |
|
196 |
msgid "To begin, just press the button below"
|
197 |
msgstr "Druk op de knop om te starten"
|
@@ -207,30 +195,3 @@ msgstr "Navigeer niet van deze pagina want daardoor stopt het proces"
|
|
207 |
|
208 |
msgid "You will be notified via this page when the processing is done"
|
209 |
msgstr "Je wordt genotificeerd op deze pagina bij voltooing"
|
210 |
-
|
211 |
-
msgid "Settings"
|
212 |
-
msgstr "Instellingen"
|
213 |
-
|
214 |
-
msgid "Resize original"
|
215 |
-
msgstr "Orgineel verkleinen"
|
216 |
-
|
217 |
-
msgid "Enable the compression of the original image size to configure resizing"
|
218 |
-
msgstr "Schakel de compressie van het originele formaat in om het origineel te verkleinen"
|
219 |
-
|
220 |
-
msgid "Resize and compress orginal images to fit within"
|
221 |
-
msgstr "Verklein en comprimeer het origineel in"
|
222 |
-
|
223 |
-
msgid "Resizing takes %s per image larger than the specified resolution"
|
224 |
-
msgstr "Verkleinen gebruikt %s per afbeelding die groter is dan de opgegeven resolutie"
|
225 |
-
|
226 |
-
msgid "1 additional compression"
|
227 |
-
msgstr "1 extra compressie"
|
228 |
-
|
229 |
-
msgid "Resized original to %dx%d"
|
230 |
-
msgstr "Origineel verkleind tot %dx%d"
|
231 |
-
|
232 |
-
msgid "Max Width"
|
233 |
-
msgstr "Maximale breedte"
|
234 |
-
|
235 |
-
msgid "Max Height"
|
236 |
-
msgstr "Maximale hoogte"
|
1 |
msgid "PNG and JPEG compression"
|
2 |
msgstr "PNG- en JPEG-compressie"
|
3 |
|
4 |
+
msgid "Multisite PNG and JPEG compression"
|
5 |
+
msgstr "Multisite PNG- en JPEG-compressie"
|
6 |
+
|
7 |
msgid "Visit %s to get an API key"
|
8 |
msgstr "Bezoek de %s om een API-sleutel te krijgen"
|
9 |
|
16 |
msgid "TinyPNG API key"
|
17 |
msgstr "TinyPNG API-sleutel"
|
18 |
|
19 |
+
msgid "Multisite API key"
|
20 |
+
msgstr "Multisite API-sleutel"
|
21 |
+
|
22 |
msgid "File compression"
|
23 |
msgstr "Bestandscompressie"
|
24 |
|
25 |
msgid "original"
|
26 |
msgstr "origineel"
|
27 |
|
28 |
+
msgid "You can choose to compress different image sizes created by WordPress here"
|
29 |
+
msgstr "Je kunt hier kiezen welke afmetingen je wilt comprimeren van de afbeeldingen"
|
30 |
|
31 |
msgid "Remember each additional image size will affect your TinyPNG monthly usage"
|
32 |
msgstr "Elke afmetingen zal apart worden gecomprimeerd en telt mee voor je verbruik"
|
91 |
msgid "Could not download output"
|
92 |
msgstr "Kon output niet downloaden"
|
93 |
|
94 |
+
msgid "File does not exists"
|
95 |
msgstr "Bestand bestaat niet"
|
96 |
|
97 |
+
msgid "Could not decode JSON"
|
98 |
+
msgstr "Kon JSON niet decoderen"
|
99 |
+
|
100 |
msgid "Could not compress, enable cURL for detailed error"
|
101 |
msgstr "Kon niet comprimeren, schakel cURL in voor een preciezere foutmelding"
|
102 |
|
142 |
msgid "Upgrade your %s if you like to compress more images"
|
143 |
msgstr "Upgrade je %s als je meer afbeeldingen wilt comprimeren"
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
msgid "Please fill in an API key to start compressing images"
|
146 |
msgstr "Vul een API-sleutel in om te starten met comprimeren"
|
147 |
|
178 |
msgid "Only images that have not been compressed will be compressed"
|
179 |
msgstr "Dit geldt alleen voor de afbeeldingen die nog niet zijn gecomprimeerd"
|
180 |
|
181 |
+
msgid "We have found %d images in your media library"
|
182 |
+
msgstr "We hebben %d afbeeldingen in de media-bibliotheek gevonden"
|
|
|
|
|
|
|
183 |
|
184 |
msgid "To begin, just press the button below"
|
185 |
msgstr "Druk op de knop om te starten"
|
195 |
|
196 |
msgid "You will be notified via this page when the processing is done"
|
197 |
msgstr "Je wordt genotificeerd op deze pagina bij voltooing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/languages/tiny-compress-images-ru_RU.mo
CHANGED
Binary file
|
src/languages/tiny-compress-images-ru_RU.po
CHANGED
@@ -16,6 +16,9 @@ msgstr ""
|
|
16 |
msgid "PNG and JPEG compression"
|
17 |
msgstr "Сжатие PNG и JPEG"
|
18 |
|
|
|
|
|
|
|
19 |
msgid "Visit %s to get an API key"
|
20 |
msgstr "Посетите %s, чтобы получить API ключ"
|
21 |
|
@@ -28,6 +31,9 @@ msgstr "раздел TinyPNG для разработчиков"
|
|
28 |
msgid "TinyPNG API key"
|
29 |
msgstr "TinyPNG API ключ"
|
30 |
|
|
|
|
|
|
|
31 |
msgid "File compression"
|
32 |
msgstr "Сжатие файлов"
|
33 |
|
@@ -97,9 +103,12 @@ msgstr "Не могу найти url результата"
|
|
97 |
msgid "Could not download output"
|
98 |
msgstr "Не могу загрузить результат"
|
99 |
|
100 |
-
msgid "File does not
|
101 |
msgstr "Файл не существует или не найден плагином"
|
102 |
|
|
|
|
|
|
|
103 |
msgid "Could not compress, enable cURL for detailed error"
|
104 |
msgstr "Не могу сжать. Подключите cURL для деталей"
|
105 |
|
16 |
msgid "PNG and JPEG compression"
|
17 |
msgstr "Сжатие PNG и JPEG"
|
18 |
|
19 |
+
msgid "Multisite PNG and JPEG compression"
|
20 |
+
msgstr "PNG и JPEG сжатие для Multisite"
|
21 |
+
|
22 |
msgid "Visit %s to get an API key"
|
23 |
msgstr "Посетите %s, чтобы получить API ключ"
|
24 |
|
31 |
msgid "TinyPNG API key"
|
32 |
msgstr "TinyPNG API ключ"
|
33 |
|
34 |
+
msgid "Multisite API key"
|
35 |
+
msgstr "Multisite API ключ"
|
36 |
+
|
37 |
msgid "File compression"
|
38 |
msgstr "Сжатие файлов"
|
39 |
|
103 |
msgid "Could not download output"
|
104 |
msgstr "Не могу загрузить результат"
|
105 |
|
106 |
+
msgid "File does not exists"
|
107 |
msgstr "Файл не существует или не найден плагином"
|
108 |
|
109 |
+
msgid "Could not decode JSON"
|
110 |
+
msgstr "Не могу раскодировать JSON"
|
111 |
+
|
112 |
msgid "Could not compress, enable cURL for detailed error"
|
113 |
msgstr "Не могу сжать. Подключите cURL для деталей"
|
114 |
|
src/languages/tiny-compress-images-zh_TW.mo
DELETED
Binary file
|
src/languages/tiny-compress-images-zh_TW.po
DELETED
@@ -1,202 +0,0 @@
|
|
1 |
-
msgid ""
|
2 |
-
msgstr ""
|
3 |
-
"Project-Id-Version: \n"
|
4 |
-
"POT-Creation-Date: \n"
|
5 |
-
"PO-Revision-Date: \n"
|
6 |
-
"Language-Team: \n"
|
7 |
-
"MIME-Version: 1.0\n"
|
8 |
-
"Content-Type: text/plain; charset=UTF-8\n"
|
9 |
-
"Content-Transfer-Encoding: 8bit\n"
|
10 |
-
"X-Generator: Poedit 1.8.4\n"
|
11 |
-
"Last-Translator: Pseric <pserics@gmail.com>\n"
|
12 |
-
"Plural-Forms: nplurals=1; plural=0;\n"
|
13 |
-
"Language: zh_TW\n"
|
14 |
-
|
15 |
-
msgid "PNG and JPEG compression"
|
16 |
-
msgstr "PNG 和 JPEG 壓縮"
|
17 |
-
|
18 |
-
msgid "Visit %s to get an API key"
|
19 |
-
msgstr "訪問 %s 取得一個 API 金鑰"
|
20 |
-
|
21 |
-
msgid "Visit %s to view your usage or upgrade your account"
|
22 |
-
msgstr "訪問 %s 檢視你的使用量或升級你的帳號"
|
23 |
-
|
24 |
-
msgid "TinyPNG Developer section"
|
25 |
-
msgstr "TinyPNG 開發者功能"
|
26 |
-
|
27 |
-
msgid "TinyPNG API key"
|
28 |
-
msgstr "TinyPNG API 金鑰"
|
29 |
-
|
30 |
-
msgid "File compression"
|
31 |
-
msgstr "檔案壓縮"
|
32 |
-
|
33 |
-
msgid "original"
|
34 |
-
msgstr "原始大小"
|
35 |
-
|
36 |
-
msgid "You can choose to compress different image sizes created by WordPress here"
|
37 |
-
msgstr "你可以在這裡選擇要壓縮的圖片大小,由 WordPress 建立"
|
38 |
-
|
39 |
-
msgid "Remember each additional image size will affect your TinyPNG monthly usage"
|
40 |
-
msgstr "請記住,每個額外圖片尺寸都會影響你的 TinyPNG 每月使用量"
|
41 |
-
|
42 |
-
msgid "Compression"
|
43 |
-
msgstr "壓縮"
|
44 |
-
|
45 |
-
msgid "Compress"
|
46 |
-
msgstr "壓縮"
|
47 |
-
|
48 |
-
msgid "Compress Images"
|
49 |
-
msgstr "壓縮圖片"
|
50 |
-
|
51 |
-
msgid "Compressed %d out of %d sizes"
|
52 |
-
msgstr "已壓縮 %d/%d 個尺寸"
|
53 |
-
|
54 |
-
msgid "Compressing %d sizes..."
|
55 |
-
msgstr "壓縮 %d 個尺寸..."
|
56 |
-
|
57 |
-
msgid "Total size"
|
58 |
-
msgstr "總共大小"
|
59 |
-
|
60 |
-
msgid "Compressed size"
|
61 |
-
msgstr "已壓縮尺寸"
|
62 |
-
|
63 |
-
msgid "Latest error"
|
64 |
-
msgstr "最近錯誤"
|
65 |
-
|
66 |
-
msgid "Error"
|
67 |
-
msgstr "錯誤"
|
68 |
-
|
69 |
-
msgid "Internal error"
|
70 |
-
msgstr "內部錯誤"
|
71 |
-
|
72 |
-
msgid "Credentials are invalid"
|
73 |
-
msgstr "憑證無效"
|
74 |
-
|
75 |
-
msgid "Your monthly limit has been exceeded"
|
76 |
-
msgstr "你的每月限額已經超過"
|
77 |
-
|
78 |
-
msgid "File is empty"
|
79 |
-
msgstr "檔案是空的"
|
80 |
-
|
81 |
-
msgid "Does not appear to be a PNG or JPEG file"
|
82 |
-
msgstr "似乎不是一個 PNG 或 JPEG 檔案"
|
83 |
-
|
84 |
-
msgid "CMYK color space is not supported"
|
85 |
-
msgstr "不支援 CMYK 色彩空間"
|
86 |
-
|
87 |
-
msgid "Image appears corrupt"
|
88 |
-
msgstr "圖片似乎已經損壞"
|
89 |
-
|
90 |
-
msgid "Compression failed"
|
91 |
-
msgstr "壓縮失敗"
|
92 |
-
|
93 |
-
msgid "No HTTP client is available (cURL or fopen)"
|
94 |
-
msgstr "沒有 HTTP 客戶端可用(cURL 或 fopen)"
|
95 |
-
|
96 |
-
msgid "Could not find output url"
|
97 |
-
msgstr "找不到輸出網址"
|
98 |
-
|
99 |
-
msgid "Could not download output"
|
100 |
-
msgstr "無法下載輸出"
|
101 |
-
|
102 |
-
msgid "File does not exist"
|
103 |
-
msgstr "檔案不存在"
|
104 |
-
|
105 |
-
msgid "Could not compress, enable cURL for detailed error"
|
106 |
-
msgstr "無法壓縮,啟用 cURL 取得詳細錯誤資訊"
|
107 |
-
|
108 |
-
msgid "You don't have permission to work with uploaded files"
|
109 |
-
msgstr "你沒有權限來處理上傳的檔案"
|
110 |
-
|
111 |
-
msgid "Not a valid media file"
|
112 |
-
msgstr "不是一個有效的媒體檔案"
|
113 |
-
|
114 |
-
msgid "Could not find metadata of media file"
|
115 |
-
msgstr "找不到媒體檔案的 metadata"
|
116 |
-
|
117 |
-
msgid "The API key has been configured in %s"
|
118 |
-
msgstr "這個 API 金鑰已經設定在 %s"
|
119 |
-
|
120 |
-
msgid "Connection status"
|
121 |
-
msgstr "連線狀態"
|
122 |
-
|
123 |
-
msgid "Dismiss"
|
124 |
-
msgstr "拒絕"
|
125 |
-
|
126 |
-
msgid "TinyPNG API account"
|
127 |
-
msgstr "TinyPNG API 帳號"
|
128 |
-
|
129 |
-
msgid "API connection successful"
|
130 |
-
msgstr "API 連線成功"
|
131 |
-
|
132 |
-
msgid "API connection unsuccessful"
|
133 |
-
msgstr "API 連線不成功"
|
134 |
-
|
135 |
-
msgid "API status could not be checked, enable cURL for more information"
|
136 |
-
msgstr "無法檢查 API 狀態,啟用 cURL 取得更多資訊"
|
137 |
-
|
138 |
-
msgid "You have made %s compressions this month"
|
139 |
-
msgstr "本月你已經壓縮 %s 張圖片"
|
140 |
-
|
141 |
-
msgid "You have reached your limit of %s compressions this month"
|
142 |
-
msgstr "本月你已經到達你的壓縮限制 %s 張圖片"
|
143 |
-
|
144 |
-
msgid "If you need to compress more images you can change your %s"
|
145 |
-
msgstr "如果你需要壓縮更多圖片,你可以變更你的 %s"
|
146 |
-
|
147 |
-
msgid "Upgrade your %s if you like to compress more images"
|
148 |
-
msgstr "如果你想壓縮更多圖片,升級你的 %s"
|
149 |
-
|
150 |
-
msgid "Please fill in an API key to start compressing images"
|
151 |
-
msgstr "請填入一個 API 金鑰來開始壓縮圖片"
|
152 |
-
|
153 |
-
msgid "Compress All Images"
|
154 |
-
msgstr "壓縮所有圖片"
|
155 |
-
|
156 |
-
msgid "Compress JPEG & PNG Images"
|
157 |
-
msgstr "壓縮 JPEG & PNG 圖片"
|
158 |
-
|
159 |
-
msgid "All images are processed"
|
160 |
-
msgstr "所有圖片皆處理完成"
|
161 |
-
|
162 |
-
msgid "Compressions this month"
|
163 |
-
msgstr "本月壓縮"
|
164 |
-
|
165 |
-
msgid "Processing"
|
166 |
-
msgstr "處理中"
|
167 |
-
|
168 |
-
msgid "Waiting"
|
169 |
-
msgstr "等待中"
|
170 |
-
|
171 |
-
msgid "Compressing"
|
172 |
-
msgstr "壓縮中"
|
173 |
-
|
174 |
-
msgid "compressions"
|
175 |
-
msgstr "壓縮"
|
176 |
-
|
177 |
-
msgid "out of"
|
178 |
-
msgstr "以外"
|
179 |
-
|
180 |
-
msgid "Use this tool to compress all images in your media library"
|
181 |
-
msgstr "使用這個工具來壓縮你媒體庫的所有圖片"
|
182 |
-
|
183 |
-
msgid "Only images that have not been compressed will be compressed"
|
184 |
-
msgstr "只有沒被壓縮過的圖片才會壓縮"
|
185 |
-
|
186 |
-
msgid "We have found %d images in your media library"
|
187 |
-
msgstr "我們在你的媒體庫找到 %d 張圖片"
|
188 |
-
|
189 |
-
msgid "To begin, just press the button below"
|
190 |
-
msgstr "如要開始,只要點選下方案扭"
|
191 |
-
|
192 |
-
msgid "Please be patient while the images are being compressed"
|
193 |
-
msgstr "相片壓縮時請耐心等待"
|
194 |
-
|
195 |
-
msgid "This can take a while if you have many images"
|
196 |
-
msgstr "如果你有許多圖片,這可能需要一段時間"
|
197 |
-
|
198 |
-
msgid "Do not navigate away from this page because it will stop the process"
|
199 |
-
msgstr "請不要離開此頁面,因為它會停止壓縮程序"
|
200 |
-
|
201 |
-
msgid "You will be notified via this page when the processing is done"
|
202 |
-
msgstr "當處理完成後,你將透過此頁面取得通知"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/scripts/admin.js
CHANGED
@@ -155,33 +155,6 @@
|
|
155 |
|
156 |
if (adminpage === "options-media-php") {
|
157 |
jQuery('#tiny-compress-status').load(ajaxurl + '?action=tiny_compress_status')
|
158 |
-
|
159 |
-
jQuery('input[name*="tinypng_sizes"], input#tinypng_resize_original_enabled').on("click", function() {
|
160 |
-
// Unfortunately, we need some additional information to display the correct notice.
|
161 |
-
totalSelectedSizes = jQuery('input[name*="tinypng_sizes"]:checked').length
|
162 |
-
var image_count_url = ajaxurl + '?action=tiny_image_sizes_notice&image_sizes_selected=' + totalSelectedSizes
|
163 |
-
if (jQuery('input#tinypng_resize_original_enabled').prop('checked') && jQuery('input#tinypng_sizes_0').prop('checked')) {
|
164 |
-
image_count_url += '&resize_original=true'
|
165 |
-
}
|
166 |
-
jQuery('#tiny-image-sizes-notice').load(image_count_url)
|
167 |
-
})
|
168 |
-
|
169 |
-
function update_resize_settings() {
|
170 |
-
if (jQuery('#tinypng_sizes_0').prop('checked')) {
|
171 |
-
jQuery('.tiny-resize-available').show()
|
172 |
-
jQuery('.tiny-resize-unavailable').hide()
|
173 |
-
} else {
|
174 |
-
jQuery('.tiny-resize-available').hide()
|
175 |
-
jQuery('.tiny-resize-unavailable').show()
|
176 |
-
}
|
177 |
-
|
178 |
-
var elements = jQuery('#tinypng_resize_original_width, #tinypng_resize_original_height')
|
179 |
-
for (var i = 0; i < elements.length; i++) {
|
180 |
-
elements[i].disabled = !jQuery('#tinypng_resize_original_enabled').prop('checked')
|
181 |
-
}
|
182 |
-
}
|
183 |
-
update_resize_settings()
|
184 |
-
jQuery('#tinypng_sizes_0, #tinypng_resize_original_enabled').click(update_resize_settings)
|
185 |
}
|
186 |
|
187 |
jQuery('.tiny-notice a.tiny-dismiss').click(dismiss_notice)
|
@@ -190,4 +163,4 @@
|
|
190 |
})
|
191 |
|
192 |
window.tinyBulkCompress = bulk_compress
|
193 |
-
}).call()
|
155 |
|
156 |
if (adminpage === "options-media-php") {
|
157 |
jQuery('#tiny-compress-status').load(ajaxurl + '?action=tiny_compress_status')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
|
160 |
jQuery('.tiny-notice a.tiny-dismiss').click(dismiss_notice)
|
163 |
})
|
164 |
|
165 |
window.tinyBulkCompress = bulk_compress
|
166 |
+
}).call()
|
src/styles/admin.css
CHANGED
@@ -51,15 +51,3 @@
|
|
51 |
box-shadow: 0px 1px 0px #DFDFDF;
|
52 |
padding: 5px;
|
53 |
}
|
54 |
-
|
55 |
-
p.tiny-resize-resolution {
|
56 |
-
margin-left: 24px;
|
57 |
-
}
|
58 |
-
|
59 |
-
p.tiny-resize-resolution input {
|
60 |
-
margin-right: 6px;
|
61 |
-
}
|
62 |
-
|
63 |
-
input[type=number][name*="tinypng_resize_original"] {
|
64 |
-
width: 65px;
|
65 |
-
}
|
51 |
box-shadow: 0px 1px 0px #DFDFDF;
|
52 |
padding: 5px;
|
53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test/fixtures/input-large.jpg
DELETED
Binary file
|
test/helpers/setup.php
CHANGED
@@ -103,12 +103,8 @@ function setup_wordpress_site($driver) {
|
|
103 |
}
|
104 |
$driver->findElement(WebDriverBy::name('weblog_title'))->sendKeys('Wordpress test');
|
105 |
$driver->findElement(WebDriverBy::name('user_name'))->clear()->sendKeys('admin');
|
106 |
-
|
107 |
-
|
108 |
-
} else {
|
109 |
-
$driver->findElement(WebDriverBy::name('admin_password'))->sendKeys('admin');
|
110 |
-
$driver->findElement(WebDriverBy::name('admin_password2'))->sendKeys('admin');
|
111 |
-
}
|
112 |
$driver->findElement(WebDriverBy::name('admin_email'))->sendKeys('developers@voormedia.com');
|
113 |
$driver->findElement(WebDriverBy::tagName('form'))->submit();
|
114 |
$h1s = $driver->findElements(WebDriverBy::tagName('h1'));
|
@@ -122,16 +118,13 @@ function setup_wordpress_site($driver) {
|
|
122 |
}
|
123 |
|
124 |
function login($driver) {
|
125 |
-
print "Logging in to Wordpress... ";
|
126 |
$driver->get(wordpress('/wp-login.php'));
|
127 |
$driver->findElement(WebDriverBy::tagName('body'))->click();
|
128 |
$driver->findElement(WebDriverBy::name('log'))->clear()->click()->sendKeys('admin');
|
129 |
$driver->findElement(WebDriverBy::name('pwd'))->clear()->click()->sendKeys('admin');
|
130 |
$driver->findElement(WebDriverBy::tagName('form'))->submit();
|
131 |
-
|
132 |
-
|
133 |
-
if ($dashboardHeading->getText() == 'Dashboard') {
|
134 |
-
print "success!\n";
|
135 |
} else {
|
136 |
var_dump($driver->getPageSource());
|
137 |
throw new UnexpectedValueException('Login failed.');
|
@@ -164,6 +157,7 @@ function reset_webservice() {
|
|
164 |
curl_setopt_array($request, array(
|
165 |
CURLOPT_URL => 'http://' . getenv('HOST_IP') .':8080/reset',
|
166 |
));
|
|
|
167 |
$response = curl_exec($request);
|
168 |
curl_close($request);
|
169 |
}
|
103 |
}
|
104 |
$driver->findElement(WebDriverBy::name('weblog_title'))->sendKeys('Wordpress test');
|
105 |
$driver->findElement(WebDriverBy::name('user_name'))->clear()->sendKeys('admin');
|
106 |
+
$driver->findElement(WebDriverBy::name('admin_password'))->sendKeys('admin');
|
107 |
+
$driver->findElement(WebDriverBy::name('admin_password2'))->sendKeys('admin');
|
|
|
|
|
|
|
|
|
108 |
$driver->findElement(WebDriverBy::name('admin_email'))->sendKeys('developers@voormedia.com');
|
109 |
$driver->findElement(WebDriverBy::tagName('form'))->submit();
|
110 |
$h1s = $driver->findElements(WebDriverBy::tagName('h1'));
|
118 |
}
|
119 |
|
120 |
function login($driver) {
|
|
|
121 |
$driver->get(wordpress('/wp-login.php'));
|
122 |
$driver->findElement(WebDriverBy::tagName('body'))->click();
|
123 |
$driver->findElement(WebDriverBy::name('log'))->clear()->click()->sendKeys('admin');
|
124 |
$driver->findElement(WebDriverBy::name('pwd'))->clear()->click()->sendKeys('admin');
|
125 |
$driver->findElement(WebDriverBy::tagName('form'))->submit();
|
126 |
+
if ($driver->findElement(WebDriverBy::tagName('h2'))->getText() == 'Dashboard') {
|
127 |
+
print "Successfully logged into WordPress.\n";
|
|
|
|
|
128 |
} else {
|
129 |
var_dump($driver->getPageSource());
|
130 |
throw new UnexpectedValueException('Login failed.');
|
157 |
curl_setopt_array($request, array(
|
158 |
CURLOPT_URL => 'http://' . getenv('HOST_IP') .':8080/reset',
|
159 |
));
|
160 |
+
|
161 |
$response = curl_exec($request);
|
162 |
curl_close($request);
|
163 |
}
|
test/helpers/wordpress.php
CHANGED
@@ -176,12 +176,7 @@ class WordPressStubs {
|
|
176 |
}
|
177 |
|
178 |
public function getTestMetadata($path='14/01', $name='test') {
|
179 |
-
$metadata = array(
|
180 |
-
'file' => "$path/$name.png",
|
181 |
-
'width' => 4000,
|
182 |
-
'height' => 3000,
|
183 |
-
'sizes' => array()
|
184 |
-
);
|
185 |
|
186 |
$regex = '#^' . preg_quote($name) .'-([^.]+)[.](png|jpe?g)$#';
|
187 |
$dir = $this->vfs->getChild(self::UPLOAD_DIR . "/$path");
|
176 |
}
|
177 |
|
178 |
public function getTestMetadata($path='14/01', $name='test') {
|
179 |
+
$metadata = array('file' => "$path/$name.png", 'sizes' => array());
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
$regex = '#^' . preg_quote($name) .'-([^.]+)[.](png|jpe?g)$#';
|
182 |
$dir = $this->vfs->getChild(self::UPLOAD_DIR . "/$path");
|
test/integration/BulkCompressIntegrationTest.php
CHANGED
@@ -35,7 +35,7 @@ class BulkCompressIntegrationTest extends IntegrationTestCase {
|
|
35 |
$this->enable_compression_sizes(array('thumbnail', 'medium', 'large'));
|
36 |
}
|
37 |
|
38 |
-
public function
|
39 |
$this->prepare(1, 2);
|
40 |
|
41 |
self::$driver->get(wordpress('/wp-admin/upload.php?orderby=title&order=asc'));
|
35 |
$this->enable_compression_sizes(array('thumbnail', 'medium', 'large'));
|
36 |
}
|
37 |
|
38 |
+
public function testBulkCompressShouldFromMediaShouldOnlyCompressSelected() {
|
39 |
$this->prepare(1, 2);
|
40 |
|
41 |
self::$driver->get(wordpress('/wp-admin/upload.php?orderby=title&order=asc'));
|
test/integration/CompressIntegrationTest.php
CHANGED
@@ -67,64 +67,4 @@ class CompressIntegrationTest extends IntegrationTestCase {
|
|
67 |
self::$driver->get(wordpress('/wp-admin/options-media.php'));
|
68 |
$this->assertEquals(0, count(self::$driver->findElements(WebDriverBy::cssSelector('div.error p'))));
|
69 |
}
|
70 |
-
|
71 |
-
public function testIncorrectJsonButton() {
|
72 |
-
$this->enable_compression_sizes(array());
|
73 |
-
$this->upload_image(dirname(__FILE__) . '/../fixtures/input-example.png');
|
74 |
-
$this->enable_compression_sizes(array('medium', 'large'));
|
75 |
-
|
76 |
-
$this->set_api_key('JSON1234');
|
77 |
-
self::$driver->get(wordpress('/wp-admin/upload.php'));
|
78 |
-
|
79 |
-
self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images button'))->click();
|
80 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
81 |
-
WebDriverBy::cssSelector('td.tiny-compress-images'), 'JSON: Syntax error [4]'));
|
82 |
-
}
|
83 |
-
|
84 |
-
public function testResizeFit() {
|
85 |
-
$this->set_api_key('JPG123');
|
86 |
-
$this->enable_resize(300, 200);
|
87 |
-
$this->upload_image(dirname(__FILE__) . '/../fixtures/input-large.jpg');
|
88 |
-
$this->assertContains('Resized original to 300x200',
|
89 |
-
self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images'))->getText());
|
90 |
-
$this->view_edit_image();
|
91 |
-
$this->assertContains('Dimensions: 300 × 200',
|
92 |
-
self::$driver->findElement(WebDriverBy::cssSelector('div.misc-pub-dimensions'))->getText());
|
93 |
-
}
|
94 |
-
|
95 |
-
public function testResizeScale() {
|
96 |
-
$this->set_api_key('JPG123');
|
97 |
-
$this->enable_resize(0, 200);
|
98 |
-
$this->upload_image(dirname(__FILE__) . '/../fixtures/input-large.jpg');
|
99 |
-
$this->assertContains('Resized original to 300x200',
|
100 |
-
self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images'))->getText());
|
101 |
-
$this->view_edit_image();
|
102 |
-
$this->assertContains('Dimensions: 300 × 200',
|
103 |
-
self::$driver->findElement(WebDriverBy::cssSelector('div.misc-pub-dimensions'))->getText());
|
104 |
-
}
|
105 |
-
|
106 |
-
public function testResizeNotNeeded()
|
107 |
-
{
|
108 |
-
$this->set_api_key('JPG123');
|
109 |
-
$this->enable_resize(30000, 20000);
|
110 |
-
$this->upload_image(dirname(__FILE__) . '/../fixtures/input-large.jpg');
|
111 |
-
$this->assertNotContains('Resized original',
|
112 |
-
self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images'))->getText());
|
113 |
-
$this->view_edit_image();
|
114 |
-
$this->assertContains('Dimensions: 1080 × 330',
|
115 |
-
self::$driver->findElement(WebDriverBy::cssSelector('div.misc-pub-dimensions'))->getText());
|
116 |
-
}
|
117 |
-
|
118 |
-
public function testResizeDisabled()
|
119 |
-
{
|
120 |
-
$this->set_api_key('JPG123');
|
121 |
-
$this->enable_resize(300, 200);
|
122 |
-
$this->disable_resize();
|
123 |
-
$this->upload_image(dirname(__FILE__) . '/../fixtures/input-large.jpg');
|
124 |
-
$this->assertNotContains('Resized original',
|
125 |
-
self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images'))->getText());
|
126 |
-
$this->view_edit_image();
|
127 |
-
$this->assertContains('Dimensions: 1080 × 330',
|
128 |
-
self::$driver->findElement(WebDriverBy::cssSelector('div.misc-pub-dimensions'))->getText());
|
129 |
-
}
|
130 |
}
|
67 |
self::$driver->get(wordpress('/wp-admin/options-media.php'));
|
68 |
$this->assertEquals(0, count(self::$driver->findElements(WebDriverBy::cssSelector('div.error p'))));
|
69 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
}
|
test/integration/IntegrationTestCase.php
CHANGED
@@ -62,43 +62,4 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase {
|
|
62 |
}
|
63 |
self::$driver->findElement(WebDriverBy::tagName('form'))->submit();
|
64 |
}
|
65 |
-
|
66 |
-
protected function enable_resize($width, $height) {
|
67 |
-
$url = wordpress('/wp-admin/options-media.php');
|
68 |
-
if (self::$driver->getCurrentUrl() != $url) {
|
69 |
-
self::$driver->get($url);
|
70 |
-
}
|
71 |
-
$element = self::$driver->findElement(WebDriverBy::id('tinypng_resize_original_enabled'));
|
72 |
-
if (!$element->getAttribute('checked')) {
|
73 |
-
$element->click();
|
74 |
-
}
|
75 |
-
self::$driver->findElement(WebDriverBy::id('tinypng_resize_original_width'))->clear()->sendKeys($width);
|
76 |
-
self::$driver->findElement(WebDriverBy::id('tinypng_resize_original_height'))->clear()->sendKeys($height);
|
77 |
-
self::$driver->findElement(WebDriverBy::tagName('form'))->submit();
|
78 |
-
}
|
79 |
-
|
80 |
-
protected function disable_resize() {
|
81 |
-
$url = wordpress('/wp-admin/options-media.php');
|
82 |
-
if (self::$driver->getCurrentUrl() != $url) {
|
83 |
-
self::$driver->get($url);
|
84 |
-
}
|
85 |
-
$element = self::$driver->findElement(WebDriverBy::id('tinypng_resize_original_enabled'));
|
86 |
-
if ($element->getAttribute('checked')) {
|
87 |
-
$element->click();
|
88 |
-
}
|
89 |
-
self::$driver->findElement(WebDriverBy::tagName('form'))->submit();
|
90 |
-
}
|
91 |
-
|
92 |
-
protected function view_edit_image($image_title = 'input-large') {
|
93 |
-
$url = wordpress('/wp-admin/upload.php');
|
94 |
-
if (self::$driver->getCurrentUrl() != $url) {
|
95 |
-
self::$driver->get($url);
|
96 |
-
}
|
97 |
-
if (wordpress_version() >= 43) {
|
98 |
-
$selector = "//span[text()='" . $image_title . "']";
|
99 |
-
} else {
|
100 |
-
$selector = "//a[contains(text(),'" . $image_title . "')]";
|
101 |
-
}
|
102 |
-
self::$driver->findElement(WebDriverBy::xpath($selector))->click();
|
103 |
-
}
|
104 |
}
|
62 |
}
|
63 |
self::$driver->findElement(WebDriverBy::tagName('form'))->submit();
|
64 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
}
|
test/integration/PluginIntegrationTest.php
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once(dirname(__FILE__) . "/IntegrationTestCase.php");
|
4 |
-
|
5 |
-
class PluginIntegrationTest extends IntegrationTestCase {
|
6 |
-
|
7 |
-
public function setUp() {
|
8 |
-
parent::setUp();
|
9 |
-
self::$driver->get(wordpress('/wp-admin/plugins.php'));
|
10 |
-
}
|
11 |
-
|
12 |
-
public function tearDown() {
|
13 |
-
clear_settings();
|
14 |
-
}
|
15 |
-
|
16 |
-
public function testTitlePresence()
|
17 |
-
{
|
18 |
-
$element = self::$driver->findElements(WebDriverBy::xpath('//*[@id="compress-jpeg-png-images"]//a[text()="Settings"]'));
|
19 |
-
$this->assertStringEndsWith('options-media.php#tiny-compress-images', $element[0]->getAttribute('href'));
|
20 |
-
}
|
21 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test/integration/SettingsIntegrationTest.php
CHANGED
@@ -86,74 +86,9 @@ class SettingsIntegrationTest extends IntegrationTestCase {
|
|
86 |
$this->assertEquals(0, count(array_map('elementName', $elements)));
|
87 |
}
|
88 |
|
89 |
-
public function testShouldShowTotalImagesInfo() {
|
90 |
-
$elements = self::$driver->findElement(WebDriverBy::id('tiny-image-sizes-notice'))->findElements(WebDriverBy::tagName('p'));
|
91 |
-
$statuses = array_map('innerText', $elements);
|
92 |
-
$this->assertContains('Each selected size counts as a compression. With these settings you can compress at least 100 images for free each month.', $statuses);
|
93 |
-
}
|
94 |
-
|
95 |
-
public function testShouldUpdateTotalImagesInfo() {
|
96 |
-
$element = self::$driver->findElement(
|
97 |
-
WebDriverBy::xpath('//input[@type="checkbox" and @name="tinypng_sizes[0]" and @checked="checked"]'));
|
98 |
-
$element->click();
|
99 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
100 |
-
WebDriverBy::cssSelector('#tiny-image-sizes-notice'), 'Each selected size counts as a compression. With these settings you can compress at least 125 images for free each month.'));
|
101 |
-
// Not really necessary anymore to assert this.
|
102 |
-
$elements = self::$driver->findElement(WebDriverBy::id('tiny-image-sizes-notice'))->findElements(WebDriverBy::tagName('p'));
|
103 |
-
$statuses = array_map('innerText', $elements);
|
104 |
-
$this->assertContains('Each selected size counts as a compression. With these settings you can compress at least 125 images for free each month.', $statuses);
|
105 |
-
}
|
106 |
-
|
107 |
-
public function testShouldShowCorrectNoImageSizesInfo() {
|
108 |
-
$elements = self::$driver->findElements(
|
109 |
-
WebDriverBy::xpath('//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]'));
|
110 |
-
foreach ($elements as $element) {
|
111 |
-
$element->click();
|
112 |
-
}
|
113 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
114 |
-
WebDriverBy::cssSelector('#tiny-image-sizes-notice'), 'Each selected size counts as a compression. With these settings no images will be compressed.'));
|
115 |
-
// Not really necessary anymore to assert this.
|
116 |
-
$elements = self::$driver->findElement(WebDriverBy::id('tiny-image-sizes-notice'))->findElements(WebDriverBy::tagName('p'));
|
117 |
-
$statuses = array_map('innerText', $elements);
|
118 |
-
$this->assertContains('Each selected size counts as a compression. With these settings no images will be compressed.', $statuses);
|
119 |
-
}
|
120 |
-
|
121 |
-
public function testShouldShowResizingWhenOriginalEnabled() {
|
122 |
-
$element = self::$driver->findElement(WebDriverBy::id('tinypng_sizes_0'));
|
123 |
-
if (!$element->getAttribute('checked')) {
|
124 |
-
$element->click();
|
125 |
-
}
|
126 |
-
$labels = self::$driver->findElements(WebDriverBy::tagName('label'));
|
127 |
-
$texts = array_map('innerText', $labels);
|
128 |
-
$this->assertContains('Resize and compress orginal images to fit within:', $texts);
|
129 |
-
$paragraphs = self::$driver->findElements(WebDriverBy::tagName('p'));
|
130 |
-
$texts = array_map('innerText', $paragraphs);
|
131 |
-
$this->assertNotContains('Enable the compression of the original image size to configure resizing.', $texts);
|
132 |
-
}
|
133 |
-
|
134 |
-
public function testShouldNotShowResizingWhenOriginalDisabled() {
|
135 |
-
$element = self::$driver->findElement(WebDriverBy::id('tinypng_sizes_0'));
|
136 |
-
if ($element->getAttribute('checked')) {
|
137 |
-
$element->click();
|
138 |
-
}
|
139 |
-
$labels = self::$driver->findElements(WebDriverBy::tagName('label'));
|
140 |
-
$texts = array_map('innerText', $labels);
|
141 |
-
$this->assertNotContains('Resize and compress orginal images to fit within:', $texts);
|
142 |
-
$paragraphs = self::$driver->findElements(WebDriverBy::tagName('p'));
|
143 |
-
$texts = array_map('innerText', $paragraphs);
|
144 |
-
$this->assertContains('Enable the compression of the original image size to configure resizing.', $texts);
|
145 |
-
}
|
146 |
-
|
147 |
-
public function testShouldPersistResizingSettings() {
|
148 |
-
$this->enable_resize(123, 456);
|
149 |
-
$this->assertEquals('123', self::$driver->findElement(WebDriverBy::id('tinypng_resize_original_width'))->getAttribute('value'));
|
150 |
-
$this->assertEquals('456', self::$driver->findElement(WebDriverBy::id('tinypng_resize_original_height'))->getAttribute('value'));
|
151 |
-
}
|
152 |
-
|
153 |
public function testStatusPresenceOK() {
|
154 |
reset_webservice();
|
155 |
$this->set_api_key('PNG123');
|
156 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('#tiny-compress-status p')));
|
157 |
$elements = self::$driver->findElement(WebDriverBy::id('tiny-compress-status'))->findElements(WebDriverBy::tagName('p'));
|
158 |
$statuses = array_map('innerText', $elements);
|
159 |
$this->assertContains('API connection successful', $statuses);
|
@@ -162,7 +97,6 @@ class SettingsIntegrationTest extends IntegrationTestCase {
|
|
162 |
|
163 |
public function testStatusPresenseFail() {
|
164 |
$this->set_api_key('INVALID123');
|
165 |
-
self::$driver->wait(2)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::cssSelector('#tiny-compress-status p')));
|
166 |
$elements = self::$driver->findElement(WebDriverBy::id('tiny-compress-status'))->findElements(WebDriverBy::tagName('p'));
|
167 |
$statuses = array_map('innerText', $elements);
|
168 |
$this->assertContains('API connection unsuccessful', $statuses);
|
86 |
$this->assertEquals(0, count(array_map('elementName', $elements)));
|
87 |
}
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
public function testStatusPresenceOK() {
|
90 |
reset_webservice();
|
91 |
$this->set_api_key('PNG123');
|
|
|
92 |
$elements = self::$driver->findElement(WebDriverBy::id('tiny-compress-status'))->findElements(WebDriverBy::tagName('p'));
|
93 |
$statuses = array_map('innerText', $elements);
|
94 |
$this->assertContains('API connection successful', $statuses);
|
97 |
|
98 |
public function testStatusPresenseFail() {
|
99 |
$this->set_api_key('INVALID123');
|
|
|
100 |
$elements = self::$driver->findElement(WebDriverBy::id('tiny-compress-status'))->findElements(WebDriverBy::tagName('p'));
|
101 |
$statuses = array_map('innerText', $elements);
|
102 |
$this->assertContains('API connection unsuccessful', $statuses);
|
test/mock-tinypng-webservice/common.php
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
define('SESSION_FILE', '/tmp/session.dat');
|
4 |
-
|
5 |
-
if (file_exists(SESSION_FILE)) {
|
6 |
-
$session = unserialize(file_get_contents(SESSION_FILE));
|
7 |
-
} else {
|
8 |
-
$session = array('Compression-Count' => 0);
|
9 |
-
}
|
10 |
-
|
11 |
-
function save_session() {
|
12 |
-
global $session;
|
13 |
-
if ($session) {
|
14 |
-
file_put_contents(SESSION_FILE, serialize($session));
|
15 |
-
} elseif (file_exists(SESSION_FILE)) {
|
16 |
-
unlink(SESSION_FILE);
|
17 |
-
}
|
18 |
-
}
|
19 |
-
register_shutdown_function('save_session');
|
20 |
-
|
21 |
-
function get_api_key() {
|
22 |
-
$request_headers = apache_request_headers();
|
23 |
-
if (!isset($request_headers['Authorization'])) {
|
24 |
-
return null;
|
25 |
-
}
|
26 |
-
$basic_auth = base64_decode(str_replace('Basic ', '', $request_headers['Authorization']));
|
27 |
-
return next(explode(':', $basic_auth));
|
28 |
-
}
|
29 |
-
|
30 |
-
function get_json_body() {
|
31 |
-
return json_decode(file_get_contents("php://input"));
|
32 |
-
}
|
33 |
-
|
34 |
-
function mock_invalid_response() {
|
35 |
-
global $session;
|
36 |
-
|
37 |
-
header('HTTP/1.1 401 Unauthorized');
|
38 |
-
header("Content-Type: application/json; charset=utf-8");
|
39 |
-
|
40 |
-
$response = array(
|
41 |
-
"error" => "Unauthorized",
|
42 |
-
"message" => "Credentials are invalid"
|
43 |
-
);
|
44 |
-
return json_encode($response);
|
45 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test/mock-tinypng-webservice/output-resized.jpg
DELETED
Binary file
|
test/mock-tinypng-webservice/output.php
CHANGED
@@ -1,33 +1,13 @@
|
|
1 |
<?php
|
2 |
ob_start();
|
3 |
|
4 |
-
require_once('common.php');
|
5 |
-
|
6 |
if (preg_match('#output/.+[.](png|jpg)$#', $_SERVER['REQUEST_URI'], $match)) {
|
7 |
$file = str_replace('/', '-', $match[0]);
|
8 |
-
$ext = $match[1];
|
9 |
$mime = $match[1] == 'jpg' ? 'image/jpeg' : "image/$ext";
|
10 |
} else {
|
11 |
$file = null;
|
12 |
}
|
13 |
|
14 |
-
$api_key = get_api_key();
|
15 |
-
if (!is_null($api_key)) {
|
16 |
-
$data = get_json_body();
|
17 |
-
if (is_null($data) || $api_key != 'JPG123') {
|
18 |
-
mock_invalid_response();
|
19 |
-
ob_end_flush();
|
20 |
-
exit();
|
21 |
-
}
|
22 |
-
|
23 |
-
$resize = $data->resize;
|
24 |
-
if ($resize->method) {
|
25 |
-
$file = "output-resized.$ext";
|
26 |
-
header("Image-Width: {$resize->width}");
|
27 |
-
header("Image-Height: {$resize->height}");
|
28 |
-
}
|
29 |
-
}
|
30 |
-
|
31 |
if ($file && file_exists($file)) {
|
32 |
header("Content-Type: $mime");
|
33 |
header('Content-Disposition: attachment');
|
@@ -36,4 +16,4 @@ if ($file && file_exists($file)) {
|
|
36 |
header("HTTP/1.1 404 Not Found");
|
37 |
}
|
38 |
|
39 |
-
ob_end_flush();
|
1 |
<?php
|
2 |
ob_start();
|
3 |
|
|
|
|
|
4 |
if (preg_match('#output/.+[.](png|jpg)$#', $_SERVER['REQUEST_URI'], $match)) {
|
5 |
$file = str_replace('/', '-', $match[0]);
|
|
|
6 |
$mime = $match[1] == 'jpg' ? 'image/jpeg' : "image/$ext";
|
7 |
} else {
|
8 |
$file = null;
|
9 |
}
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
if ($file && file_exists($file)) {
|
12 |
header("Content-Type: $mime");
|
13 |
header('Content-Disposition: attachment');
|
16 |
header("HTTP/1.1 404 Not Found");
|
17 |
}
|
18 |
|
19 |
+
ob_end_flush();
|
test/mock-tinypng-webservice/reset.php
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
1 |
<?php
|
2 |
|
3 |
+
define('SESSION_FILE', '/tmp/session.dat');
|
4 |
+
|
5 |
+
if (file_exists(SESSION_FILE)) {
|
6 |
+
unlink(SESSION_FILE);
|
7 |
+
}
|
test/mock-tinypng-webservice/shrink.php
CHANGED
@@ -1,7 +1,13 @@
|
|
1 |
<?php
|
2 |
ob_start();
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
function mock_png_response() {
|
7 |
global $session;
|
@@ -9,11 +15,10 @@ function mock_png_response() {
|
|
9 |
$session['Compression-Count'] += 1;
|
10 |
header('HTTP/1.1 201 Created');
|
11 |
header("Location: http://webservice/output/example.png");
|
12 |
-
header("Content-Type: application/json; charset=utf-8");
|
13 |
header("Compression-Count: {$session['Compression-Count']}");
|
14 |
$response = array(
|
15 |
"input" => array("size" => 161885, "type" => "image/png"),
|
16 |
-
"output" => array("size" => 151021, "type" => "image
|
17 |
);
|
18 |
return json_encode($response);
|
19 |
}
|
@@ -24,7 +29,6 @@ function mock_jpg_response() {
|
|
24 |
$session['Compression-Count'] += 1;
|
25 |
header('HTTP/1.1 201 Created');
|
26 |
header("Location: http://webservice/output/example.jpg");
|
27 |
-
header("Content-Type: application/json; charset=utf-8");
|
28 |
header("Compression-Count: {$session['Compression-Count']}");
|
29 |
|
30 |
$response = array(
|
@@ -40,7 +44,6 @@ function mock_large_response() {
|
|
40 |
$session['Compression-Count'] += 1;
|
41 |
header('HTTP/1.1 201 Created');
|
42 |
header("Location: http://webservice/output/large.png");
|
43 |
-
header("Content-Type: application/json; charset=utf-8");
|
44 |
header("Compression-Count: {$session['Compression-Count']}");
|
45 |
|
46 |
$response = array(
|
@@ -50,6 +53,19 @@ function mock_large_response() {
|
|
50 |
return json_encode($response);
|
51 |
}
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
function mock_empty_response() {
|
54 |
global $session;
|
55 |
|
@@ -78,18 +94,13 @@ function mock_limit_reached_response() {
|
|
78 |
return json_encode($response);
|
79 |
}
|
80 |
|
81 |
-
|
82 |
-
|
|
|
|
|
83 |
|
84 |
-
|
85 |
-
header('HTTP/1.1 201 Created');
|
86 |
-
header("Location: http://webservice/output/example.png");
|
87 |
-
header("Content-Type: application/json; charset=utf-8");
|
88 |
-
header("Compression-Count: {$session['Compression-Count']}");
|
89 |
-
return '{invalid: json}';
|
90 |
-
}
|
91 |
|
92 |
-
$api_key = get_api_key();
|
93 |
if ($api_key == 'PNG123') {
|
94 |
if (intval($_SERVER['CONTENT_LENGTH']) == 0) {
|
95 |
echo mock_empty_response();
|
@@ -102,16 +113,12 @@ if ($api_key == 'PNG123') {
|
|
102 |
} else {
|
103 |
echo mock_jpg_response();
|
104 |
}
|
105 |
-
} else if ($api_key == 'JSON1234') {
|
106 |
-
if (intval($_SERVER['CONTENT_LENGTH']) == 0) {
|
107 |
-
echo mock_empty_response();
|
108 |
-
} else {
|
109 |
-
echo mock_invalid_json_response();
|
110 |
-
}
|
111 |
} else if ($api_key == 'LIMIT123') {
|
112 |
echo mock_limit_reached_response();
|
113 |
} else {
|
114 |
echo mock_invalid_response();
|
115 |
}
|
116 |
|
117 |
-
|
|
|
|
1 |
<?php
|
2 |
ob_start();
|
3 |
|
4 |
+
define('SESSION_FILE', '/tmp/session.dat');
|
5 |
+
|
6 |
+
if (file_exists(SESSION_FILE)) {
|
7 |
+
$session = unserialize(file_get_contents(SESSION_FILE));
|
8 |
+
} else {
|
9 |
+
$session = array('Compression-Count' => 0);
|
10 |
+
}
|
11 |
|
12 |
function mock_png_response() {
|
13 |
global $session;
|
15 |
$session['Compression-Count'] += 1;
|
16 |
header('HTTP/1.1 201 Created');
|
17 |
header("Location: http://webservice/output/example.png");
|
|
|
18 |
header("Compression-Count: {$session['Compression-Count']}");
|
19 |
$response = array(
|
20 |
"input" => array("size" => 161885, "type" => "image/png"),
|
21 |
+
"output" => array("size" => 151021, "type" => "image.png", "ratio" => 0.933)
|
22 |
);
|
23 |
return json_encode($response);
|
24 |
}
|
29 |
$session['Compression-Count'] += 1;
|
30 |
header('HTTP/1.1 201 Created');
|
31 |
header("Location: http://webservice/output/example.jpg");
|
|
|
32 |
header("Compression-Count: {$session['Compression-Count']}");
|
33 |
|
34 |
$response = array(
|
44 |
$session['Compression-Count'] += 1;
|
45 |
header('HTTP/1.1 201 Created');
|
46 |
header("Location: http://webservice/output/large.png");
|
|
|
47 |
header("Compression-Count: {$session['Compression-Count']}");
|
48 |
|
49 |
$response = array(
|
53 |
return json_encode($response);
|
54 |
}
|
55 |
|
56 |
+
function mock_invalid_response() {
|
57 |
+
global $session;
|
58 |
+
|
59 |
+
header('HTTP/1.1 401 Unauthorized');
|
60 |
+
header("Content-Type: application/json; charset=utf-8");
|
61 |
+
|
62 |
+
$response = array(
|
63 |
+
"error" => "Unauthorized",
|
64 |
+
"message" => "Credentials are invalid"
|
65 |
+
);
|
66 |
+
return json_encode($response);
|
67 |
+
}
|
68 |
+
|
69 |
function mock_empty_response() {
|
70 |
global $session;
|
71 |
|
94 |
return json_encode($response);
|
95 |
}
|
96 |
|
97 |
+
$request_headers = apache_request_headers();
|
98 |
+
$basic_auth = base64_decode(str_replace('Basic ', '', $request_headers['Authorization']));
|
99 |
+
$api_key_elements = explode(':', $basic_auth);
|
100 |
+
$api_key = $api_key_elements[1];
|
101 |
|
102 |
+
header("Content-Type: application/json; charset=utf-8");
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
|
|
104 |
if ($api_key == 'PNG123') {
|
105 |
if (intval($_SERVER['CONTENT_LENGTH']) == 0) {
|
106 |
echo mock_empty_response();
|
113 |
} else {
|
114 |
echo mock_jpg_response();
|
115 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
} else if ($api_key == 'LIMIT123') {
|
117 |
echo mock_limit_reached_response();
|
118 |
} else {
|
119 |
echo mock_invalid_response();
|
120 |
}
|
121 |
|
122 |
+
file_put_contents(SESSION_FILE, serialize($session));
|
123 |
+
|
124 |
+
ob_end_flush();
|
test/unit/TinyMetadataTest.php
DELETED
@@ -1,59 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
require_once(dirname(__FILE__) . "/TinyTestCase.php");
|
4 |
-
|
5 |
-
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 |
-
$this->wp->addOption("tinypng_sizes[custom-size]", "on");
|
12 |
-
$this->wp->addOption("tinypng_sizes[custom-size-2]", "on");
|
13 |
-
$this->wp->addImageSize('custom-size', array('width' => 150, 'height' => 150));
|
14 |
-
$this->wp->addImageSize('custom-size-2', array('width' => 150, 'height' => 150));
|
15 |
-
$this->wp->createImages();
|
16 |
-
|
17 |
-
$wp_metadata = array();
|
18 |
-
$wp_metadata['file'] = "2015/09/panda.jpg";
|
19 |
-
$wp_metadata['width'] = 1080;
|
20 |
-
$wp_metadata['height'] = 720;
|
21 |
-
$wp_metadata['sizes'] = array();
|
22 |
-
|
23 |
-
$wp_metadata['sizes']['custom-size'] = array();
|
24 |
-
$wp_metadata['sizes']['custom-size']['file'] = "panda-150x150.jpg";
|
25 |
-
$wp_metadata['sizes']['custom-size']['width'] = 150;
|
26 |
-
$wp_metadata['sizes']['custom-size']['height'] = 150;
|
27 |
-
|
28 |
-
$wp_metadata['sizes']['custom-size-2'] = array();
|
29 |
-
$wp_metadata['sizes']['custom-size-2']['file'] = "panda-150x150.jpg";
|
30 |
-
$wp_metadata['sizes']['custom-size-2']['width'] = 150;
|
31 |
-
$wp_metadata['sizes']['custom-size-2']['height'] = 150;
|
32 |
-
|
33 |
-
$this->subject = new Tiny_Metadata(150, $wp_metadata);
|
34 |
-
}
|
35 |
-
|
36 |
-
public function testGetUncompressedSizesShouldReturnOnlyUniqueSizes() {
|
37 |
-
$tinify_sizes = array(Tiny_Metadata::ORIGINAL, "custom-size", "custom-size-2");
|
38 |
-
$uncompressed_sizes = array(Tiny_Metadata::ORIGINAL, "custom-size");
|
39 |
-
$this->assertEquals($uncompressed_sizes, $this->subject->get_uncompressed_sizes($tinify_sizes));
|
40 |
-
}
|
41 |
-
|
42 |
-
public function testUpdateWpMetadataShouldNotUpdateWithNoResizedOriginal() {
|
43 |
-
$wp_metadata = array(
|
44 |
-
'width' => 2000,
|
45 |
-
'height' => 1000
|
46 |
-
);
|
47 |
-
$this->assertEquals(array('width' => 2000, 'height' => 1000), $this->subject->update_wp_metadata($wp_metadata));
|
48 |
-
}
|
49 |
-
|
50 |
-
public function testUpdateWpMetadataShouldUpdateWithResizedOriginal() {
|
51 |
-
$wp_metadata = array(
|
52 |
-
'width' => 2000,
|
53 |
-
'height' => 1000
|
54 |
-
);
|
55 |
-
$this->subject->add_request();
|
56 |
-
$this->subject->add_response(array('output' => array('width' => 200, 'height' => 100)));
|
57 |
-
$this->assertEquals(array('width' => 200, 'height' => 100), $this->subject->update_wp_metadata($wp_metadata));
|
58 |
-
}
|
59 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test/unit/TinyPluginTest.php
CHANGED
@@ -34,32 +34,19 @@ class Tiny_Plugin_Test extends TinyTestCase {
|
|
34 |
$input = filesize($file);
|
35 |
switch ($key) {
|
36 |
case "thumbnail":
|
37 |
-
$output = 81;
|
38 |
-
$width = '150';
|
39 |
-
$height = '150';
|
40 |
-
break;
|
41 |
case "medium":
|
42 |
-
$output = 768;
|
43 |
-
$width = '300';
|
44 |
-
$height = '300';
|
45 |
-
break;
|
46 |
case "large":
|
47 |
-
$output = 6789;
|
48 |
-
$width = '1024';
|
49 |
-
$height = '1024';
|
50 |
-
break;
|
51 |
case "post-thumbnail":
|
52 |
-
$output = 1000;
|
53 |
-
$width = '800';
|
54 |
-
$height = '500';
|
55 |
-
break;
|
56 |
default:
|
57 |
$output = 10000;
|
58 |
-
$width = '4000';
|
59 |
-
$height = '3000';
|
60 |
}
|
61 |
$this->vfs->getChild(vfsStream::path($file))->truncate($output);
|
62 |
-
return array('input' => array('size' => $input), 'output' => array('size' => $output
|
|
|
63 |
}
|
64 |
|
65 |
public function testInitShouldAddFilters() {
|
@@ -128,14 +115,14 @@ class Tiny_Plugin_Test extends TinyTestCase {
|
|
128 |
|
129 |
$metadata = $this->wp->getMetadata(1, 'tiny_compress_images', true);
|
130 |
foreach ($metadata as $key => $values) {
|
131 |
-
$this->
|
132 |
unset($metadata[$key]['end']);
|
133 |
unset($metadata[$key]['start']);
|
134 |
}
|
135 |
$this->assertEquals(array(
|
136 |
-
0 => array('input' => array('size' => 12345), 'output' => array('size' => 10000
|
137 |
-
'large' => array('input' => array('size' => 10000), 'output' => array('size' => 6789
|
138 |
-
'post-thumbnail' => array('input' => array('size' => 1234), 'output' => array('size' => 1000
|
139 |
), $metadata);
|
140 |
}
|
141 |
|
@@ -199,4 +186,4 @@ class Tiny_Plugin_Test extends TinyTestCase {
|
|
199 |
$this->subject->compress_attachment($testmeta, 1);
|
200 |
$this->assertEquals(2, count($this->wp->getCalls('update_post_meta')));
|
201 |
}
|
202 |
-
}
|
34 |
$input = filesize($file);
|
35 |
switch ($key) {
|
36 |
case "thumbnail":
|
37 |
+
$output = 81; break;
|
|
|
|
|
|
|
38 |
case "medium":
|
39 |
+
$output = 768; break;
|
|
|
|
|
|
|
40 |
case "large":
|
41 |
+
$output = 6789; break;
|
|
|
|
|
|
|
42 |
case "post-thumbnail":
|
43 |
+
$output = 1000; break;
|
|
|
|
|
|
|
44 |
default:
|
45 |
$output = 10000;
|
|
|
|
|
46 |
}
|
47 |
$this->vfs->getChild(vfsStream::path($file))->truncate($output);
|
48 |
+
return array('input' => array('size' => $input), 'output' => array('size' => $output));
|
49 |
+
|
50 |
}
|
51 |
|
52 |
public function testInitShouldAddFilters() {
|
115 |
|
116 |
$metadata = $this->wp->getMetadata(1, 'tiny_compress_images', true);
|
117 |
foreach ($metadata as $key => $values) {
|
118 |
+
$this->assertEquals(time(), $values['end'], 2);
|
119 |
unset($metadata[$key]['end']);
|
120 |
unset($metadata[$key]['start']);
|
121 |
}
|
122 |
$this->assertEquals(array(
|
123 |
+
0 => array('input' => array('size' => 12345), 'output' => array('size' => 10000)),
|
124 |
+
'large' => array('input' => array('size' => 10000), 'output' => array('size' => 6789)),
|
125 |
+
'post-thumbnail' => array('input' => array('size' => 1234), 'output' => array('size' => 1000)),
|
126 |
), $metadata);
|
127 |
}
|
128 |
|
186 |
$this->subject->compress_attachment($testmeta, 1);
|
187 |
$this->assertEquals(2, count($this->wp->getCalls('update_post_meta')));
|
188 |
}
|
189 |
+
}
|
test/unit/TinySettingsTest.php
CHANGED
@@ -14,7 +14,6 @@ class Tiny_Settings_Test extends TinyTestCase {
|
|
14 |
$this->assertEquals(array(
|
15 |
array('media', 'tinypng_api_key'),
|
16 |
array('media', 'tinypng_sizes'),
|
17 |
-
array('media', 'tinypng_resize_original'),
|
18 |
array('media', 'tinypng_status')
|
19 |
), $this->wp->getCalls('register_setting'));
|
20 |
}
|
@@ -29,7 +28,6 @@ class Tiny_Settings_Test extends TinyTestCase {
|
|
29 |
$this->assertEquals(array(
|
30 |
array('tinypng_api_key', 'TinyPNG API key', array($this->subject, 'render_api_key'), 'media', 'tinypng_settings', array('label_for' => 'tinypng_api_key')),
|
31 |
array('tinypng_sizes', 'File compression', array($this->subject, 'render_sizes'), 'media', 'tinypng_settings'),
|
32 |
-
array('tinypng_resize_original', 'Resize original', array($this->subject, 'render_resize'), 'media', 'tinypng_settings'),
|
33 |
array('tinypng_status', 'Connection status', array($this->subject, 'render_pending_status'), 'media', 'tinypng_settings')
|
34 |
), $this->wp->getCalls('add_settings_field'));
|
35 |
}
|
@@ -101,49 +99,4 @@ class Tiny_Settings_Test extends TinyTestCase {
|
|
101 |
array('width' => 0, 'height' => 888, 'tinify' => true),
|
102 |
$sizes["additional_size_no_width"]);
|
103 |
}
|
104 |
-
|
105 |
-
public function testShouldReturnResizeEnabled() {
|
106 |
-
$this->wp->addOption("tinypng_resize_original", array('enabled' => 'on'));
|
107 |
-
$this->assertEquals(true, $this->subject->get_resize_enabled());
|
108 |
-
}
|
109 |
-
|
110 |
-
public function testShouldReturnResizeNotEnabledWithoutConfiguration() {
|
111 |
-
$this->wp->addOption("tinypng_resize_original", array());
|
112 |
-
$this->assertEquals(false, $this->subject->get_resize_enabled());
|
113 |
-
}
|
114 |
-
|
115 |
-
public function testShouldReturnResizeOptionsWithWidthAndHeight() {
|
116 |
-
$this->wp->addOption("tinypng_resize_original", array('enabled' => 'on', 'width' => '800', 'height' => '600'));
|
117 |
-
$this->assertEquals(array('method' => 'fit', 'width' => 800, 'height' => 600), $this->subject->get_resize_options());
|
118 |
-
}
|
119 |
-
|
120 |
-
public function testShouldReturnResizeOptionsWithoutWidth() {
|
121 |
-
$this->wp->addOption("tinypng_resize_original", array('enabled' => 'on', 'width' => '', 'height' => '600'));
|
122 |
-
$this->assertEquals(array('method' => 'scale', 'height' => 600), $this->subject->get_resize_options());
|
123 |
-
}
|
124 |
-
|
125 |
-
public function testShouldReturnResizeOptionsWithoutHeight() {
|
126 |
-
$this->wp->addOption("tinypng_resize_original", array('enabled' => 'on', 'width' => '800', 'height' => '',));
|
127 |
-
$this->assertEquals(array('method' => 'scale', 'width' => 800), $this->subject->get_resize_options());
|
128 |
-
}
|
129 |
-
|
130 |
-
public function testShouldReturnResizeOptionsWithInvaledWidth() {
|
131 |
-
$this->wp->addOption("tinypng_resize_original", array('enabled' => 'on', 'width' => '-1', 'height' => '600'));
|
132 |
-
$this->assertEquals(array('method' => 'scale', 'height' => 600), $this->subject->get_resize_options());
|
133 |
-
}
|
134 |
-
|
135 |
-
public function testShouldReturnResizeOptionsWithInvaledHeight() {
|
136 |
-
$this->wp->addOption("tinypng_resize_original", array('enabled' => 'on', 'width' => '800', 'height' => '-1'));
|
137 |
-
$this->assertEquals(array('method' => 'scale', 'width' => 800), $this->subject->get_resize_options());
|
138 |
-
}
|
139 |
-
|
140 |
-
public function testShouldNotReturnResizeOptionsWithoutWithAndHeight() {
|
141 |
-
$this->wp->addOption("tinypng_resize_original", array('enabled' => 'on', 'width' => '', 'height' => ''));
|
142 |
-
$this->assertEquals(false, $this->subject->get_resize_options());
|
143 |
-
}
|
144 |
-
|
145 |
-
public function testShouldNotReturnResizeOptionsWhenNotEnabled() {
|
146 |
-
$this->wp->addOption("tinypng_resize_original", array('width' => '800', 'height' => '600'));
|
147 |
-
$this->assertEquals(false, $this->subject->get_resize_options());
|
148 |
-
}
|
149 |
}
|
14 |
$this->assertEquals(array(
|
15 |
array('media', 'tinypng_api_key'),
|
16 |
array('media', 'tinypng_sizes'),
|
|
|
17 |
array('media', 'tinypng_status')
|
18 |
), $this->wp->getCalls('register_setting'));
|
19 |
}
|
28 |
$this->assertEquals(array(
|
29 |
array('tinypng_api_key', 'TinyPNG API key', array($this->subject, 'render_api_key'), 'media', 'tinypng_settings', array('label_for' => 'tinypng_api_key')),
|
30 |
array('tinypng_sizes', 'File compression', array($this->subject, 'render_sizes'), 'media', 'tinypng_settings'),
|
|
|
31 |
array('tinypng_status', 'Connection status', array($this->subject, 'render_pending_status'), 'media', 'tinypng_settings')
|
32 |
), $this->wp->getCalls('add_settings_field'));
|
33 |
}
|
99 |
array('width' => 0, 'height' => 888, 'tinify' => true),
|
100 |
$sizes["additional_size_no_width"]);
|
101 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
test/unit/TinyTestCase.php
CHANGED
@@ -27,9 +27,4 @@ abstract class TinyTestCase extends PHPUnit_Framework_TestCase {
|
|
27 |
|
28 |
protected function tearDown() {
|
29 |
}
|
30 |
-
|
31 |
-
protected function assertBetween($lower_bound, $upper_bound, $actual, $message='') {
|
32 |
-
$this->assertGreaterThanOrEqual($lower_bound, $actual, $message);
|
33 |
-
$this->assertLessThanOrEqual($upper_bound, $actual, $message);
|
34 |
-
}
|
35 |
}
|
27 |
|
28 |
protected function tearDown() {
|
29 |
}
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
tiny-compress-images.php
CHANGED
@@ -2,12 +2,13 @@
|
|
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.
|
6 |
* Author: TinyPNG
|
7 |
* Author URI: https://tinypng.com
|
8 |
* License: GPLv2 or later
|
9 |
*/
|
10 |
|
|
|
11 |
require (dirname(__FILE__) . '/src/config/tiny-config.php');
|
12 |
require (dirname(__FILE__) . '/src/class-tiny-php.php');
|
13 |
require (dirname(__FILE__) . '/src/class-tiny-wp-base.php');
|
@@ -24,4 +25,4 @@ $tiny_plugin = new Tiny_Plugin();
|
|
24 |
|
25 |
if (!defined('TINY_DEBUG')) {
|
26 |
define('TINY_DEBUG', null);
|
27 |
-
}
|
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.3.1
|
6 |
* Author: TinyPNG
|
7 |
* Author URI: https://tinypng.com
|
8 |
* License: GPLv2 or later
|
9 |
*/
|
10 |
|
11 |
+
|
12 |
require (dirname(__FILE__) . '/src/config/tiny-config.php');
|
13 |
require (dirname(__FILE__) . '/src/class-tiny-php.php');
|
14 |
require (dirname(__FILE__) . '/src/class-tiny-wp-base.php');
|
25 |
|
26 |
if (!defined('TINY_DEBUG')) {
|
27 |
define('TINY_DEBUG', null);
|
28 |
+
}
|
trunk/tmp/.gitkeep
ADDED
File without changes
|