Version Description
- Use string for text domain instead of PHP Constant ( WordPress Guideline )
Download this release
Release Info
Developer | UmeshSingla |
Plugin | Smush Image Compression and Optimization |
Version | 2.0.6.2 |
Comparing to | |
See all releases |
Code changes from version 2.0.6.3 to 2.0.6.2
- assets/css/wp-smushit-admin.css +0 -78
- assets/js/wp-smushit-admin.js +39 -56
- languages/wp-smushit.pot +146 -260
- lib/class-wp-smush-admin.php +98 -118
- lib/class-wp-smush.php +0 -1062
- readme.txt +2 -14
- wp-smush.php +857 -87
assets/css/wp-smushit-admin.css
CHANGED
@@ -258,7 +258,6 @@ Progressbar ui
|
|
258 |
overflow: hidden;
|
259 |
position: relative;
|
260 |
}
|
261 |
-
|
262 |
#progress-ui #wp-smush-ss-progress-wrap {
|
263 |
/*background-color: #2ea2cc;*/
|
264 |
}
|
@@ -377,21 +376,8 @@ button .wp-smush-loader-wrap {
|
|
377 |
padding: 5px 5px 5px 0;
|
378 |
}
|
379 |
|
380 |
-
/*Pro rows*/
|
381 |
-
#wp-smush-options-wrap .wp-smush-pro-features .wp-smush-setting-row {
|
382 |
-
margin: 5px 20px 5px 25px;
|
383 |
-
}
|
384 |
-
|
385 |
-
#wp-smush-options-wrap .wp-smush-pro-features .pro-note {
|
386 |
-
margin: 0 0 0 25px;
|
387 |
-
}
|
388 |
-
|
389 |
.wp-smush-pro-features {
|
390 |
-
border: 1px solid lightgray;
|
391 |
display: inline-block;
|
392 |
-
padding: 0 0 10px 0;
|
393 |
-
margin: 10px 0 0;
|
394 |
-
width: 85%;
|
395 |
}
|
396 |
|
397 |
input#wp-smush-save-settings {
|
@@ -440,25 +426,6 @@ input#wp-smush-save-settings {
|
|
440 |
content: "";
|
441 |
}
|
442 |
|
443 |
-
.wp-smush-pro-features legend {
|
444 |
-
margin-left: 15px;
|
445 |
-
padding: 0 10px;
|
446 |
-
}
|
447 |
-
|
448 |
-
.pro-note .dashicons-info {
|
449 |
-
color: gray;
|
450 |
-
margin: 0 5px 0 0;
|
451 |
-
}
|
452 |
-
|
453 |
-
.pro-note .find-out-link {
|
454 |
-
margin: -5px 0 0 10px;
|
455 |
-
}
|
456 |
-
|
457 |
-
.wp-smush-setting-row.disabled label, .wp-smush-setting-row.disabled input {
|
458 |
-
color: gray;
|
459 |
-
cursor: default;
|
460 |
-
}
|
461 |
-
|
462 |
/** Grid view button **/
|
463 |
.smush-wrap {
|
464 |
margin-left: 14%;
|
@@ -507,7 +474,6 @@ input#wp-smush-save-settings {
|
|
507 |
#post-body-content .wp-smush-send {
|
508 |
margin: 4px 0 0;
|
509 |
}
|
510 |
-
|
511 |
#post-body-content .smush-status {
|
512 |
margin: 4px 0;
|
513 |
}
|
@@ -569,48 +535,4 @@ input#wp-smush-save-settings {
|
|
569 |
|
570 |
.inactive-anim {
|
571 |
transition: opacity .3s;
|
572 |
-
}
|
573 |
-
|
574 |
-
.smush-stats-wrapper {
|
575 |
-
border: 1px solid lightgray;
|
576 |
-
}
|
577 |
-
table.wp-smush-stats-holder {
|
578 |
-
border-collapse: collapse;
|
579 |
-
width: 100%;
|
580 |
-
}
|
581 |
-
table.wp-smush-stats-holder th {
|
582 |
-
background-color: #E4E4E4;
|
583 |
-
}
|
584 |
-
table.wp-smush-stats-holder td, table.wp-smush-stats-holder th {
|
585 |
-
border: 1px solid #CECECE;
|
586 |
-
}
|
587 |
-
table.wp-smush-stats-holder tr:first-child th {
|
588 |
-
border-top: 0;
|
589 |
-
}
|
590 |
-
table.wp-smush-stats-holder tr:last-child td {
|
591 |
-
border-bottom: 0;
|
592 |
-
}
|
593 |
-
table.wp-smush-stats-holder tr td:first-child,
|
594 |
-
table.wp-smush-stats-holder tr th:first-child {
|
595 |
-
border-left: 0;
|
596 |
-
}
|
597 |
-
table.wp-smush-stats-holder tr td:last-child,
|
598 |
-
table.wp-smush-stats-holder tr th:last-child {
|
599 |
-
border-right: 0;
|
600 |
-
}
|
601 |
-
table.wp-smush-stats-holder tr td:first-child {
|
602 |
-
text-align: right;
|
603 |
-
}
|
604 |
-
.smush-skipped.error {
|
605 |
-
color: #C41921;
|
606 |
-
}
|
607 |
-
.smush-skipped .dashicons-editor-help {
|
608 |
-
cursor: pointer;
|
609 |
-
}
|
610 |
-
/*Media Modal Styling*/
|
611 |
-
.compat-field-wp_smush .wp-smush-stats-holder tr {
|
612 |
-
display: table-row;
|
613 |
-
}
|
614 |
-
.compat-field-wp_smush .wp-smush-stats-holder td {
|
615 |
-
padding: 8px 10px
|
616 |
}
|
258 |
overflow: hidden;
|
259 |
position: relative;
|
260 |
}
|
|
|
261 |
#progress-ui #wp-smush-ss-progress-wrap {
|
262 |
/*background-color: #2ea2cc;*/
|
263 |
}
|
376 |
padding: 5px 5px 5px 0;
|
377 |
}
|
378 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
.wp-smush-pro-features {
|
|
|
380 |
display: inline-block;
|
|
|
|
|
|
|
381 |
}
|
382 |
|
383 |
input#wp-smush-save-settings {
|
426 |
content: "";
|
427 |
}
|
428 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
429 |
/** Grid view button **/
|
430 |
.smush-wrap {
|
431 |
margin-left: 14%;
|
474 |
#post-body-content .wp-smush-send {
|
475 |
margin: 4px 0 0;
|
476 |
}
|
|
|
477 |
#post-body-content .smush-status {
|
478 |
margin: 4px 0;
|
479 |
}
|
535 |
|
536 |
.inactive-anim {
|
537 |
transition: opacity .3s;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
}
|
assets/js/wp-smushit-admin.js
CHANGED
@@ -2,41 +2,40 @@
|
|
2 |
* Processes bulk smushing
|
3 |
*
|
4 |
* @author Saurabh Shukla <saurabh@incsub.com>
|
5 |
-
* @author Umesh Kumar
|
6 |
*
|
7 |
*/
|
8 |
var WP_Smush = WP_Smush || {};
|
9 |
jQuery(function ($) {
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
WP_Smush.Smush = function ($button, bulk) {
|
42 |
var self = this;
|
@@ -172,15 +171,15 @@ jQuery(function ($) {
|
|
172 |
};
|
173 |
|
174 |
this.update_progress = function (stats) {
|
175 |
-
if
|
176 |
//handle progress for normal bulk smush
|
177 |
var progress = ( stats.data.smushed / stats.data.total) * 100;
|
178 |
-
}
|
179 |
//Handle progress for Super smush progress bar
|
180 |
-
if
|
181 |
$('#wp-smush-ss-progress-wrap .remaining-count').html(wp_smushit_data.lossless.length);
|
182 |
-
}
|
183 |
-
$('#wp-smush-ss-progress-wrap #wp-smush-compression').html(wp_smush_msgs.all_supersmushed);
|
184 |
}
|
185 |
|
186 |
}
|
@@ -195,11 +194,11 @@ jQuery(function ($) {
|
|
195 |
|
196 |
this._update_progress = function (count, width) {
|
197 |
"use strict";
|
198 |
-
if
|
199 |
return;
|
200 |
}
|
201 |
|
202 |
-
if
|
203 |
// get the progress bar
|
204 |
var $progress_bar = jQuery('#wp-smush-progress-wrap #wp-smush-fetched-progress div');
|
205 |
if ($progress_bar.length < 1) {
|
@@ -208,9 +207,9 @@ jQuery(function ($) {
|
|
208 |
$('.done-count').html(count);
|
209 |
// increase progress
|
210 |
$progress_bar.css('width', width + '%');
|
211 |
-
}
|
212 |
|
213 |
-
if
|
214 |
var remaining_lossless = this.lossless_count - wp_smushit_data.lossless.length;
|
215 |
var progress_width = ( remaining_lossless / this.lossless_count * 100 );
|
216 |
var $progress_bar = jQuery('#wp-smush-ss-progress-wrap #wp-smush-ss-progress div');
|
@@ -323,20 +322,6 @@ jQuery(function ($) {
|
|
323 |
return;
|
324 |
});
|
325 |
|
326 |
-
/**
|
327 |
-
* Handle the Smush Stats link click
|
328 |
-
*/
|
329 |
-
$('body').on('click', 'a.smush-stats-details', function (e) {
|
330 |
-
|
331 |
-
// prevent the default action
|
332 |
-
e.preventDefault();
|
333 |
-
var slide_symbol = $(this).find('.stats-toggle');
|
334 |
-
$(this).parents().eq(1).find('.smush-stats-wrapper').slideToggle();
|
335 |
-
slide_symbol.text(slide_symbol.text() == '+' ? '-' : '+');
|
336 |
-
|
337 |
-
return;
|
338 |
-
});
|
339 |
-
|
340 |
//Handle smush button click
|
341 |
$('body').on('click', '.wp-smush-send', function (e) {
|
342 |
|
@@ -344,8 +329,6 @@ jQuery(function ($) {
|
|
344 |
e.preventDefault();
|
345 |
new WP_Smush.Smush($(this), false);
|
346 |
});
|
347 |
-
//Stats Button Click
|
348 |
-
|
349 |
|
350 |
});
|
351 |
(function ($) {
|
2 |
* Processes bulk smushing
|
3 |
*
|
4 |
* @author Saurabh Shukla <saurabh@incsub.com>
|
|
|
5 |
*
|
6 |
*/
|
7 |
var WP_Smush = WP_Smush || {};
|
8 |
jQuery(function ($) {
|
9 |
+
// url for smushing
|
10 |
+
WP_Smush.errors = [];
|
11 |
+
WP_Smush.timeout = 60000;
|
12 |
+
/**
|
13 |
+
* Checks for the specified param in URL
|
14 |
+
* @param sParam
|
15 |
+
* @returns {*}
|
16 |
+
*/
|
17 |
+
WP_Smush.geturlparam = function(arg) {
|
18 |
+
var $sPageURL = window.location.search.substring(1);
|
19 |
+
var $sURLVariables = $sPageURL.split('&');
|
20 |
+
|
21 |
+
for (var i = 0; i < $sURLVariables.length; i++) {
|
22 |
+
var $sParameterName = $sURLVariables[i].split('=');
|
23 |
+
if ($sParameterName[0] == arg) {
|
24 |
+
return $sParameterName[1];
|
25 |
+
}
|
26 |
+
}
|
27 |
+
};
|
28 |
+
|
29 |
+
WP_Smush.ajax = function ($id, $send_url, $getnxt) {
|
30 |
+
"use strict";
|
31 |
+
return $.ajax({
|
32 |
+
type: "GET",
|
33 |
+
data: {attachment_id: $id, get_next: $getnxt},
|
34 |
+
url: $send_url,
|
35 |
+
timeout: WP_Smush.timeout,
|
36 |
+
dataType: 'json'
|
37 |
+
});
|
38 |
+
};
|
39 |
|
40 |
WP_Smush.Smush = function ($button, bulk) {
|
41 |
var self = this;
|
171 |
};
|
172 |
|
173 |
this.update_progress = function (stats) {
|
174 |
+
if( !this.is_bulk_super_smush ) {
|
175 |
//handle progress for normal bulk smush
|
176 |
var progress = ( stats.data.smushed / stats.data.total) * 100;
|
177 |
+
}else{
|
178 |
//Handle progress for Super smush progress bar
|
179 |
+
if( wp_smushit_data.lossless.length > 0 ) {
|
180 |
$('#wp-smush-ss-progress-wrap .remaining-count').html(wp_smushit_data.lossless.length);
|
181 |
+
}else if( wp_smushit_data.lossless.length == 0 ){
|
182 |
+
$('#wp-smush-ss-progress-wrap #wp-smush-compression').html( wp_smush_msgs.all_supersmushed );
|
183 |
}
|
184 |
|
185 |
}
|
194 |
|
195 |
this._update_progress = function (count, width) {
|
196 |
"use strict";
|
197 |
+
if( !this.is_bulk ) {
|
198 |
return;
|
199 |
}
|
200 |
|
201 |
+
if( !this.is_bulk_super_smush ) {
|
202 |
// get the progress bar
|
203 |
var $progress_bar = jQuery('#wp-smush-progress-wrap #wp-smush-fetched-progress div');
|
204 |
if ($progress_bar.length < 1) {
|
207 |
$('.done-count').html(count);
|
208 |
// increase progress
|
209 |
$progress_bar.css('width', width + '%');
|
210 |
+
}else{
|
211 |
|
212 |
+
if( this.lossless_count > 0 ) {
|
213 |
var remaining_lossless = this.lossless_count - wp_smushit_data.lossless.length;
|
214 |
var progress_width = ( remaining_lossless / this.lossless_count * 100 );
|
215 |
var $progress_bar = jQuery('#wp-smush-ss-progress-wrap #wp-smush-ss-progress div');
|
322 |
return;
|
323 |
});
|
324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
//Handle smush button click
|
326 |
$('body').on('click', '.wp-smush-send', function (e) {
|
327 |
|
329 |
e.preventDefault();
|
330 |
new WP_Smush.Smush($(this), false);
|
331 |
});
|
|
|
|
|
332 |
|
333 |
});
|
334 |
(function ($) {
|
languages/wp-smushit.pot
CHANGED
@@ -1,164 +1,176 @@
|
|
1 |
-
|
|
|
2 |
msgid ""
|
3 |
msgstr ""
|
4 |
-
"Project-Id-Version: WP Smush\n"
|
5 |
-
"
|
6 |
-
"
|
7 |
-
"Last-Translator: Umesh <umeshsingla05@gmail.com>\n"
|
8 |
-
"Language-Team: Umesh <umeshsingla05@gmail.com>\n"
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
-
"
|
13 |
-
"
|
14 |
-
"
|
15 |
-
"X-Poedit-SourceCharset: UTF-8\n"
|
16 |
-
"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;"
|
17 |
-
"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;"
|
18 |
-
"_nx_noop:3c,1,2;__ngettext_noop:1,2\n"
|
19 |
-
"X-Poedit-SearchPath-0: .\n"
|
20 |
-
"X-Poedit-SearchPathExcluded-0: *.js\n"
|
21 |
-
|
22 |
-
#: extras/free-dashboard/module.php:388
|
23 |
-
#, php-format
|
24 |
-
msgid ""
|
25 |
-
"We're happy that you've chosen to install %s! Are you interested in how to "
|
26 |
-
"make the most of this plugin? How would you like a quick 5 day email crash "
|
27 |
-
"course with actionable advice on building your membership site? Only the "
|
28 |
-
"info you want, no subscription!"
|
29 |
-
msgstr ""
|
30 |
-
|
31 |
-
#: extras/free-dashboard/module.php:403 extras/free-dashboard/module.php:438
|
32 |
-
msgid "Thanks :)"
|
33 |
-
msgstr ""
|
34 |
-
|
35 |
-
#: extras/free-dashboard/module.php:406 extras/free-dashboard/module.php:445
|
36 |
-
msgid "Saving"
|
37 |
-
msgstr ""
|
38 |
-
|
39 |
-
#: extras/free-dashboard/module.php:407 extras/free-dashboard/module.php:446
|
40 |
-
msgid "No thanks"
|
41 |
-
msgstr ""
|
42 |
-
|
43 |
-
#: extras/free-dashboard/module.php:423
|
44 |
-
#, php-format
|
45 |
-
msgid ""
|
46 |
-
"Hey %s, you've been using %s for a while now, and we hope you're happy with "
|
47 |
-
"it."
|
48 |
-
msgstr ""
|
49 |
-
|
50 |
-
#: extras/free-dashboard/module.php:423
|
51 |
-
msgid ""
|
52 |
-
"We've spent countless hours developing this free plugin for you, and we "
|
53 |
-
"would really appreciate it if you dropped us a quick rating!"
|
54 |
-
msgstr ""
|
55 |
-
|
56 |
-
#: extras/free-dashboard/module.php:441
|
57 |
-
#, php-format
|
58 |
-
msgid "Rate %s"
|
59 |
-
msgstr ""
|
60 |
|
|
|
61 |
#. Plugin Name of the plugin/theme
|
62 |
-
#: lib/class-wp-smush-admin.php:
|
63 |
msgid "WP Smush"
|
64 |
msgstr ""
|
65 |
|
66 |
-
#: lib/class-wp-smush-admin.php:
|
67 |
-
#: lib/class-wp-smush-admin.php:
|
68 |
msgid "Bulk Smush Now"
|
69 |
msgstr ""
|
70 |
|
71 |
-
#: lib/class-wp-smush-admin.php:
|
72 |
-
#, php-format
|
73 |
msgid "Bulk Smush %d Attachments"
|
74 |
msgstr ""
|
75 |
|
76 |
-
#: lib/class-wp-smush-admin.php:
|
77 |
msgid "Smushing in Progress"
|
78 |
msgstr ""
|
79 |
|
80 |
-
#: lib/class-wp-smush-admin.php:
|
81 |
msgid "All Done!"
|
82 |
msgstr ""
|
83 |
|
84 |
-
#: lib/class-wp-smush-admin.php:
|
85 |
msgid "Ops!... something went wrong"
|
86 |
msgstr ""
|
87 |
|
88 |
-
#: lib/class-wp-smush-admin.php:
|
89 |
msgid "Super-Smush"
|
90 |
msgstr ""
|
91 |
|
92 |
-
#: lib/class-wp-smush-admin.php:
|
93 |
msgid "Smush it"
|
94 |
msgstr ""
|
95 |
|
96 |
-
#: lib/class-wp-smush-admin.php:
|
97 |
msgid "Smush Now"
|
98 |
msgstr ""
|
99 |
|
100 |
-
#: lib/class-wp-smush-admin.php:
|
101 |
msgid "Sending ..."
|
102 |
msgstr ""
|
103 |
|
104 |
-
#: lib/class-wp-smush-admin.php:
|
105 |
msgid "{{errors}} image(s) were skipped due to an error."
|
106 |
msgstr ""
|
107 |
|
108 |
-
#: lib/class-wp-smush-admin.php:
|
109 |
msgid "All images are Super-Smushed."
|
110 |
msgstr ""
|
111 |
|
112 |
-
#: lib/class-wp-smush-admin.php:
|
113 |
-
msgid "Smush images on upload"
|
114 |
msgstr ""
|
115 |
|
116 |
-
#: lib/class-wp-smush-admin.php:
|
117 |
-
msgid "Smush
|
118 |
msgstr ""
|
119 |
|
120 |
-
#: lib/class-wp-smush-admin.php:
|
121 |
-
msgid "
|
122 |
msgstr ""
|
123 |
|
124 |
-
#: lib/class-wp-smush-admin.php:
|
125 |
-
msgid "
|
126 |
msgstr ""
|
127 |
|
128 |
-
#: lib/class-wp-smush-admin.php:
|
129 |
-
msgid "
|
130 |
msgstr ""
|
131 |
|
132 |
-
#: lib/class-wp-smush-admin.php:
|
133 |
-
msgid "
|
134 |
msgstr ""
|
135 |
|
136 |
-
#: lib/class-wp-smush-admin.php:
|
137 |
-
msgid "
|
138 |
msgstr ""
|
139 |
|
140 |
-
#: lib/class-wp-smush-admin.php:
|
141 |
-
msgid "
|
|
|
|
|
|
|
142 |
msgstr ""
|
143 |
|
144 |
-
#: lib/class-wp-smush-admin.php:
|
145 |
-
msgid "
|
|
|
|
|
146 |
msgstr ""
|
147 |
|
148 |
-
#: lib/class-wp-smush-admin.php:
|
149 |
-
msgid "
|
150 |
msgstr ""
|
151 |
|
152 |
-
#: lib/class-wp-smush-admin.php:
|
153 |
-
msgid "
|
154 |
msgstr ""
|
155 |
|
156 |
-
#: lib/class-wp-smush-admin.php:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
msgid "Save Changes"
|
158 |
msgstr ""
|
159 |
|
160 |
-
#: lib/class-wp-smush-admin.php:
|
161 |
-
#, php-format
|
162 |
msgid ""
|
163 |
"%d image is over 1MB so will be skipped using the free version of the plugin."
|
164 |
msgid_plural ""
|
@@ -167,27 +179,26 @@ msgid_plural ""
|
|
167 |
msgstr[0] ""
|
168 |
msgstr[1] ""
|
169 |
|
170 |
-
#: lib/class-wp-smush-admin.php:
|
171 |
msgid "Smush in Bulk"
|
172 |
msgstr ""
|
173 |
|
174 |
-
#: lib/class-wp-smush-admin.php:
|
175 |
msgid "Congratulations, all your images are currently Smushed!"
|
176 |
msgstr ""
|
177 |
|
178 |
-
#: lib/class-wp-smush-admin.php:
|
179 |
-
#, php-format
|
180 |
msgid "%d attachment in your media library has not been smushed."
|
181 |
msgid_plural ""
|
182 |
"%d image attachments in your media library have not been smushed yet."
|
183 |
msgstr[0] ""
|
184 |
msgstr[1] ""
|
185 |
|
186 |
-
#: lib/class-wp-smush-admin.php:
|
187 |
msgid "Remove size limit »"
|
188 |
msgstr ""
|
189 |
|
190 |
-
#: lib/class-wp-smush-admin.php:
|
191 |
msgid ""
|
192 |
"Please be aware, smushing a large number of images can take a while "
|
193 |
"depending on your server and network speed.\n"
|
@@ -196,77 +207,70 @@ msgid ""
|
|
196 |
"where it left off."
|
197 |
msgstr ""
|
198 |
|
199 |
-
#: lib/class-wp-smush-admin.php:
|
200 |
-
#, php-format
|
201 |
msgid ""
|
202 |
"Free accounts are limited to bulk smushing %d attachments per request. You "
|
203 |
"will need to click to start a new bulk job after each %d attachments."
|
204 |
msgstr ""
|
205 |
|
206 |
-
#: lib/class-wp-smush-admin.php:
|
207 |
msgid "Remove limits »"
|
208 |
msgstr ""
|
209 |
|
210 |
-
#: lib/class-wp-smush-admin.php:
|
211 |
-
#, php-format
|
212 |
msgid ""
|
213 |
"When you <a href=\"%s\">upload some images</a> they will be available to "
|
214 |
"smush here."
|
215 |
msgstr ""
|
216 |
|
217 |
-
#: lib/class-wp-smush-admin.php:
|
218 |
-
#, php-format
|
219 |
msgid ""
|
220 |
"You can also smush images individually from your <a href=\"%s\">Media "
|
221 |
"Library</a>."
|
222 |
msgstr ""
|
223 |
|
224 |
-
#: lib/class-wp-smush-admin.php:
|
225 |
msgid "Reduced by "
|
226 |
msgstr ""
|
227 |
|
228 |
-
#: lib/class-wp-smush-admin.php:
|
229 |
-
#, php-format
|
230 |
msgid ""
|
231 |
"<span class=\"done-count\">%d</span> of <span class=\"total-count\">%d</"
|
232 |
"span> total attachments have been smushed"
|
233 |
msgstr ""
|
234 |
|
235 |
-
#: lib/class-wp-smush-admin.php:
|
236 |
msgid "You don't have permission to work with uploaded files."
|
237 |
msgstr ""
|
238 |
|
239 |
-
#: lib/class-wp-smush-admin.php:
|
240 |
msgid "No attachment ID was provided."
|
241 |
msgstr ""
|
242 |
|
243 |
-
#: lib/class-wp-smush-admin.php:
|
244 |
-
#, php-format
|
245 |
msgid "<p>Please <a href=\"%s\">upload some images</a>.</p>"
|
246 |
msgstr ""
|
247 |
|
248 |
-
#: lib/class-wp-smush-admin.php:
|
249 |
msgid "All your images are already smushed!"
|
250 |
msgstr ""
|
251 |
|
252 |
-
#: lib/class-wp-smush-admin.php:
|
253 |
-
#, php-format
|
254 |
msgid "<strong>%d of %d images</strong> were sent for smushing:"
|
255 |
msgstr ""
|
256 |
|
257 |
-
#: lib/class-wp-smush-admin.php:
|
258 |
msgid "Super-Smush Images"
|
259 |
msgstr ""
|
260 |
|
261 |
-
#: lib/class-wp-smush-admin.php:
|
262 |
msgid ""
|
263 |
"We found attachments that were previously smushed losslessly. If desired you "
|
264 |
"can Super-Smush them now for more savings with almost no noticeable quality "
|
265 |
"loss."
|
266 |
msgstr ""
|
267 |
|
268 |
-
#: lib/class-wp-smush-admin.php:
|
269 |
-
#, php-format
|
270 |
msgid ""
|
271 |
"<span class=\"remaining-count\">%d</span> attachment left to Super-Smush"
|
272 |
msgid_plural ""
|
@@ -274,197 +278,79 @@ msgid_plural ""
|
|
274 |
msgstr[0] ""
|
275 |
msgstr[1] ""
|
276 |
|
277 |
-
#:
|
278 |
-
msgid "
|
279 |
-
msgstr ""
|
280 |
-
|
281 |
-
#: lib/class-wp-smush-admin.php:1179 lib/class-wp-smush-admin.php:1191
|
282 |
-
msgid ""
|
283 |
-
"Smush Full size Image, It is skipped by default, if large size is available "
|
284 |
-
"for a image"
|
285 |
-
msgstr ""
|
286 |
-
|
287 |
-
#: lib/class-wp-smush-admin.php:1180 lib/class-wp-smush-admin.php:1192
|
288 |
-
msgid ""
|
289 |
-
"\"Super-Smush\" your images with our intelligent multi-pass lossy "
|
290 |
-
"compression. Get 2× more compression than lossless with almost no "
|
291 |
-
"noticeable quality loss!"
|
292 |
-
msgstr ""
|
293 |
-
|
294 |
-
#: lib/class-wp-smush-admin.php:1181 lib/class-wp-smush-admin.php:1193
|
295 |
-
msgid ""
|
296 |
-
"Get the best lossless compression. We try multiple methods to squeeze every "
|
297 |
-
"last byte out of your images."
|
298 |
-
msgstr ""
|
299 |
-
|
300 |
-
#: lib/class-wp-smush-admin.php:1182
|
301 |
-
msgid "Smush images up to 32MB."
|
302 |
-
msgstr ""
|
303 |
-
|
304 |
-
#: lib/class-wp-smush-admin.php:1183
|
305 |
-
msgid "Bulk smush ALL your images with one click!"
|
306 |
-
msgstr ""
|
307 |
-
|
308 |
-
#: lib/class-wp-smush-admin.php:1184 lib/class-wp-smush-admin.php:1196
|
309 |
-
msgid ""
|
310 |
-
"Keep a backup of your original un-smushed images in case you want to restore "
|
311 |
-
"later."
|
312 |
-
msgstr ""
|
313 |
-
|
314 |
-
#: lib/class-wp-smush-admin.php:1189
|
315 |
-
msgid "Upgrade to WP Smush Pro to:"
|
316 |
-
msgstr ""
|
317 |
-
|
318 |
-
#: lib/class-wp-smush-admin.php:1194
|
319 |
-
msgid "Smush images greater than 1MB."
|
320 |
-
msgstr ""
|
321 |
-
|
322 |
-
#: lib/class-wp-smush-admin.php:1195
|
323 |
-
msgid "Bulk smush ALL your images with one click! No more rate limiting."
|
324 |
-
msgstr ""
|
325 |
-
|
326 |
-
#: lib/class-wp-smush-admin.php:1197
|
327 |
-
msgid ""
|
328 |
-
"Access 24/7/365 support from <a href=\"https://premium.wpmudev.org/support/?"
|
329 |
-
"utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade"
|
330 |
-
"\">the best WordPress support team on the planet</a>."
|
331 |
-
msgstr ""
|
332 |
-
|
333 |
-
#: lib/class-wp-smush-admin.php:1198
|
334 |
-
msgid ""
|
335 |
-
"Download <a href=\"https://premium.wpmudev.org/?utm_source=wordpress."
|
336 |
-
"org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade\">350+ other premium "
|
337 |
-
"plugins and themes</a> included in your membership."
|
338 |
-
msgstr ""
|
339 |
-
|
340 |
-
#: lib/class-wp-smush-admin.php:1201
|
341 |
-
msgid "Upgrade Now »"
|
342 |
-
msgstr ""
|
343 |
-
|
344 |
-
#: lib/class-wp-smush-admin.php:1204
|
345 |
-
msgid ""
|
346 |
-
"Already upgraded to a WPMU DEV membership? Install and Login to our "
|
347 |
-
"Dashboard plugin to enable Smush Pro features."
|
348 |
-
msgstr ""
|
349 |
-
|
350 |
-
#: lib/class-wp-smush-admin.php:1213
|
351 |
-
msgid "Activate WPMU DEV Dashboard"
|
352 |
-
msgstr ""
|
353 |
-
|
354 |
-
#: lib/class-wp-smush-admin.php:1216
|
355 |
-
msgid "Install WPMU DEV Dashboard"
|
356 |
msgstr ""
|
357 |
|
358 |
-
#:
|
359 |
-
msgid "File
|
360 |
msgstr ""
|
361 |
|
362 |
-
#:
|
363 |
-
#, php-format
|
364 |
msgid "Could not find %s"
|
365 |
msgstr ""
|
366 |
|
367 |
-
#:
|
368 |
-
#, php-format
|
369 |
msgid "%s is not writable"
|
370 |
msgstr ""
|
371 |
|
372 |
-
#:
|
373 |
-
#, php-format
|
374 |
msgid "Skipped (%s), image not found."
|
375 |
msgstr ""
|
376 |
|
377 |
-
#:
|
378 |
-
#, php-format
|
379 |
msgid "Skipped (%s), size limit exceeded."
|
380 |
msgstr ""
|
381 |
|
382 |
-
#:
|
383 |
msgid "Unknown API error"
|
384 |
msgstr ""
|
385 |
|
386 |
-
#:
|
387 |
-
#, php-format
|
388 |
msgid "Size '%s' not processed correctly"
|
389 |
msgstr ""
|
390 |
|
391 |
-
#:
|
392 |
msgid "Size 'full' not processed correctly"
|
393 |
msgstr ""
|
394 |
|
395 |
-
#:
|
396 |
-
#, php-format
|
397 |
msgid "Error posting to API: %s"
|
398 |
msgstr ""
|
399 |
|
400 |
-
#:
|
401 |
-
#, php-format
|
402 |
msgid "Error posting to API: %s %s"
|
403 |
msgstr ""
|
404 |
|
405 |
-
#:
|
406 |
msgid "Smush data corrupted, try again."
|
407 |
msgstr ""
|
408 |
|
409 |
-
#:
|
410 |
msgid "Image couldn't be smushed"
|
411 |
msgstr ""
|
412 |
|
413 |
-
#:
|
414 |
msgid "Error processing request"
|
415 |
msgstr ""
|
416 |
|
417 |
-
#:
|
418 |
msgid "Already Optimized"
|
419 |
msgstr ""
|
420 |
|
421 |
-
#:
|
422 |
-
|
423 |
-
msgid "%d images reduced "
|
424 |
-
msgstr ""
|
425 |
-
|
426 |
-
#: lib/class-wp-smush.php:679
|
427 |
-
msgid "Reduced "
|
428 |
-
msgstr ""
|
429 |
-
|
430 |
-
#: lib/class-wp-smush.php:680
|
431 |
-
#, php-format
|
432 |
-
msgid "by %s ( %01.1f%% )"
|
433 |
-
msgstr ""
|
434 |
-
|
435 |
-
#: lib/class-wp-smush.php:683
|
436 |
-
msgid "Smush stats"
|
437 |
msgstr ""
|
438 |
|
439 |
-
#:
|
440 |
msgid "Not processed"
|
441 |
msgstr ""
|
442 |
|
443 |
-
#:
|
444 |
msgid "Smush Now!"
|
445 |
msgstr ""
|
446 |
|
447 |
-
#:
|
448 |
-
msgid "Large size available for the image."
|
449 |
-
msgstr ""
|
450 |
-
|
451 |
-
#: lib/class-wp-smush.php:986
|
452 |
-
msgid "Image exceeded the 1Mb size limit."
|
453 |
-
msgstr ""
|
454 |
-
|
455 |
-
#: lib/class-wp-smush.php:988
|
456 |
-
msgid " Skipped"
|
457 |
-
msgstr ""
|
458 |
-
|
459 |
-
#: lib/class-wp-smush.php:1005
|
460 |
-
msgid "Image size"
|
461 |
-
msgstr ""
|
462 |
-
|
463 |
-
#: lib/class-wp-smush.php:1006
|
464 |
-
msgid "Savings"
|
465 |
-
msgstr ""
|
466 |
-
|
467 |
-
#: wp-smush.php:82
|
468 |
msgid "Get Fast"
|
469 |
msgstr ""
|
470 |
|
1 |
+
# Copyright (C) 2015 WP Smush
|
2 |
+
# This file is distributed under the same license as the WP Smush package.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: WP Smush 2.0.6.2\n"
|
6 |
+
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-smushit\n"
|
7 |
+
"POT-Creation-Date: 2015-09-15 07:04:21+00:00\n"
|
|
|
|
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
|
12 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
#. #-#-#-#-# plugin.pot (WP Smush 2.0.6.2) #-#-#-#-#
|
16 |
#. Plugin Name of the plugin/theme
|
17 |
+
#: lib/class-wp-smush-admin.php:106 lib/class-wp-smush-admin.php:299
|
18 |
msgid "WP Smush"
|
19 |
msgstr ""
|
20 |
|
21 |
+
#: lib/class-wp-smush-admin.php:218 lib/class-wp-smush-admin.php:989
|
22 |
+
#: lib/class-wp-smush-admin.php:1005
|
23 |
msgid "Bulk Smush Now"
|
24 |
msgstr ""
|
25 |
|
26 |
+
#: lib/class-wp-smush-admin.php:220 lib/class-wp-smush-admin.php:1009
|
|
|
27 |
msgid "Bulk Smush %d Attachments"
|
28 |
msgstr ""
|
29 |
|
30 |
+
#: lib/class-wp-smush-admin.php:224
|
31 |
msgid "Smushing in Progress"
|
32 |
msgstr ""
|
33 |
|
34 |
+
#: lib/class-wp-smush-admin.php:225 lib/class-wp-smush-admin.php:999
|
35 |
msgid "All Done!"
|
36 |
msgstr ""
|
37 |
|
38 |
+
#: lib/class-wp-smush-admin.php:227
|
39 |
msgid "Ops!... something went wrong"
|
40 |
msgstr ""
|
41 |
|
42 |
+
#: lib/class-wp-smush-admin.php:228 wp-smush.php:711
|
43 |
msgid "Super-Smush"
|
44 |
msgstr ""
|
45 |
|
46 |
+
#: lib/class-wp-smush-admin.php:229
|
47 |
msgid "Smush it"
|
48 |
msgstr ""
|
49 |
|
50 |
+
#: lib/class-wp-smush-admin.php:230
|
51 |
msgid "Smush Now"
|
52 |
msgstr ""
|
53 |
|
54 |
+
#: lib/class-wp-smush-admin.php:231
|
55 |
msgid "Sending ..."
|
56 |
msgstr ""
|
57 |
|
58 |
+
#: lib/class-wp-smush-admin.php:232
|
59 |
msgid "{{errors}} image(s) were skipped due to an error."
|
60 |
msgstr ""
|
61 |
|
62 |
+
#: lib/class-wp-smush-admin.php:233
|
63 |
msgid "All images are Super-Smushed."
|
64 |
msgstr ""
|
65 |
|
66 |
+
#: lib/class-wp-smush-admin.php:271
|
67 |
+
msgid "Auto-Smush images on upload"
|
68 |
msgstr ""
|
69 |
|
70 |
+
#: lib/class-wp-smush-admin.php:272
|
71 |
+
msgid "Super-Smush images"
|
72 |
msgstr ""
|
73 |
|
74 |
+
#: lib/class-wp-smush-admin.php:272
|
75 |
+
msgid "lossy optimization"
|
76 |
msgstr ""
|
77 |
|
78 |
+
#: lib/class-wp-smush-admin.php:273
|
79 |
+
msgid "Backup original images"
|
80 |
msgstr ""
|
81 |
|
82 |
+
#: lib/class-wp-smush-admin.php:273
|
83 |
+
msgid "this will nearly double the size of your uploads directory"
|
84 |
msgstr ""
|
85 |
|
86 |
+
#: lib/class-wp-smush-admin.php:297
|
87 |
+
msgid "WP Smush Pro"
|
88 |
msgstr ""
|
89 |
|
90 |
+
#: lib/class-wp-smush-admin.php:305
|
91 |
+
msgid "Thanks for using WP Smush Pro! You now can:"
|
92 |
msgstr ""
|
93 |
|
94 |
+
#: lib/class-wp-smush-admin.php:307 lib/class-wp-smush-admin.php:318
|
95 |
+
msgid ""
|
96 |
+
"\"Super-Smush\" your images with our intelligent multi-pass lossy "
|
97 |
+
"compression. Get 2× more compression than lossless with almost no "
|
98 |
+
"noticeable quality loss!"
|
99 |
msgstr ""
|
100 |
|
101 |
+
#: lib/class-wp-smush-admin.php:308 lib/class-wp-smush-admin.php:319
|
102 |
+
msgid ""
|
103 |
+
"Get the best lossless compression. We try multiple methods to squeeze every "
|
104 |
+
"last byte out of your images."
|
105 |
msgstr ""
|
106 |
|
107 |
+
#: lib/class-wp-smush-admin.php:309
|
108 |
+
msgid "Smush images up to 32MB."
|
109 |
msgstr ""
|
110 |
|
111 |
+
#: lib/class-wp-smush-admin.php:310
|
112 |
+
msgid "Bulk smush ALL your images with one click!"
|
113 |
msgstr ""
|
114 |
|
115 |
+
#: lib/class-wp-smush-admin.php:311 lib/class-wp-smush-admin.php:322
|
116 |
+
msgid ""
|
117 |
+
"Keep a backup of your original un-smushed images in case you want to restore "
|
118 |
+
"later."
|
119 |
+
msgstr ""
|
120 |
+
|
121 |
+
#: lib/class-wp-smush-admin.php:316
|
122 |
+
msgid "Upgrade to WP Smush Pro to:"
|
123 |
+
msgstr ""
|
124 |
+
|
125 |
+
#: lib/class-wp-smush-admin.php:320
|
126 |
+
msgid "Smush images greater than 1MB."
|
127 |
+
msgstr ""
|
128 |
+
|
129 |
+
#: lib/class-wp-smush-admin.php:321
|
130 |
+
msgid "Bulk smush ALL your images with one click! No more rate limiting."
|
131 |
+
msgstr ""
|
132 |
+
|
133 |
+
#: lib/class-wp-smush-admin.php:323
|
134 |
+
msgid ""
|
135 |
+
"Access 24/7/365 support from <a href=\"https://premium.wpmudev.org/support/?"
|
136 |
+
"utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade"
|
137 |
+
"\">the best WordPress support team on the planet</a>."
|
138 |
+
msgstr ""
|
139 |
+
|
140 |
+
#: lib/class-wp-smush-admin.php:324
|
141 |
+
msgid ""
|
142 |
+
"Download <a href=\"https://premium.wpmudev.org/?utm_source=wordpress."
|
143 |
+
"org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade\">350+ other premium "
|
144 |
+
"plugins and themes</a> included in your membership."
|
145 |
+
msgstr ""
|
146 |
+
|
147 |
+
#: lib/class-wp-smush-admin.php:327
|
148 |
+
msgid "Upgrade Now »"
|
149 |
+
msgstr ""
|
150 |
+
|
151 |
+
#: lib/class-wp-smush-admin.php:330
|
152 |
+
msgid ""
|
153 |
+
"Already upgraded to a WPMU DEV membership? Install and Login to our "
|
154 |
+
"Dashboard plugin to enable Smush Pro features."
|
155 |
+
msgstr ""
|
156 |
+
|
157 |
+
#: lib/class-wp-smush-admin.php:339
|
158 |
+
msgid "Activate WPMU DEV Dashboard"
|
159 |
+
msgstr ""
|
160 |
+
|
161 |
+
#: lib/class-wp-smush-admin.php:342
|
162 |
+
msgid "Install WPMU DEV Dashboard"
|
163 |
+
msgstr ""
|
164 |
+
|
165 |
+
#: lib/class-wp-smush-admin.php:353 lib/class-wp-smush-admin.php:1058
|
166 |
+
msgid "Settings"
|
167 |
+
msgstr ""
|
168 |
+
|
169 |
+
#: lib/class-wp-smush-admin.php:439
|
170 |
msgid "Save Changes"
|
171 |
msgstr ""
|
172 |
|
173 |
+
#: lib/class-wp-smush-admin.php:511
|
|
|
174 |
msgid ""
|
175 |
"%d image is over 1MB so will be skipped using the free version of the plugin."
|
176 |
msgid_plural ""
|
179 |
msgstr[0] ""
|
180 |
msgstr[1] ""
|
181 |
|
182 |
+
#: lib/class-wp-smush-admin.php:520
|
183 |
msgid "Smush in Bulk"
|
184 |
msgstr ""
|
185 |
|
186 |
+
#: lib/class-wp-smush-admin.php:525
|
187 |
msgid "Congratulations, all your images are currently Smushed!"
|
188 |
msgstr ""
|
189 |
|
190 |
+
#: lib/class-wp-smush-admin.php:534
|
|
|
191 |
msgid "%d attachment in your media library has not been smushed."
|
192 |
msgid_plural ""
|
193 |
"%d image attachments in your media library have not been smushed yet."
|
194 |
msgstr[0] ""
|
195 |
msgstr[1] ""
|
196 |
|
197 |
+
#: lib/class-wp-smush-admin.php:538
|
198 |
msgid "Remove size limit »"
|
199 |
msgstr ""
|
200 |
|
201 |
+
#: lib/class-wp-smush-admin.php:543
|
202 |
msgid ""
|
203 |
"Please be aware, smushing a large number of images can take a while "
|
204 |
"depending on your server and network speed.\n"
|
207 |
"where it left off."
|
208 |
msgstr ""
|
209 |
|
210 |
+
#: lib/class-wp-smush-admin.php:548
|
|
|
211 |
msgid ""
|
212 |
"Free accounts are limited to bulk smushing %d attachments per request. You "
|
213 |
"will need to click to start a new bulk job after each %d attachments."
|
214 |
msgstr ""
|
215 |
|
216 |
+
#: lib/class-wp-smush-admin.php:549
|
217 |
msgid "Remove limits »"
|
218 |
msgstr ""
|
219 |
|
220 |
+
#: lib/class-wp-smush-admin.php:569
|
|
|
221 |
msgid ""
|
222 |
"When you <a href=\"%s\">upload some images</a> they will be available to "
|
223 |
"smush here."
|
224 |
msgstr ""
|
225 |
|
226 |
+
#: lib/class-wp-smush-admin.php:575 lib/class-wp-smush-admin.php:811
|
|
|
227 |
msgid ""
|
228 |
"You can also smush images individually from your <a href=\"%s\">Media "
|
229 |
"Library</a>."
|
230 |
msgstr ""
|
231 |
|
232 |
+
#: lib/class-wp-smush-admin.php:627
|
233 |
msgid "Reduced by "
|
234 |
msgstr ""
|
235 |
|
236 |
+
#: lib/class-wp-smush-admin.php:637
|
|
|
237 |
msgid ""
|
238 |
"<span class=\"done-count\">%d</span> of <span class=\"total-count\">%d</"
|
239 |
"span> total attachments have been smushed"
|
240 |
msgstr ""
|
241 |
|
242 |
+
#: lib/class-wp-smush-admin.php:707
|
243 |
msgid "You don't have permission to work with uploaded files."
|
244 |
msgstr ""
|
245 |
|
246 |
+
#: lib/class-wp-smush-admin.php:711
|
247 |
msgid "No attachment ID was provided."
|
248 |
msgstr ""
|
249 |
|
250 |
+
#: lib/class-wp-smush-admin.php:781
|
|
|
251 |
msgid "<p>Please <a href=\"%s\">upload some images</a>.</p>"
|
252 |
msgstr ""
|
253 |
|
254 |
+
#: lib/class-wp-smush-admin.php:799
|
255 |
msgid "All your images are already smushed!"
|
256 |
msgstr ""
|
257 |
|
258 |
+
#: lib/class-wp-smush-admin.php:899
|
|
|
259 |
msgid "<strong>%d of %d images</strong> were sent for smushing:"
|
260 |
msgstr ""
|
261 |
|
262 |
+
#: lib/class-wp-smush-admin.php:1185
|
263 |
msgid "Super-Smush Images"
|
264 |
msgstr ""
|
265 |
|
266 |
+
#: lib/class-wp-smush-admin.php:1186
|
267 |
msgid ""
|
268 |
"We found attachments that were previously smushed losslessly. If desired you "
|
269 |
"can Super-Smush them now for more savings with almost no noticeable quality "
|
270 |
"loss."
|
271 |
msgstr ""
|
272 |
|
273 |
+
#: lib/class-wp-smush-admin.php:1194
|
|
|
274 |
msgid ""
|
275 |
"<span class=\"remaining-count\">%d</span> attachment left to Super-Smush"
|
276 |
msgid_plural ""
|
278 |
msgstr[0] ""
|
279 |
msgstr[1] ""
|
280 |
|
281 |
+
#: wp-smush.php:141
|
282 |
+
msgid "File path is empty"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
msgstr ""
|
284 |
|
285 |
+
#: wp-smush.php:145
|
286 |
+
msgid "File URL is empty"
|
287 |
msgstr ""
|
288 |
|
289 |
+
#: wp-smush.php:150
|
|
|
290 |
msgid "Could not find %s"
|
291 |
msgstr ""
|
292 |
|
293 |
+
#: wp-smush.php:155
|
|
|
294 |
msgid "%s is not writable"
|
295 |
msgstr ""
|
296 |
|
297 |
+
#: wp-smush.php:165
|
|
|
298 |
msgid "Skipped (%s), image not found."
|
299 |
msgstr ""
|
300 |
|
301 |
+
#: wp-smush.php:170
|
|
|
302 |
msgid "Skipped (%s), size limit exceeded."
|
303 |
msgstr ""
|
304 |
|
305 |
+
#: wp-smush.php:185
|
306 |
msgid "Unknown API error"
|
307 |
msgstr ""
|
308 |
|
309 |
+
#: wp-smush.php:329
|
|
|
310 |
msgid "Size '%s' not processed correctly"
|
311 |
msgstr ""
|
312 |
|
313 |
+
#: wp-smush.php:351 wp-smush.php:359
|
314 |
msgid "Size 'full' not processed correctly"
|
315 |
msgstr ""
|
316 |
|
317 |
+
#: wp-smush.php:475
|
|
|
318 |
msgid "Error posting to API: %s"
|
319 |
msgstr ""
|
320 |
|
321 |
+
#: wp-smush.php:481
|
|
|
322 |
msgid "Error posting to API: %s %s"
|
323 |
msgstr ""
|
324 |
|
325 |
+
#: wp-smush.php:498
|
326 |
msgid "Smush data corrupted, try again."
|
327 |
msgstr ""
|
328 |
|
329 |
+
#: wp-smush.php:514
|
330 |
msgid "Image couldn't be smushed"
|
331 |
msgstr ""
|
332 |
|
333 |
+
#: wp-smush.php:685
|
334 |
msgid "Error processing request"
|
335 |
msgstr ""
|
336 |
|
337 |
+
#: wp-smush.php:689
|
338 |
msgid "Already Optimized"
|
339 |
msgstr ""
|
340 |
|
341 |
+
#: wp-smush.php:691
|
342 |
+
msgid "Reduced by %s ( %01.1f%% )"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
343 |
msgstr ""
|
344 |
|
345 |
+
#: wp-smush.php:717
|
346 |
msgid "Not processed"
|
347 |
msgstr ""
|
348 |
|
349 |
+
#: wp-smush.php:723
|
350 |
msgid "Smush Now!"
|
351 |
msgstr ""
|
352 |
|
353 |
+
#: wp-smush.php:869
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
msgid "Get Fast"
|
355 |
msgstr ""
|
356 |
|
lib/class-wp-smush-admin.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* @package WP
|
4 |
* @subpackage Admin
|
5 |
* @version 1.0
|
6 |
*
|
@@ -84,6 +84,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
84 |
/// Smush Upgrade
|
85 |
add_action( 'admin_notices', array( $this, 'smush_upgrade' ) );
|
86 |
|
|
|
87 |
$this->init_settings();
|
88 |
|
89 |
}
|
@@ -141,9 +142,6 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
141 |
|
142 |
// Enqueue js on Post screen (Edit screen for media )
|
143 |
add_action( 'admin_print_scripts-post.php', array( $this, 'enqueue' ) );
|
144 |
-
|
145 |
-
// Enqueue js on Post screen (Edit screen for media )
|
146 |
-
add_action( 'admin_print_scripts-post-new.php', array( $this, 'enqueue' ) );
|
147 |
}
|
148 |
|
149 |
/**
|
@@ -168,12 +166,12 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
168 |
wp_register_script( 'wp-smushit-admin-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin.js', array(
|
169 |
'jquery',
|
170 |
'media-views'
|
171 |
-
),
|
172 |
} else {
|
173 |
wp_register_script( 'wp-smushit-admin-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin.js', array(
|
174 |
'jquery',
|
175 |
'underscore'
|
176 |
-
),
|
177 |
}
|
178 |
wp_register_script( 'wp-smushit-admin-media-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin-media.js', array( 'jquery' ), $WpSmush->version );
|
179 |
|
@@ -209,7 +207,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
209 |
|
210 |
function localize() {
|
211 |
global $pagenow;
|
212 |
-
if ( ! isset( $pagenow ) || ! in_array( $pagenow, array( "post.php", "upload.php"
|
213 |
return;
|
214 |
}
|
215 |
|
@@ -258,8 +256,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
258 |
$data = array(
|
259 |
'smushed' => $this->get_smushed_image_ids(),
|
260 |
'unsmushed' => $this->ids,
|
261 |
-
'lossless' => $this->lossless_ids
|
262 |
-
'timeout' => WP_SMUSH_TIMEOUT * 1000 //Convert it into ms
|
263 |
);
|
264 |
|
265 |
wp_localize_script( 'wp-smushit-admin-js', 'wp_smushit_data', $data );
|
@@ -271,10 +268,9 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
271 |
*/
|
272 |
function init_settings() {
|
273 |
$this->settings = array(
|
274 |
-
'auto'
|
275 |
-
'
|
276 |
-
'
|
277 |
-
'backup' => __( 'Backup Original Images', 'wp-smushit' ) . ' <small>(' . __( 'Will nearly double the size of your Uploads Directory', 'wp-smushit' ) . ')</small>'
|
278 |
);
|
279 |
}
|
280 |
|
@@ -302,9 +298,55 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
302 |
} else {
|
303 |
_e( 'WP Smush', 'wp-smushit' );
|
304 |
} ?>
|
305 |
-
</h2
|
306 |
-
|
307 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
<div class="wp-smpushit-container">
|
310 |
<h3>
|
@@ -343,11 +385,6 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
343 |
$opt_auto_val = 1;
|
344 |
}
|
345 |
|
346 |
-
//Smush auto key
|
347 |
-
$opt_original = WP_SMUSH_PREFIX . 'original';
|
348 |
-
//Auto value
|
349 |
-
$opt_original_val = get_option( $opt_original, false );
|
350 |
-
|
351 |
//Smush auto key
|
352 |
$opt_lossy = WP_SMUSH_PREFIX . 'lossy';
|
353 |
//Auto value
|
@@ -359,41 +396,41 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
359 |
$opt_backup_val = get_option( $opt_backup, false );
|
360 |
|
361 |
//disable lossy for non-premium members
|
362 |
-
$disabled = $class =
|
363 |
if ( ! $this->is_pro() ) {
|
364 |
$disabled = ' disabled';
|
365 |
$opt_lossy_val = $opt_backup_val = 0;
|
366 |
$class = ' inactive inactive-anim';
|
367 |
-
}
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
|
|
|
|
|
|
|
|
|
|
375 |
|
|
|
|
|
|
|
|
|
376 |
if ( ! $this->is_pro() ) {
|
377 |
?>
|
378 |
<div class="pro-note">
|
379 |
-
<div style="padding:14px 0 14px;"
|
380 |
-
<a href="<?php echo $this->upgrade_url; ?>" target="_blank"
|
381 |
</div>
|
382 |
</div>
|
383 |
-
|
384 |
-
$feature_class = ' disabled';
|
385 |
}
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
//Lossy
|
391 |
-
printf( "<div class='wp-smush-setting-row%5\$s'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_lossy ), checked( $opt_lossy_val, 1, false ), $disabled, $this->settings['lossy'], $feature_class );
|
392 |
-
|
393 |
-
//Backup
|
394 |
-
printf( "<div class='wp-smush-setting-row%5\$s'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_backup ), checked( $opt_backup_val, 1, false ), $disabled, $this->settings['backup'], $feature_class ); ?>
|
395 |
-
<!-- End of pro-only -->
|
396 |
-
</fieldset>
|
397 |
</div>
|
398 |
<!-- End of wrap --><?php
|
399 |
// nonce
|
@@ -401,7 +438,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
401 |
?>
|
402 |
<input type="submit" id="wp-smush-save-settings" class="button button-primary" value="<?php _e( 'Save Changes', 'wp-smushit' ); ?>">
|
403 |
</form>
|
404 |
-
|
405 |
}
|
406 |
|
407 |
/**
|
@@ -530,7 +567,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
530 |
if ( ! $auto_smush && $this->remaining_count == 0 ) {
|
531 |
?>
|
532 |
<p><?php printf( __( 'When you <a href="%s">upload some images</a> they will be available to smush here.', 'wp-smushit' ), admin_url( 'media-new.php' ) ); ?></p>
|
533 |
-
|
534 |
} else { ?>
|
535 |
<p>
|
536 |
<?php
|
@@ -541,7 +578,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
541 |
}
|
542 |
?>
|
543 |
</div>
|
544 |
-
|
545 |
}
|
546 |
|
547 |
function print_loader() {
|
@@ -566,7 +603,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
566 |
</div>
|
567 |
</div>
|
568 |
</div>
|
569 |
-
|
570 |
}
|
571 |
|
572 |
/**
|
@@ -762,7 +799,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
762 |
_e( 'All your images are already smushed!', 'wp-smushit' );
|
763 |
?>
|
764 |
</p>
|
765 |
-
|
766 |
} else {
|
767 |
$this->selected_ui( $send_ids, '' );
|
768 |
// we have some smushing to do! :)
|
@@ -774,7 +811,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
774 |
printf( __( 'You can also smush images individually from your <a href="%s">Media Library</a>.', 'wp-smushit' ), admin_url( 'upload.php' ) );
|
775 |
?>
|
776 |
</p>
|
777 |
-
|
778 |
}
|
779 |
|
780 |
// display the progress bar
|
@@ -785,7 +822,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
785 |
|
786 |
?>
|
787 |
</div>
|
788 |
-
|
789 |
}
|
790 |
|
791 |
/**
|
@@ -875,7 +912,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
875 |
?>
|
876 |
</ul>
|
877 |
</div>
|
878 |
-
|
879 |
}
|
880 |
|
881 |
/**
|
@@ -890,7 +927,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
890 |
<button class="button button-primary<?php echo ' ' . $button['class']; ?>" name="smush-all" <?php echo $disabled; ?>>
|
891 |
<span><?php echo $button['text'] ?></span>
|
892 |
</button>
|
893 |
-
|
894 |
}
|
895 |
|
896 |
function global_stats() {
|
@@ -1026,7 +1063,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
1026 |
}
|
1027 |
|
1028 |
function smush_upgrade() {
|
1029 |
-
if ( ! current_user_can( 'edit_others_posts' )
|
1030 |
return;
|
1031 |
}
|
1032 |
|
@@ -1042,7 +1079,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
1042 |
return;
|
1043 |
}
|
1044 |
?>
|
1045 |
-
<div class="
|
1046 |
<a href="<?php echo admin_url( 'index.php' ); ?>?dismiss_smush_upgrade=1" style="float:right;margin-top: 10px;text-decoration: none;"><span class="dashicons dashicons-dismiss" style="color:gray;"></span>Dismiss</a>
|
1047 |
|
1048 |
<h3><span class="dashicons dashicons-megaphone" style="color:red"></span> Happy Smushing!</h3>
|
@@ -1059,7 +1096,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
1059 |
<a href="https://premium.wpmudev.org/?coupon=SMUSH50OFF#pricing"> Click here to upgrade with a 50%
|
1060 |
discount</a>.</p>
|
1061 |
</div>
|
1062 |
-
|
1063 |
}
|
1064 |
|
1065 |
/**
|
@@ -1154,73 +1191,16 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
1154 |
<div id="wp-smush-ss-progress" class="wp-smush-progressbar"><div style="width:0%"></div></div>
|
1155 |
<p id="wp-smush-compression">'
|
1156 |
. sprintf(
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
. '</p>
|
1162 |
</div>
|
1163 |
</div><!-- End of progress ui -->';
|
1164 |
echo $ss_progress_ui;
|
1165 |
$this->setup_button( true );
|
1166 |
}
|
1167 |
-
|
1168 |
-
/**
|
1169 |
-
* Displays the features available in Smush pro
|
1170 |
-
*/
|
1171 |
-
function smush_pro_features() {
|
1172 |
-
if ( ! is_super_admin() ) {
|
1173 |
-
return;
|
1174 |
-
}
|
1175 |
-
if ( $this->is_pro() ) { ?>
|
1176 |
-
<div class="wp-smpushit-features updated">
|
1177 |
-
<h3><?php _e( 'Thanks for using WP Smush Pro! You now can:', 'wp-smushit' ) ?></h3>
|
1178 |
-
<ol>
|
1179 |
-
<li><?php _e( 'Smush Full size Image, It is skipped by default, if large size is available for a image', 'wp-smushit' ); ?></li>
|
1180 |
-
<li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2× more compression than lossless with almost no noticeable quality loss!', 'wp-smushit' ); ?></li>
|
1181 |
-
<li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', 'wp-smushit' ); ?></li>
|
1182 |
-
<li><?php _e( 'Smush images up to 32MB.', 'wp-smushit' ); ?></li>
|
1183 |
-
<li><?php _e( 'Bulk smush ALL your images with one click!', 'wp-smushit' ); ?></li>
|
1184 |
-
<li><?php _e( 'Keep a backup of your original un-smushed images in case you want to restore later.', 'wp-smushit' ); ?></li>
|
1185 |
-
</ol>
|
1186 |
-
</div>
|
1187 |
-
<?php } else { ?>
|
1188 |
-
<div class="wp-smpushit-features error">
|
1189 |
-
<h3><?php _e( 'Upgrade to WP Smush Pro to:', 'wp-smushit' ) ?></h3>
|
1190 |
-
<ol>
|
1191 |
-
<li><?php _e( 'Smush Full size Image, It is skipped by default, if large size is available for a image', 'wp-smushit' ); ?></li>
|
1192 |
-
<li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2× more compression than lossless with almost no noticeable quality loss!', 'wp-smushit' ); ?></li>
|
1193 |
-
<li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', 'wp-smushit' ); ?></li>
|
1194 |
-
<li><?php _e( 'Smush images greater than 1MB.', 'wp-smushit' ); ?></li>
|
1195 |
-
<li><?php _e( 'Bulk smush ALL your images with one click! No more rate limiting.', 'wp-smushit' ); ?></li>
|
1196 |
-
<li><?php _e( 'Keep a backup of your original un-smushed images in case you want to restore later.', 'wp-smushit' ); ?></li>
|
1197 |
-
<li><?php _e( 'Access 24/7/365 support from <a href="https://premium.wpmudev.org/support/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade">the best WordPress support team on the planet</a>.', 'wp-smushit' ); ?></li>
|
1198 |
-
<li><?php _e( 'Download <a href="https://premium.wpmudev.org/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade">350+ other premium plugins and themes</a> included in your membership.', 'wp-smushit' ); ?></li>
|
1199 |
-
</ol>
|
1200 |
-
<p>
|
1201 |
-
<a class="button-primary" href="<?php echo $this->upgrade_url; ?>"><?php _e( 'Upgrade Now »', 'wp-smushit' ); ?></a>
|
1202 |
-
</p>
|
1203 |
-
|
1204 |
-
<p><?php _e( 'Already upgraded to a WPMU DEV membership? Install and Login to our Dashboard plugin to enable Smush Pro features.', 'wp-smushit' ); ?></p>
|
1205 |
-
|
1206 |
-
<p>
|
1207 |
-
<?php
|
1208 |
-
if ( ! class_exists( 'WPMUDEV_Dashboard' ) ) {
|
1209 |
-
if ( file_exists( WP_PLUGIN_DIR . '/wpmudev-updates/update-notifications.php' ) ) {
|
1210 |
-
$function = is_multisite() ? 'network_admin_url' : 'admin_url';
|
1211 |
-
$url = wp_nonce_url( $function( 'plugins.php?action=activate&plugin=wpmudev-updates%2Fupdate-notifications.php' ), 'activate-plugin_wpmudev-updates/update-notifications.php' );
|
1212 |
-
?><a class="button-secondary"
|
1213 |
-
href="<?php echo $url; ?>"><?php _e( 'Activate WPMU DEV Dashboard', 'wp-smushit' ); ?></a><?php
|
1214 |
-
} else { //dashboard not installed at all
|
1215 |
-
?><a class="button-secondary" target="_blank"
|
1216 |
-
href="https://premium.wpmudev.org/project/wpmu-dev-dashboard/"><?php _e( 'Install WPMU DEV Dashboard', 'wp-smushit' ); ?></a><?php
|
1217 |
-
}
|
1218 |
-
}
|
1219 |
-
?>
|
1220 |
-
</p>
|
1221 |
-
</div>
|
1222 |
-
<?php }
|
1223 |
-
}
|
1224 |
}
|
1225 |
|
1226 |
$wpsmushit_admin = new WpSmushitAdmin();
|
1 |
<?php
|
2 |
/**
|
3 |
+
* @package WP SmushIt
|
4 |
* @subpackage Admin
|
5 |
* @version 1.0
|
6 |
*
|
84 |
/// Smush Upgrade
|
85 |
add_action( 'admin_notices', array( $this, 'smush_upgrade' ) );
|
86 |
|
87 |
+
|
88 |
$this->init_settings();
|
89 |
|
90 |
}
|
142 |
|
143 |
// Enqueue js on Post screen (Edit screen for media )
|
144 |
add_action( 'admin_print_scripts-post.php', array( $this, 'enqueue' ) );
|
|
|
|
|
|
|
145 |
}
|
146 |
|
147 |
/**
|
166 |
wp_register_script( 'wp-smushit-admin-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin.js', array(
|
167 |
'jquery',
|
168 |
'media-views'
|
169 |
+
), WP_SMUSH_VERSON );
|
170 |
} else {
|
171 |
wp_register_script( 'wp-smushit-admin-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin.js', array(
|
172 |
'jquery',
|
173 |
'underscore'
|
174 |
+
), WP_SMUSH_VERSON );
|
175 |
}
|
176 |
wp_register_script( 'wp-smushit-admin-media-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin-media.js', array( 'jquery' ), $WpSmush->version );
|
177 |
|
207 |
|
208 |
function localize() {
|
209 |
global $pagenow;
|
210 |
+
if ( ! isset( $pagenow ) || ! in_array( $pagenow, array( "post.php", "upload.php" ) ) ) {
|
211 |
return;
|
212 |
}
|
213 |
|
256 |
$data = array(
|
257 |
'smushed' => $this->get_smushed_image_ids(),
|
258 |
'unsmushed' => $this->ids,
|
259 |
+
'lossless' => $this->lossless_ids
|
|
|
260 |
);
|
261 |
|
262 |
wp_localize_script( 'wp-smushit-admin-js', 'wp_smushit_data', $data );
|
268 |
*/
|
269 |
function init_settings() {
|
270 |
$this->settings = array(
|
271 |
+
'auto' => __( 'Auto-Smush images on upload', 'wp-smushit' ),
|
272 |
+
'lossy' => __( 'Super-Smush images', 'wp-smushit' ) . ' <small>(' . __( 'lossy optimization', 'wp-smushit' ) . ')</small>',
|
273 |
+
'backup' => __( 'Backup original images', 'wp-smushit' ) . ' <small>(' . __( 'this will nearly double the size of your uploads directory', 'wp-smushit' ) . ')</small>'
|
|
|
274 |
);
|
275 |
}
|
276 |
|
298 |
} else {
|
299 |
_e( 'WP Smush', 'wp-smushit' );
|
300 |
} ?>
|
301 |
+
</h2>
|
302 |
+
|
303 |
+
<?php if ( $this->is_pro() ) { ?>
|
304 |
+
<div class="wp-smpushit-features updated">
|
305 |
+
<h3><?php _e( 'Thanks for using WP Smush Pro! You now can:', 'wp-smushit' ) ?></h3>
|
306 |
+
<ol>
|
307 |
+
<li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2× more compression than lossless with almost no noticeable quality loss!', 'wp-smushit' ); ?></li>
|
308 |
+
<li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', 'wp-smushit' ); ?></li>
|
309 |
+
<li><?php _e( 'Smush images up to 32MB.', 'wp-smushit' ); ?></li>
|
310 |
+
<li><?php _e( 'Bulk smush ALL your images with one click!', 'wp-smushit' ); ?></li>
|
311 |
+
<li><?php _e( 'Keep a backup of your original un-smushed images in case you want to restore later.', 'wp-smushit' ); ?></li>
|
312 |
+
</ol>
|
313 |
+
</div>
|
314 |
+
<?php } else { ?>
|
315 |
+
<div class="wp-smpushit-features error">
|
316 |
+
<h3><?php _e( 'Upgrade to WP Smush Pro to:', 'wp-smushit' ) ?></h3>
|
317 |
+
<ol>
|
318 |
+
<li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2× more compression than lossless with almost no noticeable quality loss!', 'wp-smushit' ); ?></li>
|
319 |
+
<li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', 'wp-smushit' ); ?></li>
|
320 |
+
<li><?php _e( 'Smush images greater than 1MB.', 'wp-smushit' ); ?></li>
|
321 |
+
<li><?php _e( 'Bulk smush ALL your images with one click! No more rate limiting.', 'wp-smushit' ); ?></li>
|
322 |
+
<li><?php _e( 'Keep a backup of your original un-smushed images in case you want to restore later.', 'wp-smushit' ); ?></li>
|
323 |
+
<li><?php _e( 'Access 24/7/365 support from <a href="https://premium.wpmudev.org/support/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade">the best WordPress support team on the planet</a>.', 'wp-smushit' ); ?></li>
|
324 |
+
<li><?php _e( 'Download <a href="https://premium.wpmudev.org/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade">350+ other premium plugins and themes</a> included in your membership.', 'wp-smushit' ); ?></li>
|
325 |
+
</ol>
|
326 |
+
<p>
|
327 |
+
<a class="button-primary" href="<?php echo $this->upgrade_url; ?>"><?php _e( 'Upgrade Now »', 'wp-smushit' ); ?></a>
|
328 |
+
</p>
|
329 |
+
|
330 |
+
<p><?php _e( 'Already upgraded to a WPMU DEV membership? Install and Login to our Dashboard plugin to enable Smush Pro features.', 'wp-smushit' ); ?></p>
|
331 |
+
|
332 |
+
<p>
|
333 |
+
<?php
|
334 |
+
if ( ! class_exists( 'WPMUDEV_Dashboard' ) ) {
|
335 |
+
if ( file_exists( WP_PLUGIN_DIR . '/wpmudev-updates/update-notifications.php' ) ) {
|
336 |
+
$function = is_multisite() ? 'network_admin_url' : 'admin_url';
|
337 |
+
$url = wp_nonce_url( $function( 'plugins.php?action=activate&plugin=wpmudev-updates%2Fupdate-notifications.php' ), 'activate-plugin_wpmudev-updates/update-notifications.php' );
|
338 |
+
?><a class="button-secondary"
|
339 |
+
href="<?php echo $url; ?>"><?php _e( 'Activate WPMU DEV Dashboard', 'wp-smushit' ); ?></a><?php
|
340 |
+
} else { //dashboard not installed at all
|
341 |
+
?><a class="button-secondary" target="_blank"
|
342 |
+
href="https://premium.wpmudev.org/project/wpmu-dev-dashboard/"><?php _e( 'Install WPMU DEV Dashboard', 'wp-smushit' ); ?></a><?php
|
343 |
+
}
|
344 |
+
}
|
345 |
+
?>
|
346 |
+
</p>
|
347 |
+
</div>
|
348 |
+
<?php } ?>
|
349 |
+
|
350 |
|
351 |
<div class="wp-smpushit-container">
|
352 |
<h3>
|
385 |
$opt_auto_val = 1;
|
386 |
}
|
387 |
|
|
|
|
|
|
|
|
|
|
|
388 |
//Smush auto key
|
389 |
$opt_lossy = WP_SMUSH_PREFIX . 'lossy';
|
390 |
//Auto value
|
396 |
$opt_backup_val = get_option( $opt_backup, false );
|
397 |
|
398 |
//disable lossy for non-premium members
|
399 |
+
$disabled = $class = '';
|
400 |
if ( ! $this->is_pro() ) {
|
401 |
$disabled = ' disabled';
|
402 |
$opt_lossy_val = $opt_backup_val = 0;
|
403 |
$class = ' inactive inactive-anim';
|
404 |
+
}
|
405 |
+
|
406 |
+
// return html
|
407 |
+
printf(
|
408 |
+
"<div class='wp-smush-setting-row'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_auto ), checked( $opt_auto_val, 1, false ), '', $this->settings['auto']
|
409 |
+
);
|
410 |
+
?>
|
411 |
+
<div class="pro-only<?php echo $class; ?>"><?php
|
412 |
+
|
413 |
+
//Lossy
|
414 |
+
printf(
|
415 |
+
"<div class='wp-smush-setting-row'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_lossy ), checked( $opt_lossy_val, 1, false ), $disabled, $this->settings['lossy']
|
416 |
+
);
|
417 |
|
418 |
+
//Backup
|
419 |
+
printf(
|
420 |
+
"<div class='wp-smush-setting-row'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_backup ), checked( $opt_backup_val, 1, false ), $disabled, $this->settings['backup']
|
421 |
+
);
|
422 |
if ( ! $this->is_pro() ) {
|
423 |
?>
|
424 |
<div class="pro-note">
|
425 |
+
<div style="padding:14px 0 14px;">Pro feature only.
|
426 |
+
<a href="<?php echo $this->upgrade_url; ?>" target="_blank">Find out more »</a>
|
427 |
</div>
|
428 |
</div>
|
429 |
+
<?php
|
|
|
430 |
}
|
431 |
+
?>
|
432 |
+
</div>
|
433 |
+
<!-- End of pro-only -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
</div>
|
435 |
<!-- End of wrap --><?php
|
436 |
// nonce
|
438 |
?>
|
439 |
<input type="submit" id="wp-smush-save-settings" class="button button-primary" value="<?php _e( 'Save Changes', 'wp-smushit' ); ?>">
|
440 |
</form>
|
441 |
+
<?php
|
442 |
}
|
443 |
|
444 |
/**
|
567 |
if ( ! $auto_smush && $this->remaining_count == 0 ) {
|
568 |
?>
|
569 |
<p><?php printf( __( 'When you <a href="%s">upload some images</a> they will be available to smush here.', 'wp-smushit' ), admin_url( 'media-new.php' ) ); ?></p>
|
570 |
+
<?php
|
571 |
} else { ?>
|
572 |
<p>
|
573 |
<?php
|
578 |
}
|
579 |
?>
|
580 |
</div>
|
581 |
+
<?php
|
582 |
}
|
583 |
|
584 |
function print_loader() {
|
603 |
</div>
|
604 |
</div>
|
605 |
</div>
|
606 |
+
<?php
|
607 |
}
|
608 |
|
609 |
/**
|
799 |
_e( 'All your images are already smushed!', 'wp-smushit' );
|
800 |
?>
|
801 |
</p>
|
802 |
+
<?php
|
803 |
} else {
|
804 |
$this->selected_ui( $send_ids, '' );
|
805 |
// we have some smushing to do! :)
|
811 |
printf( __( 'You can also smush images individually from your <a href="%s">Media Library</a>.', 'wp-smushit' ), admin_url( 'upload.php' ) );
|
812 |
?>
|
813 |
</p>
|
814 |
+
<?php
|
815 |
}
|
816 |
|
817 |
// display the progress bar
|
822 |
|
823 |
?>
|
824 |
</div>
|
825 |
+
<?php
|
826 |
}
|
827 |
|
828 |
/**
|
912 |
?>
|
913 |
</ul>
|
914 |
</div>
|
915 |
+
<?php
|
916 |
}
|
917 |
|
918 |
/**
|
927 |
<button class="button button-primary<?php echo ' ' . $button['class']; ?>" name="smush-all" <?php echo $disabled; ?>>
|
928 |
<span><?php echo $button['text'] ?></span>
|
929 |
</button>
|
930 |
+
<?php
|
931 |
}
|
932 |
|
933 |
function global_stats() {
|
1063 |
}
|
1064 |
|
1065 |
function smush_upgrade() {
|
1066 |
+
if ( ! current_user_can( 'edit_others_posts' ) ) {
|
1067 |
return;
|
1068 |
}
|
1069 |
|
1079 |
return;
|
1080 |
}
|
1081 |
?>
|
1082 |
+
<div class="error">
|
1083 |
<a href="<?php echo admin_url( 'index.php' ); ?>?dismiss_smush_upgrade=1" style="float:right;margin-top: 10px;text-decoration: none;"><span class="dashicons dashicons-dismiss" style="color:gray;"></span>Dismiss</a>
|
1084 |
|
1085 |
<h3><span class="dashicons dashicons-megaphone" style="color:red"></span> Happy Smushing!</h3>
|
1096 |
<a href="https://premium.wpmudev.org/?coupon=SMUSH50OFF#pricing"> Click here to upgrade with a 50%
|
1097 |
discount</a>.</p>
|
1098 |
</div>
|
1099 |
+
<?php
|
1100 |
}
|
1101 |
|
1102 |
/**
|
1191 |
<div id="wp-smush-ss-progress" class="wp-smush-progressbar"><div style="width:0%"></div></div>
|
1192 |
<p id="wp-smush-compression">'
|
1193 |
. sprintf(
|
1194 |
+
_n( '<span class="remaining-count">%d</span> attachment left to Super-Smush',
|
1195 |
+
'<span class="remaining-count">%d</span> attachments left to Super-Smush',
|
1196 |
+
count( $this->lossless_ids ),
|
1197 |
+
'wp-smushit' ), count( $this->lossless_ids ), count( $this->lossless_ids ) )
|
1198 |
. '</p>
|
1199 |
</div>
|
1200 |
</div><!-- End of progress ui -->';
|
1201 |
echo $ss_progress_ui;
|
1202 |
$this->setup_button( true );
|
1203 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1204 |
}
|
1205 |
|
1206 |
$wpsmushit_admin = new WpSmushitAdmin();
|
lib/class-wp-smush.php
DELETED
@@ -1,1062 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
require_once WP_SMUSH_DIR . "lib/class-wp-smush-migrate.php";
|
3 |
-
if ( ! class_exists( 'WpSmush' ) ) {
|
4 |
-
|
5 |
-
class WpSmush {
|
6 |
-
|
7 |
-
var $version = WP_SMUSH_VERSION;
|
8 |
-
|
9 |
-
var $is_pro;
|
10 |
-
|
11 |
-
/**
|
12 |
-
* Meta key for api validity
|
13 |
-
*
|
14 |
-
*/
|
15 |
-
const VALIDITY_KEY = "wp-smush-valid";
|
16 |
-
|
17 |
-
/**
|
18 |
-
* Api server url to check api key validity
|
19 |
-
*
|
20 |
-
*/
|
21 |
-
const API_SERVER = 'https://premium.wpmudev.org/wdp-un.php?action=smushit_check';
|
22 |
-
|
23 |
-
/**
|
24 |
-
* Meta key to save smush result to db
|
25 |
-
*
|
26 |
-
*
|
27 |
-
*/
|
28 |
-
const SMUSHED_META_KEY = 'wp-smpro-smush-data';
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Meta key to save migrated version
|
32 |
-
*
|
33 |
-
*/
|
34 |
-
const MIGRATED_VERSION = "wp-smush-migrated-version";
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Constructor
|
38 |
-
*/
|
39 |
-
function __construct() {
|
40 |
-
/**
|
41 |
-
* Hooks
|
42 |
-
*/
|
43 |
-
//Check if auto is enabled
|
44 |
-
$auto_smush = get_option( WP_SMUSH_PREFIX . 'auto' );
|
45 |
-
|
46 |
-
//Keep the uto smush on by default
|
47 |
-
if ( $auto_smush === false ) {
|
48 |
-
$auto_smush = 1;
|
49 |
-
}
|
50 |
-
|
51 |
-
//Auto Smush the new image
|
52 |
-
if ( $auto_smush ) {
|
53 |
-
add_filter( 'wp_update_attachment_metadata', array(
|
54 |
-
$this,
|
55 |
-
'filter_generate_attachment_metadata'
|
56 |
-
), 20, 2 );
|
57 |
-
}
|
58 |
-
|
59 |
-
//Optimise WP Retina 2x images
|
60 |
-
add_action( 'wr2x_retina_file_added', array( $this, 'smush_retina_image' ), 20, 3 );
|
61 |
-
|
62 |
-
//Add Smush Columns
|
63 |
-
add_filter( 'manage_media_columns', array( $this, 'columns' ) );
|
64 |
-
add_action( 'manage_media_custom_column', array( $this, 'custom_column' ), 10, 2 );
|
65 |
-
|
66 |
-
//Enqueue Scripts
|
67 |
-
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
68 |
-
|
69 |
-
//Old Smush stats migration
|
70 |
-
add_action( "admin_init", array( $this, "migrate" ) );
|
71 |
-
|
72 |
-
}
|
73 |
-
|
74 |
-
function admin_init() {
|
75 |
-
load_plugin_textdomain( 'wp-smushit', false, dirname( WP_SMUSH_BASENAME ) . '/languages/' );
|
76 |
-
wp_enqueue_script( 'common' );
|
77 |
-
}
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Process an image with Smush.
|
81 |
-
*
|
82 |
-
* Returns an array of the $file $results.
|
83 |
-
*
|
84 |
-
* @param string $file Full absolute path to the image file
|
85 |
-
* @param string $file_url Optional full URL to the image file
|
86 |
-
*
|
87 |
-
* @returns array
|
88 |
-
*/
|
89 |
-
function do_smushit( $file_path = '' ) {
|
90 |
-
$errors = new WP_Error();
|
91 |
-
if ( empty( $file_path ) ) {
|
92 |
-
$errors->add( "empty_path", __( "File path is empty", 'wp-smushit' ) );
|
93 |
-
}
|
94 |
-
|
95 |
-
// check that the file exists
|
96 |
-
if ( ! file_exists( $file_path ) || ! is_file( $file_path ) ) {
|
97 |
-
$errors->add( "file_not_found", sprintf( __( "Could not find %s", 'wp-smushit' ), $file_path ) );
|
98 |
-
}
|
99 |
-
|
100 |
-
// check that the file is writable
|
101 |
-
if ( ! is_writable( dirname( $file_path ) ) ) {
|
102 |
-
$errors->add( "not_writable", sprintf( __( "%s is not writable", 'wp-smushit' ), dirname( $file_path ) ) );
|
103 |
-
}
|
104 |
-
|
105 |
-
$file_size = filesize( $file_path );
|
106 |
-
|
107 |
-
//Check if premium user
|
108 |
-
$max_size = $this->is_pro() ? WP_SMUSH_PREMIUM_MAX_BYTES : WP_SMUSH_MAX_BYTES;
|
109 |
-
|
110 |
-
//Check if file exists
|
111 |
-
if ( $file_size == 0 ) {
|
112 |
-
$errors->add( "image_not_found", sprintf( __( 'Skipped (%s), image not found.', 'wp-smushit' ), $this->format_bytes( $file_size ) ) );
|
113 |
-
}
|
114 |
-
|
115 |
-
//Check size limit
|
116 |
-
if ( $file_size > $max_size ) {
|
117 |
-
$errors->add( "size_limit", sprintf( __( 'Skipped (%s), size limit exceeded.', 'wp-smushit' ), $this->format_bytes( $file_size ) ) );
|
118 |
-
}
|
119 |
-
|
120 |
-
if ( count( $errors->get_error_messages() ) ) {
|
121 |
-
return $errors;
|
122 |
-
}
|
123 |
-
|
124 |
-
/** Send image for smushing, and fetch the response */
|
125 |
-
$response = $this->_post( $file_path, $file_size );
|
126 |
-
|
127 |
-
if ( ! $response['success'] ) {
|
128 |
-
$errors->add( "false_response", $response['message'] );
|
129 |
-
}
|
130 |
-
//If there is no data
|
131 |
-
if ( empty( $response['data'] ) ) {
|
132 |
-
$errors->add( "no_data", __( 'Unknown API error', 'wp-smushit' ) );
|
133 |
-
}
|
134 |
-
|
135 |
-
if ( count( $errors->get_error_messages() ) ) {
|
136 |
-
return $errors;
|
137 |
-
}
|
138 |
-
|
139 |
-
//If there are no savings, or image returned is bigger in size
|
140 |
-
if ( ( ! empty( $response['data']->bytes_saved ) && intval( $response['data']->bytes_saved ) <= 0 )
|
141 |
-
|| empty( $response['data']->image )
|
142 |
-
) {
|
143 |
-
return $response;
|
144 |
-
}
|
145 |
-
$tempfile = $file_path . ".tmp";
|
146 |
-
|
147 |
-
//Add the file as tmp
|
148 |
-
file_put_contents( $tempfile, $response['data']->image );
|
149 |
-
|
150 |
-
//handle backups if enabled
|
151 |
-
$backup = get_option( WP_SMUSH_PREFIX . 'backup' );
|
152 |
-
if ( $backup && $this->is_pro() ) {
|
153 |
-
$path = pathinfo( $file_path );
|
154 |
-
$backup_name = trailingslashit( $path['dirname'] ) . $path['filename'] . ".bak." . $path['extension'];
|
155 |
-
@copy( $file_path, $backup_name );
|
156 |
-
}
|
157 |
-
|
158 |
-
//replace the file
|
159 |
-
$success = @rename( $tempfile, $file_path );
|
160 |
-
|
161 |
-
//if tempfile still exists, unlink it
|
162 |
-
if ( file_exists( $tempfile ) ) {
|
163 |
-
unlink( $tempfile );
|
164 |
-
}
|
165 |
-
|
166 |
-
//If file renaming failed
|
167 |
-
if ( ! $success ) {
|
168 |
-
copy( $tempfile, $file_path );
|
169 |
-
unlink( $tempfile );
|
170 |
-
}
|
171 |
-
|
172 |
-
//Some servers are having issue with file permission, this should fix it
|
173 |
-
chmod($file_path, 0644);
|
174 |
-
|
175 |
-
return $response;
|
176 |
-
}
|
177 |
-
|
178 |
-
/**
|
179 |
-
* Fills $placeholder array with values from $data array
|
180 |
-
*
|
181 |
-
* @param array $placeholders
|
182 |
-
* @param array $data
|
183 |
-
*
|
184 |
-
* @return array
|
185 |
-
*/
|
186 |
-
private function _array_fill_placeholders( array $placeholders, array $data ) {
|
187 |
-
$placeholders['percent'] = $data['compression'];
|
188 |
-
$placeholders['bytes'] = $data['bytes_saved'];
|
189 |
-
$placeholders['size_before'] = $data['before_size'];
|
190 |
-
$placeholders['size_after'] = $data['after_size'];
|
191 |
-
$placeholders['time'] = $data['time'];
|
192 |
-
|
193 |
-
return $placeholders;
|
194 |
-
}
|
195 |
-
|
196 |
-
/**
|
197 |
-
* Returns signature for single size of the smush api message to be saved to db;
|
198 |
-
*
|
199 |
-
* @return array
|
200 |
-
*/
|
201 |
-
private function _get_size_signature() {
|
202 |
-
return array(
|
203 |
-
'percent' => - 1,
|
204 |
-
'bytes' => - 1,
|
205 |
-
'size_before' => - 1,
|
206 |
-
'size_after' => - 1,
|
207 |
-
'time' => - 1
|
208 |
-
);
|
209 |
-
}
|
210 |
-
|
211 |
-
/**
|
212 |
-
* Read the image paths from an attachment's meta data and process each image
|
213 |
-
* with wp_smushit().
|
214 |
-
*
|
215 |
-
* This method also adds a `wp_smushit` meta key for use in the media library.
|
216 |
-
* Called after `wp_generate_attachment_metadata` is completed.
|
217 |
-
*
|
218 |
-
* @param $meta
|
219 |
-
* @param null $ID
|
220 |
-
*
|
221 |
-
* @return mixed
|
222 |
-
*/
|
223 |
-
function resize_from_meta_data( $meta, $ID = null ) {
|
224 |
-
|
225 |
-
//Flag to check, if original size image should be smushed or not
|
226 |
-
$original = get_option( WP_SMUSH_PREFIX . 'original' );
|
227 |
-
$smush_full = ( $this->is_pro() && $original == 1 ) ? true : false;
|
228 |
-
|
229 |
-
$errors = new WP_Error();
|
230 |
-
$stats = array(
|
231 |
-
"stats" => array_merge( $this->_get_size_signature(), array(
|
232 |
-
'api_version' => - 1,
|
233 |
-
'lossy' => - 1
|
234 |
-
)
|
235 |
-
),
|
236 |
-
'sizes' => array()
|
237 |
-
);
|
238 |
-
|
239 |
-
$size_before = $size_after = $compression = $total_time = $bytes_saved = 0;
|
240 |
-
|
241 |
-
if ( $ID && wp_attachment_is_image( $ID ) === false ) {
|
242 |
-
return $meta;
|
243 |
-
}
|
244 |
-
|
245 |
-
//File path and URL for original image
|
246 |
-
$attachment_file_path = get_attached_file( $ID );
|
247 |
-
|
248 |
-
// If images has other registered size, smush them first
|
249 |
-
if ( ! empty( $meta['sizes'] ) ) {
|
250 |
-
|
251 |
-
//if smush original is set to false, otherwise smush
|
252 |
-
//Check for large size, we will set a flag to leave the original untouched
|
253 |
-
if ( ! $smush_full ) {
|
254 |
-
if ( array_key_exists( 'large', $meta['sizes'] ) ) {
|
255 |
-
$smush_full = false;
|
256 |
-
} else {
|
257 |
-
$smush_full = true;
|
258 |
-
}
|
259 |
-
}
|
260 |
-
|
261 |
-
foreach ( $meta['sizes'] as $size_key => $size_data ) {
|
262 |
-
|
263 |
-
// We take the original image. The 'sizes' will all match the same URL and
|
264 |
-
// path. So just get the dirname and replace the filename.
|
265 |
-
$attachment_file_path_size = trailingslashit( dirname( $attachment_file_path ) ) . $size_data['file'];
|
266 |
-
|
267 |
-
//Store details for each size key
|
268 |
-
$response = $this->do_smushit( $attachment_file_path_size );
|
269 |
-
|
270 |
-
if ( is_wp_error( $response ) ) {
|
271 |
-
return $response;
|
272 |
-
}
|
273 |
-
|
274 |
-
if ( ! empty( $response['data'] ) ) {
|
275 |
-
$stats['sizes'][ $size_key ] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $response['data'] );
|
276 |
-
}
|
277 |
-
|
278 |
-
//Total Stats, store all data in bytes
|
279 |
-
if ( isset( $response['data'] ) ) {
|
280 |
-
list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
|
281 |
-
= $this->_update_stats_data( $response['data'], $size_before, $size_after, $total_time, $bytes_saved );
|
282 |
-
} else {
|
283 |
-
$errors->add( "image_size_error" . $size_key, sprintf( __( "Size '%s' not processed correctly", 'wp-smushit' ), $size_key ) );
|
284 |
-
}
|
285 |
-
|
286 |
-
if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
|
287 |
-
$stats['stats']['api_version'] = $response['data']->api_version;
|
288 |
-
$stats['stats']['lossy'] = $response['data']->lossy;
|
289 |
-
}
|
290 |
-
}
|
291 |
-
}
|
292 |
-
|
293 |
-
//If original size is supposed to be smushed
|
294 |
-
if ( $smush_full ) {
|
295 |
-
|
296 |
-
$full_image_response = $this->do_smushit( $attachment_file_path );
|
297 |
-
|
298 |
-
if ( is_wp_error( $full_image_response ) ) {
|
299 |
-
return $full_image_response;
|
300 |
-
}
|
301 |
-
|
302 |
-
if ( ! empty( $full_image_response['data'] ) ) {
|
303 |
-
$stats['sizes']['full'] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $full_image_response['data'] );
|
304 |
-
} else {
|
305 |
-
$errors->add( "image_size_error", __( "Size 'full' not processed correctly", 'wp-smushit' ) );
|
306 |
-
}
|
307 |
-
|
308 |
-
//Update stats
|
309 |
-
if ( isset( $full_image_response['data'] ) ) {
|
310 |
-
list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
|
311 |
-
= $this->_update_stats_data( $full_image_response['data'], $size_before, $size_after, $total_time, $bytes_saved );
|
312 |
-
} else {
|
313 |
-
$errors->add( "image_size_error", __( "Size 'full' not processed correctly", 'wp-smushit' ) );
|
314 |
-
}
|
315 |
-
|
316 |
-
//Api version and lossy, for some images, full image i skipped and for other images only full exists
|
317 |
-
//so have to add code again
|
318 |
-
if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
|
319 |
-
$stats['stats']['api_version'] = $full_image_response['data']->api_version;
|
320 |
-
$stats['stats']['lossy'] = $full_image_response['data']->lossy;
|
321 |
-
}
|
322 |
-
|
323 |
-
|
324 |
-
}
|
325 |
-
|
326 |
-
$has_errors = (bool) count( $errors->get_error_messages() );
|
327 |
-
|
328 |
-
list( $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['percent'], $stats['stats']['bytes'] ) =
|
329 |
-
array( $size_before, $size_after, $total_time, $compression, $bytes_saved );
|
330 |
-
|
331 |
-
//Set smush status for all the images, store it in wp-smpro-smush-data
|
332 |
-
if ( ! $has_errors ) {
|
333 |
-
|
334 |
-
$existing_stats = get_post_meta( $ID, self::SMUSHED_META_KEY, true );
|
335 |
-
|
336 |
-
if ( ! empty( $existing_stats ) ) {
|
337 |
-
//Update total bytes saved, and compression percent
|
338 |
-
$stats['stats']['bytes'] = isset( $existing_stats['stats']['bytes'] ) ? $existing_stats['stats']['bytes'] + $stats['stats']['bytes'] : $stats['stats']['bytes'];
|
339 |
-
$stats['stats']['percent'] = isset( $existing_stats['stats']['percent'] ) ? $existing_stats['stats']['percent'] + $stats['stats']['percent'] : $stats['stats']['percent'];
|
340 |
-
|
341 |
-
//Update stats for each size
|
342 |
-
if ( isset( $existing_stats['sizes'] ) && ! empty( $stats['sizes'] ) ) {
|
343 |
-
|
344 |
-
foreach ( $existing_stats['sizes'] as $size_name => $size_stats ) {
|
345 |
-
//if stats for a particular size doesn't exists
|
346 |
-
if ( empty( $stats['sizes'][ $size_name ] ) ) {
|
347 |
-
$stats['sizes'][ $size_name ] = $existing_stats['sizes'][ $size_name ];
|
348 |
-
} else {
|
349 |
-
//Update compression percent and bytes saved for each size
|
350 |
-
$stats['sizes'][ $size_name ]->bytes = $stats['sizes'][ $size_name ]->bytes + $existing_stats['sizes'][ $size_name ]->bytes;
|
351 |
-
$stats['sizes'][ $size_name ]->percent = $stats['sizes'][ $size_name ]->percent + $existing_stats['sizes'][ $size_name ]->percent;
|
352 |
-
}
|
353 |
-
}
|
354 |
-
}
|
355 |
-
}
|
356 |
-
update_post_meta( $ID, self::SMUSHED_META_KEY, $stats );
|
357 |
-
}
|
358 |
-
|
359 |
-
return $meta;
|
360 |
-
}
|
361 |
-
|
362 |
-
/**
|
363 |
-
* Read the image paths from an attachment's meta data and process each image
|
364 |
-
* with wp_smushit()
|
365 |
-
*
|
366 |
-
* Filters wp_generate_attachment_metadata
|
367 |
-
*
|
368 |
-
* @uses WpSmush::resize_from_meta_data
|
369 |
-
*
|
370 |
-
* @param $meta
|
371 |
-
* @param null $ID
|
372 |
-
*
|
373 |
-
* @return mixed
|
374 |
-
*/
|
375 |
-
function filter_generate_attachment_metadata( $meta, $ID = null ) {
|
376 |
-
//Update API url for Hostgator
|
377 |
-
|
378 |
-
//Check for use of http url, (Hostgator mostly)
|
379 |
-
$use_http = wp_cache_get( WP_SMUSH_PREFIX.'use_http', 'smush' );
|
380 |
-
if( !$use_http ) {
|
381 |
-
$use_http = get_option( WP_SMUSH_PREFIX.'use_http' );
|
382 |
-
wp_cache_add( WP_SMUSH_PREFIX.'use_http', $use_http, 'smush' );
|
383 |
-
}
|
384 |
-
$use_http ? define( 'WP_SMUSH_API_HTTP', 'http://smushpro.wpmudev.org/1.0/') : '';
|
385 |
-
|
386 |
-
$this->resize_from_meta_data( $meta, $ID );
|
387 |
-
|
388 |
-
return $meta;
|
389 |
-
}
|
390 |
-
|
391 |
-
|
392 |
-
/**
|
393 |
-
* Posts an image to Smush.
|
394 |
-
*
|
395 |
-
* @param $file_path path of file to send to Smush
|
396 |
-
* @param $file_size
|
397 |
-
*
|
398 |
-
* @return bool|array array containing success status, and stats
|
399 |
-
*/
|
400 |
-
function _post( $file_path, $file_size ) {
|
401 |
-
|
402 |
-
$data = false;
|
403 |
-
|
404 |
-
$file = @fopen( $file_path, 'r' );
|
405 |
-
$file_data = fread( $file, $file_size );
|
406 |
-
$headers = array(
|
407 |
-
'accept' => 'application/json', // The API returns JSON
|
408 |
-
'content-type' => 'application/binary', // Set content type to binary
|
409 |
-
);
|
410 |
-
|
411 |
-
//Check if premium member, add API key
|
412 |
-
$api_key = $this->_get_api_key();
|
413 |
-
if ( ! empty( $api_key ) ) {
|
414 |
-
$headers['apikey'] = $api_key;
|
415 |
-
}
|
416 |
-
|
417 |
-
//Check if lossy compression allowed and add it to headers
|
418 |
-
$lossy = get_option( WP_SMUSH_PREFIX . 'lossy' );
|
419 |
-
|
420 |
-
if ( $lossy && $this->is_pro() ) {
|
421 |
-
$headers['lossy'] = 'true';
|
422 |
-
} else {
|
423 |
-
$headers['lossy'] = 'false';
|
424 |
-
}
|
425 |
-
|
426 |
-
$api_url = defined( 'WP_SMUSH_API_HTTP' ) ? WP_SMUSH_API_HTTP : WP_SMUSH_API;
|
427 |
-
$args = array(
|
428 |
-
'headers' => $headers,
|
429 |
-
'body' => $file_data,
|
430 |
-
'timeout' => WP_SMUSH_TIMEOUT,
|
431 |
-
'user-agent' => WP_SMUSH_UA,
|
432 |
-
);
|
433 |
-
$result = wp_remote_post( $api_url, $args );
|
434 |
-
|
435 |
-
//Close file connection
|
436 |
-
fclose( $file );
|
437 |
-
unset( $file_data );//free memory
|
438 |
-
if ( is_wp_error( $result ) ) {
|
439 |
-
|
440 |
-
$er_msg = $result->get_error_message();
|
441 |
-
|
442 |
-
//Hostgator Issue
|
443 |
-
if ( ! empty( $er_msg ) && strpos( $er_msg, 'SSL CA cert' ) !== false ) {
|
444 |
-
//Update DB for using http protocol
|
445 |
-
update_option( WP_SMUSH_PREFIX . 'use_http', 1 );
|
446 |
-
}
|
447 |
-
//Handle error
|
448 |
-
$data['message'] = sprintf( __( 'Error posting to API: %s', 'wp-smushit' ), $result->get_error_message() );
|
449 |
-
$data['success'] = false;
|
450 |
-
unset( $result ); //free memory
|
451 |
-
return $data;
|
452 |
-
} else if ( '200' != wp_remote_retrieve_response_code( $result ) ) {
|
453 |
-
//Handle error
|
454 |
-
$data['message'] = sprintf( __( 'Error posting to API: %s %s', 'wp-smushit' ), wp_remote_retrieve_response_code( $result ), wp_remote_retrieve_response_message( $result ) );
|
455 |
-
$data['success'] = false;
|
456 |
-
unset( $result ); //free memory
|
457 |
-
|
458 |
-
return $data;
|
459 |
-
}
|
460 |
-
|
461 |
-
//If there is a response and image was successfully optimised
|
462 |
-
$response = json_decode( $result['body'] );
|
463 |
-
if ( $response && $response->success == true ) {
|
464 |
-
|
465 |
-
//If there is any savings
|
466 |
-
if ( $response->data->bytes_saved > 0 ) {
|
467 |
-
$image = base64_decode( $response->data->image ); //base64_decode is necessary to send binary img over JSON, no security problems here!
|
468 |
-
$image_md5 = md5( $response->data->image );
|
469 |
-
if ( $response->data->image_md5 != $image_md5 ) {
|
470 |
-
//Handle error
|
471 |
-
$data['message'] = __( 'Smush data corrupted, try again.', 'wp-smushit' );
|
472 |
-
$data['success'] = false;
|
473 |
-
unset( $image );//free memory
|
474 |
-
} else {
|
475 |
-
$data['success'] = true;
|
476 |
-
$data['data'] = $response->data;
|
477 |
-
$data['data']->image = $image;
|
478 |
-
unset( $image );//free memory
|
479 |
-
}
|
480 |
-
} else {
|
481 |
-
//just return the data
|
482 |
-
$data['success'] = true;
|
483 |
-
$data['data'] = $response->data;
|
484 |
-
}
|
485 |
-
} else {
|
486 |
-
//Server side error, get message from response
|
487 |
-
$data['message'] = ! empty( $response->data ) ? $response->data : __( "Image couldn't be smushed", 'wp-smushit' );
|
488 |
-
$data['success'] = false;
|
489 |
-
}
|
490 |
-
|
491 |
-
unset( $result );//free memory
|
492 |
-
unset( $response );//free memory
|
493 |
-
return $data;
|
494 |
-
}
|
495 |
-
|
496 |
-
|
497 |
-
/**
|
498 |
-
* Print column header for Smush results in the media library using
|
499 |
-
* the `manage_media_columns` hook.
|
500 |
-
*/
|
501 |
-
function columns( $defaults ) {
|
502 |
-
$defaults['smushit'] = 'WP Smush';
|
503 |
-
|
504 |
-
return $defaults;
|
505 |
-
}
|
506 |
-
|
507 |
-
/**
|
508 |
-
* Return the filesize in a humanly readable format.
|
509 |
-
* Taken from http://www.php.net/manual/en/function.filesize.php#91477
|
510 |
-
*/
|
511 |
-
function format_bytes( $bytes, $precision = 2 ) {
|
512 |
-
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
|
513 |
-
$bytes = max( $bytes, 0 );
|
514 |
-
$pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
|
515 |
-
$pow = min( $pow, count( $units ) - 1 );
|
516 |
-
$bytes /= pow( 1024, $pow );
|
517 |
-
|
518 |
-
return round( $bytes, $precision ) . ' ' . $units[ $pow ];
|
519 |
-
}
|
520 |
-
|
521 |
-
/**
|
522 |
-
* Print column data for Smush results in the media library using
|
523 |
-
* the `manage_media_custom_column` hook.
|
524 |
-
*/
|
525 |
-
function custom_column( $column_name, $id ) {
|
526 |
-
if ( 'smushit' == $column_name ) {
|
527 |
-
$this->set_status( $id );
|
528 |
-
}
|
529 |
-
}
|
530 |
-
|
531 |
-
/**
|
532 |
-
* Check if user is premium member, check for api key
|
533 |
-
*
|
534 |
-
* @return mixed|string
|
535 |
-
*/
|
536 |
-
function is_pro() {
|
537 |
-
|
538 |
-
if ( isset( $this->is_pro ) ) {
|
539 |
-
return $this->is_pro;
|
540 |
-
}
|
541 |
-
|
542 |
-
//no api key set, always false
|
543 |
-
$api_key = $this->_get_api_key();
|
544 |
-
if ( empty( $api_key ) ) {
|
545 |
-
return false;
|
546 |
-
}
|
547 |
-
|
548 |
-
$key = "wp-smush-premium-" . substr( $api_key, - 10, 10 ); //add last 10 chars of apikey to transient key in case it changes
|
549 |
-
if ( false === ( $valid = get_site_transient( $key ) ) ) {
|
550 |
-
// call api
|
551 |
-
$url = self::API_SERVER . '&key=' . urlencode( $api_key );
|
552 |
-
|
553 |
-
$request = wp_remote_get( $url, array(
|
554 |
-
"user-agent" => WP_SMUSH_UA,
|
555 |
-
"timeout" => 3
|
556 |
-
)
|
557 |
-
);
|
558 |
-
|
559 |
-
if ( ! is_wp_error( $request ) && '200' == wp_remote_retrieve_response_code( $request ) ) {
|
560 |
-
$result = json_decode( wp_remote_retrieve_body( $request ) );
|
561 |
-
if ( $result && $result->success ) {
|
562 |
-
$valid = true;
|
563 |
-
set_site_transient( $key, 1, 12 * HOUR_IN_SECONDS );
|
564 |
-
} else {
|
565 |
-
$valid = false;
|
566 |
-
set_site_transient( $key, 0, 30 * MINUTE_IN_SECONDS ); //cache failure much shorter
|
567 |
-
}
|
568 |
-
|
569 |
-
} else {
|
570 |
-
$valid = false;
|
571 |
-
set_site_transient( $key, 0, 5 * MINUTE_IN_SECONDS ); //cache network failure even shorter, we don't want a request every pageload
|
572 |
-
}
|
573 |
-
|
574 |
-
}
|
575 |
-
|
576 |
-
$this->is_pro = (bool) $valid;
|
577 |
-
|
578 |
-
return $this->is_pro;
|
579 |
-
}
|
580 |
-
|
581 |
-
/**
|
582 |
-
* Returns api key
|
583 |
-
*
|
584 |
-
* @return mixed
|
585 |
-
*/
|
586 |
-
private function _get_api_key() {
|
587 |
-
//Try to fetch it from Cache
|
588 |
-
$api_key = wp_cache_get( 'wpmudev_apikey', 'smush' );
|
589 |
-
|
590 |
-
//If not available, get it from other means, and set it in cache
|
591 |
-
if ( ! $api_key ) {
|
592 |
-
if ( defined( 'WPMUDEV_APIKEY' ) ) {
|
593 |
-
$api_key = WPMUDEV_APIKEY;
|
594 |
-
} else {
|
595 |
-
$api_key = get_site_option( 'wpmudev_apikey' );
|
596 |
-
}
|
597 |
-
if ( $api_key ) {
|
598 |
-
wp_cache_add( "wpmudev_apikey", $api_key, 'smush', 6000 );
|
599 |
-
}
|
600 |
-
}
|
601 |
-
|
602 |
-
return $api_key;
|
603 |
-
}
|
604 |
-
|
605 |
-
|
606 |
-
/**
|
607 |
-
* Checks if image is already smushed
|
608 |
-
*
|
609 |
-
* @param int $id
|
610 |
-
* @param array $data
|
611 |
-
*
|
612 |
-
* @return bool|mixed
|
613 |
-
*/
|
614 |
-
function is_smushed( $id, $data = null ) {
|
615 |
-
|
616 |
-
//For new images
|
617 |
-
$wp_is_smushed = get_post_meta( $id, 'wp-is-smushed', true );
|
618 |
-
|
619 |
-
//Not smushed, backward compatibility, check attachment metadata
|
620 |
-
if ( ! $wp_is_smushed && $data !== null ) {
|
621 |
-
if ( isset( $data['wp_smushit'] ) && ! empty( $data['wp_smushit'] ) ) {
|
622 |
-
$wp_is_smushed = true;
|
623 |
-
}
|
624 |
-
}
|
625 |
-
|
626 |
-
return $wp_is_smushed;
|
627 |
-
}
|
628 |
-
|
629 |
-
/**
|
630 |
-
* Returns size saved from the api call response
|
631 |
-
*
|
632 |
-
* @param string $message
|
633 |
-
*
|
634 |
-
* @return string|bool
|
635 |
-
*/
|
636 |
-
function get_saved_size( $message ) {
|
637 |
-
if ( preg_match( '/\((.*)\)/', $message, $matches ) ) {
|
638 |
-
return isset( $matches[1] ) ? $matches[1] : false;
|
639 |
-
}
|
640 |
-
|
641 |
-
return false;
|
642 |
-
}
|
643 |
-
|
644 |
-
/**
|
645 |
-
* Set send button status
|
646 |
-
*
|
647 |
-
* @param $id
|
648 |
-
* @param bool $echo
|
649 |
-
* @param bool $text_only
|
650 |
-
*
|
651 |
-
* @return string|void
|
652 |
-
*/
|
653 |
-
function set_status( $id, $echo = true, $text_only = false ) {
|
654 |
-
$status_txt = $button_txt = '';
|
655 |
-
$show_button = false;
|
656 |
-
|
657 |
-
//Stats are not received properly, otherwise
|
658 |
-
// wp_cache_delete( $id, 'post_meta' );
|
659 |
-
|
660 |
-
$wp_smush_data = get_post_meta( $id, self::SMUSHED_META_KEY, true );
|
661 |
-
$attachment_data = wp_get_attachment_metadata( $id );
|
662 |
-
//
|
663 |
-
// if the image is smushed
|
664 |
-
if ( ! empty( $wp_smush_data ) ) {
|
665 |
-
|
666 |
-
$image_count = count( $wp_smush_data['sizes'] );
|
667 |
-
$bytes = isset( $wp_smush_data['stats']['bytes'] ) ? $wp_smush_data['stats']['bytes'] : 0;
|
668 |
-
$bytes_readable = ! empty( $bytes ) ? $this->format_bytes( $bytes ) : '';
|
669 |
-
$percent = isset( $wp_smush_data['stats']['percent'] ) ? $wp_smush_data['stats']['percent'] : 0;
|
670 |
-
$percent = $percent < 0 ? 0 : $percent;
|
671 |
-
|
672 |
-
if ( isset( $wp_smush_data['stats']['size_before'] ) && $wp_smush_data['stats']['size_before'] == 0 ) {
|
673 |
-
$status_txt = __( 'Error processing request', 'wp-smushit' );
|
674 |
-
$show_button = true;
|
675 |
-
} else {
|
676 |
-
if ( $bytes == 0 || $percent == 0 ) {
|
677 |
-
$status_txt = __( 'Already Optimized', 'wp-smushit' );
|
678 |
-
} elseif ( ! empty( $percent ) && ! empty( $bytes_readable ) ) {
|
679 |
-
$status_txt = $image_count > 1 ? sprintf( __( "%d images reduced ", 'wp-smushit' ), $image_count ) : __( "Reduced ", 'wp-smushit' );
|
680 |
-
$status_txt .= sprintf( __( "by %s ( %01.1f%% )", 'wp-smushit' ), $bytes_readable, number_format_i18n( $percent, 2, '.', '' ) );
|
681 |
-
|
682 |
-
//Detailed Stats Link
|
683 |
-
$status_txt .= '<br /><a href="#" class="smush-stats-details">' . esc_html__( "Smush stats", 'wp-smushit' ) . ' [<span class="stats-toggle">+</span>]</a>';
|
684 |
-
|
685 |
-
//Stats
|
686 |
-
$status_txt .= $this->get_detailed_stats( $id, $wp_smush_data, $attachment_data );
|
687 |
-
}
|
688 |
-
}
|
689 |
-
|
690 |
-
//IF current compression is lossy
|
691 |
-
if ( ! empty( $wp_smush_data ) && ! empty( $wp_smush_data['stats'] ) ) {
|
692 |
-
$lossy = ! empty( $wp_smush_data['stats']['lossy'] ) ? $wp_smush_data['stats']['lossy'] : '';
|
693 |
-
$is_lossy = $lossy == 1 ? true : false;
|
694 |
-
}
|
695 |
-
|
696 |
-
//Check if Lossy enabled
|
697 |
-
$opt_lossy = WP_SMUSH_PREFIX . 'lossy';
|
698 |
-
$opt_lossy_val = get_option( $opt_lossy, false );
|
699 |
-
|
700 |
-
//Check image type
|
701 |
-
$image_type = get_post_mime_type( $id );
|
702 |
-
|
703 |
-
//Check if premium user, compression was lossless, and lossy compression is enabled
|
704 |
-
if ( $this->is_pro() && ! $is_lossy && $opt_lossy_val && $image_type != 'image/gif' ) {
|
705 |
-
// the button text
|
706 |
-
$button_txt = __( 'Super-Smush', 'wp-smushit' );
|
707 |
-
$show_button = true;
|
708 |
-
}
|
709 |
-
} else {
|
710 |
-
|
711 |
-
// the status
|
712 |
-
$status_txt = __( 'Not processed', 'wp-smushit' );
|
713 |
-
|
714 |
-
// we need to show the smush button
|
715 |
-
$show_button = true;
|
716 |
-
|
717 |
-
// the button text
|
718 |
-
$button_txt = __( 'Smush Now!', 'wp-smushit' );
|
719 |
-
}
|
720 |
-
if ( $text_only ) {
|
721 |
-
return $status_txt;
|
722 |
-
}
|
723 |
-
|
724 |
-
$text = $this->column_html( $id, $status_txt, $button_txt, $show_button, $wp_smush_data, $echo );
|
725 |
-
if ( ! $echo ) {
|
726 |
-
return $text;
|
727 |
-
}
|
728 |
-
}
|
729 |
-
|
730 |
-
/**
|
731 |
-
* Print the column html
|
732 |
-
*
|
733 |
-
* @param string $id Media id
|
734 |
-
* @param string $status_txt Status text
|
735 |
-
* @param string $button_txt Button label
|
736 |
-
* @param boolean $show_button Whether to shoe the button
|
737 |
-
*
|
738 |
-
* @return null
|
739 |
-
*/
|
740 |
-
function column_html( $id, $status_txt = "", $button_txt = "", $show_button = true, $smushed = false, $echo = true ) {
|
741 |
-
$allowed_images = array( 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' );
|
742 |
-
|
743 |
-
// don't proceed if attachment is not image, or if image is not a jpg, png or gif
|
744 |
-
if ( ! wp_attachment_is_image( $id ) || ! in_array( get_post_mime_type( $id ), $allowed_images ) ) {
|
745 |
-
return;
|
746 |
-
}
|
747 |
-
|
748 |
-
$class = $smushed ? '' : ' hidden';
|
749 |
-
$html = '
|
750 |
-
<p class="smush-status' . $class . '">' . $status_txt . '</p>';
|
751 |
-
// if we aren't showing the button
|
752 |
-
if ( ! $show_button ) {
|
753 |
-
if ( $echo ) {
|
754 |
-
echo $html;
|
755 |
-
|
756 |
-
return;
|
757 |
-
} else {
|
758 |
-
if ( ! $smushed ) {
|
759 |
-
$class = ' currently-smushing';
|
760 |
-
} else {
|
761 |
-
$class = ' smushed';
|
762 |
-
}
|
763 |
-
|
764 |
-
return '<div class="smush-wrap' . $class . '">' . $html . '</div>';
|
765 |
-
}
|
766 |
-
}
|
767 |
-
if ( ! $echo ) {
|
768 |
-
$html .= '
|
769 |
-
<button class="button button-primary wp-smush-send" data-id="' . $id . '">
|
770 |
-
<span>' . $button_txt . '</span>
|
771 |
-
</button>';
|
772 |
-
if ( ! $smushed ) {
|
773 |
-
$class = ' unsmushed';
|
774 |
-
} else {
|
775 |
-
$class = ' smushed';
|
776 |
-
}
|
777 |
-
|
778 |
-
return '<div class="smush-wrap' . $class . '">' . $html . '</div>';
|
779 |
-
} else {
|
780 |
-
$html .= '<button class="button wp-smush-send" data-id="' . $id . '">
|
781 |
-
<span>' . $button_txt . '</span>
|
782 |
-
</button>';
|
783 |
-
echo $html;
|
784 |
-
}
|
785 |
-
}
|
786 |
-
|
787 |
-
/**
|
788 |
-
* Migrates smushit api message to the latest structure
|
789 |
-
*
|
790 |
-
*
|
791 |
-
* @return void
|
792 |
-
*/
|
793 |
-
function migrate() {
|
794 |
-
|
795 |
-
if ( ! version_compare( $this->version, "1.7.1", "lte" ) ) {
|
796 |
-
return;
|
797 |
-
}
|
798 |
-
|
799 |
-
$migrated_version = get_option( self::MIGRATED_VERSION );
|
800 |
-
|
801 |
-
if ( $migrated_version === $this->version ) {
|
802 |
-
return;
|
803 |
-
}
|
804 |
-
|
805 |
-
global $wpdb;
|
806 |
-
|
807 |
-
$q = $wpdb->prepare( "SELECT * FROM `" . $wpdb->postmeta . "` WHERE `meta_key`=%s AND `meta_value` LIKE %s ", "_wp_attachment_metadata", "%wp_smushit%" );
|
808 |
-
$results = $wpdb->get_results( $q );
|
809 |
-
|
810 |
-
if ( count( $results ) < 1 ) {
|
811 |
-
return;
|
812 |
-
}
|
813 |
-
|
814 |
-
$migrator = new WpSmushMigrate();
|
815 |
-
foreach ( $results as $attachment_meta ) {
|
816 |
-
$migrated_message = $migrator->migrate_api_message( maybe_unserialize( $attachment_meta->meta_value ) );
|
817 |
-
if ( $migrated_message !== array() ) {
|
818 |
-
update_post_meta( $attachment_meta->post_id, self::SMUSHED_META_KEY, $migrated_message );
|
819 |
-
}
|
820 |
-
}
|
821 |
-
|
822 |
-
update_option( self::MIGRATED_VERSION, $this->version );
|
823 |
-
|
824 |
-
}
|
825 |
-
|
826 |
-
/**
|
827 |
-
* @param Object $response_data
|
828 |
-
* @param $size_before
|
829 |
-
* @param $size_after
|
830 |
-
* @param $total_time
|
831 |
-
* @param $bytes_saved
|
832 |
-
*
|
833 |
-
* @return array
|
834 |
-
*/
|
835 |
-
private function _update_stats_data( $response_data, $size_before, $size_after, $total_time, $bytes_saved ) {
|
836 |
-
$size_before += ! empty( $response_data->before_size ) ? (int) $response_data->before_size : 0;
|
837 |
-
$size_after += ( ! empty( $response_data->after_size ) && $response_data->after_size > 0 ) ? (int) $response_data->after_size : (int) $response_data->before_size;
|
838 |
-
$total_time += ! empty( $response_data->time ) ? (float) $response_data->time : 0;
|
839 |
-
$bytes_saved += ( ! empty( $response_data->bytes_saved ) && $response_data->bytes_saved > 0 ) ? $response_data->bytes_saved : 0;
|
840 |
-
$compression = ( $bytes_saved > 0 && $size_before > 0 ) ? ( ( $bytes_saved / $size_before ) * 100 ) : 0;
|
841 |
-
|
842 |
-
return array( $size_before, $size_after, $total_time, $compression, $bytes_saved );
|
843 |
-
}
|
844 |
-
|
845 |
-
/**
|
846 |
-
* Updates the smush stats for a single image size
|
847 |
-
* @param $id
|
848 |
-
* @param $stats
|
849 |
-
* @param $image_size
|
850 |
-
*/
|
851 |
-
function update_smush_stats_single( $id, $smush_stats, $image_size = '' ) {
|
852 |
-
//Return, if we don't have image id or stats for it
|
853 |
-
if ( empty( $id ) || empty( $smush_stats ) || empty( $image_size ) ) {
|
854 |
-
return false;
|
855 |
-
}
|
856 |
-
$image_size = $image_size . '@2x';
|
857 |
-
$data = $smush_stats['data'];
|
858 |
-
//Get existing Stats
|
859 |
-
$stats = get_post_meta( $id, self::SMUSHED_META_KEY, true );
|
860 |
-
//Update existing Stats
|
861 |
-
if ( ! empty( $stats ) ) {
|
862 |
-
//Update total bytes saved, and compression percent
|
863 |
-
//Update Main Stats
|
864 |
-
list( $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['percent'], $stats['stats']['bytes'] ) =
|
865 |
-
$this->_update_stats_data( $data, $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['bytes'] );
|
866 |
-
|
867 |
-
|
868 |
-
//Update stats for each size
|
869 |
-
if ( isset( $stats['sizes'] ) ) {
|
870 |
-
|
871 |
-
//if stats for a particular size doesn't exists
|
872 |
-
if ( empty( $stats['sizes'][ $image_size ] ) ) {
|
873 |
-
//Update size wise details
|
874 |
-
$stats['sizes'][ $image_size ] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $data );
|
875 |
-
} else {
|
876 |
-
//Update compression percent and bytes saved for each size
|
877 |
-
$stats['sizes'][ $image_size ]->bytes = $stats['sizes'][ $image_size ]->bytes + $data->bytes_saved;
|
878 |
-
$stats['sizes'][ $image_size ]->percent = $stats['sizes'][ $image_size ]->percent + $data->compression;
|
879 |
-
}
|
880 |
-
}
|
881 |
-
} else {
|
882 |
-
//Create new stats
|
883 |
-
$stats = array(
|
884 |
-
"stats" => array_merge( $this->_get_size_signature(), array(
|
885 |
-
'api_version' => - 1,
|
886 |
-
'lossy' => - 1
|
887 |
-
)
|
888 |
-
),
|
889 |
-
'sizes' => array()
|
890 |
-
);
|
891 |
-
$stats['stats']['api_version'] = $data->api_version;
|
892 |
-
$stats['stats']['lossy'] = $data->lossy;
|
893 |
-
//Update Main Stats
|
894 |
-
list( $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['percent'], $stats['stats']['bytes'] ) =
|
895 |
-
array( $data->before_size, $data->after_size, $data->time, $data->compression, $data->bytes_saved );
|
896 |
-
//Update size wise details
|
897 |
-
$stats['sizes'][ $image_size ] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $data );
|
898 |
-
}
|
899 |
-
//Calculate Percent
|
900 |
-
update_post_meta( $id, self::SMUSHED_META_KEY, $stats );
|
901 |
-
|
902 |
-
}
|
903 |
-
|
904 |
-
function smush_retina_image( $id, $retina_file, $image_size ) {
|
905 |
-
|
906 |
-
$stats = $this->do_smushit( $retina_file );
|
907 |
-
//If we squeezed out something, Update stats
|
908 |
-
if ( ! empty( $stats['data'] ) && isset( $stats['data'] ) && $stats['data']->bytes_saved > 0 ) {
|
909 |
-
$this->update_smush_stats_single( $id, $stats, $image_size );
|
910 |
-
}
|
911 |
-
}
|
912 |
-
|
913 |
-
/**
|
914 |
-
* Return a list of images not smushed and reason
|
915 |
-
* @param $image_id
|
916 |
-
* @param $size_stats
|
917 |
-
* @param $attachment_metadata
|
918 |
-
*
|
919 |
-
* @return array
|
920 |
-
*/
|
921 |
-
function get_skipped_images( $image_id, $size_stats, $attachment_metadata ) {
|
922 |
-
$skipped = array();
|
923 |
-
|
924 |
-
//Get a list of all the sizes, Show skipped images
|
925 |
-
$media_size = get_intermediate_image_sizes();
|
926 |
-
|
927 |
-
//Full size
|
928 |
-
$full_image = get_attached_file( $image_id );
|
929 |
-
|
930 |
-
//If full image was not smushed, reason 1. Large Size logic, 2. Free and greater than 1Mb
|
931 |
-
if ( ! array_key_exists( 'full', $size_stats ) ) {
|
932 |
-
//For free version, Check the image size
|
933 |
-
if ( ! $this->is_pro() ) {
|
934 |
-
//For free version, check if full size is greater than 1 Mb, show the skipped status
|
935 |
-
$file_size = filesize( $full_image );
|
936 |
-
if ( ( $file_size / WP_SMUSH_MAX_BYTES ) > 1 ) {
|
937 |
-
$skipped[] = array(
|
938 |
-
'size' => 'full',
|
939 |
-
'reason' => 'size_limit'
|
940 |
-
);
|
941 |
-
}else{
|
942 |
-
$skipped[] = array(
|
943 |
-
'size' => 'full',
|
944 |
-
'reason' => 'large_size'
|
945 |
-
);
|
946 |
-
}
|
947 |
-
} else {
|
948 |
-
//Paid version, Check if we have large size
|
949 |
-
if ( array_key_exists( 'large', $size_stats ) ) {
|
950 |
-
$skipped[] = array(
|
951 |
-
'size' => 'full',
|
952 |
-
'reason' => 'large_size'
|
953 |
-
);
|
954 |
-
}
|
955 |
-
|
956 |
-
}
|
957 |
-
}
|
958 |
-
//For other sizes, check if the image was generated and not available in stats
|
959 |
-
if ( is_array( $media_size ) ) {
|
960 |
-
foreach ( $media_size as $size ) {
|
961 |
-
if ( array_key_exists( $size, $attachment_metadata['sizes'] ) && ! array_key_exists( $size, $size_stats ) ) {
|
962 |
-
//Image Path
|
963 |
-
$img_path = trailingslashit( dirname( $full_image ) ) . $size['file'];
|
964 |
-
$image_size = filesize( $img_path );
|
965 |
-
if ( ( $image_size / WP_SMUSH_MAX_BYTES ) > 1 ) {
|
966 |
-
$skipped[] = array(
|
967 |
-
'size' => 'full',
|
968 |
-
'reason' => 'size_limit'
|
969 |
-
);
|
970 |
-
}
|
971 |
-
}
|
972 |
-
}
|
973 |
-
}
|
974 |
-
return $skipped;
|
975 |
-
}
|
976 |
-
|
977 |
-
/**
|
978 |
-
* Skip messages respective to their ids
|
979 |
-
* @param $msg_id
|
980 |
-
*
|
981 |
-
* @return bool
|
982 |
-
*/
|
983 |
-
function skip_reason( $msg_id ) {
|
984 |
-
$skip_msg = array(
|
985 |
-
'large_size' => esc_html__('Large size available for the image.', 'wp-smushit'),
|
986 |
-
'size_limit' => esc_html__('Image exceeded the 1Mb size limit.')
|
987 |
-
);
|
988 |
-
$skip_rsn = !empty( $skip_msg[$msg_id ] ) ? esc_html__(" Skipped", 'wp-smushit', 'wp-smushit'): '';
|
989 |
-
$skip_rsn = ! empty( $skip_rsn ) ? $skip_rsn . '<span class="dashicons dashicons-editor-help" title="' . $skip_msg[ $msg_id ] . '"></span>' : '';
|
990 |
-
return $skip_rsn;
|
991 |
-
}
|
992 |
-
|
993 |
-
/**
|
994 |
-
* Shows the image size and the compression for each of them
|
995 |
-
* @param $image_id
|
996 |
-
* @param $wp_smush_data
|
997 |
-
*
|
998 |
-
* @return string
|
999 |
-
*/
|
1000 |
-
function get_detailed_stats( $image_id, $wp_smush_data, $attachment_metadata ) {
|
1001 |
-
$stats = '<div id="smush-stats-' . $image_id . '" class="smush-stats-wrapper hidden">
|
1002 |
-
<table class="wp-smush-stats-holder">
|
1003 |
-
<thead>
|
1004 |
-
<tr>
|
1005 |
-
<th><strong>' . esc_html__( 'Image size', 'wp-smushit' ) . '</strong></th>
|
1006 |
-
<th><strong>' . esc_html__( 'Savings', 'wp-smushit' ) . '</strong></th>
|
1007 |
-
</tr>
|
1008 |
-
</thead>
|
1009 |
-
<tbody>';
|
1010 |
-
$size_stats = $wp_smush_data['sizes'];
|
1011 |
-
|
1012 |
-
//Reorder Sizes as per the maximum savings
|
1013 |
-
uasort( $size_stats, array( $this, "cmp" ) );
|
1014 |
-
|
1015 |
-
//Get skipped images
|
1016 |
-
$skipped = $this->get_skipped_images($image_id, $size_stats, $attachment_metadata );
|
1017 |
-
|
1018 |
-
if ( ! empty( $skipped ) ) {
|
1019 |
-
foreach ( $skipped as $img_data ) {
|
1020 |
-
$stats .= '<tr>
|
1021 |
-
<td>' . strtoupper( $img_data['size'] ) . '</td>
|
1022 |
-
<td class="smush-skipped error">' . $this->skip_reason( $img_data['reason'] ) . '</td>
|
1023 |
-
</tr>';
|
1024 |
-
}
|
1025 |
-
|
1026 |
-
}
|
1027 |
-
//Show Sizes and their compression
|
1028 |
-
foreach ( $size_stats as $size_key => $size_stats ) {
|
1029 |
-
if ( $size_stats->bytes > 0 ) {
|
1030 |
-
$stats .= '<tr>
|
1031 |
-
<td>' . strtoupper( $size_key ) . '</td>
|
1032 |
-
<td>' . $this->format_bytes( $size_stats->bytes ) . '</td>
|
1033 |
-
</tr>';
|
1034 |
-
}
|
1035 |
-
}
|
1036 |
-
$stats .= '</tbody>
|
1037 |
-
</table>
|
1038 |
-
</div>';
|
1039 |
-
|
1040 |
-
return $stats;
|
1041 |
-
}
|
1042 |
-
|
1043 |
-
/**
|
1044 |
-
* Compare Values
|
1045 |
-
* @param $a
|
1046 |
-
* @param $b
|
1047 |
-
*
|
1048 |
-
* @return int
|
1049 |
-
*/
|
1050 |
-
function cmp($a, $b) {
|
1051 |
-
return $a->bytes < $b->bytes;
|
1052 |
-
}
|
1053 |
-
}
|
1054 |
-
|
1055 |
-
global $WpSmush;
|
1056 |
-
$WpSmush = new WpSmush();
|
1057 |
-
|
1058 |
-
}
|
1059 |
-
|
1060 |
-
//Include Admin classes
|
1061 |
-
require_once( WP_SMUSH_DIR . 'lib/class-wp-smush-bulk.php' );
|
1062 |
-
require_once( WP_SMUSH_DIR . 'lib/class-wp-smush-admin.php' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
=== WP Smush ===
|
2 |
Plugin Name: WP Smush
|
3 |
-
Version: 2.0.6.
|
4 |
Author: WPMU DEV
|
5 |
Author URI: http://premium.wpmudev.org/
|
6 |
Contributors: WPMUDEV, alexdunae
|
7 |
Tags: Attachment,Attachments,Compress,Compress Image File,Compress Image Size,Compress JPG,Compressed JPG, Compression Image,Image,Images,JPG,Optimise,Optimize,Photo,Photos,Pictures,PNG,Reduce Image Size,Smush,Smush.it,Upload,WordPress Compression,WordPress Image Tool,Yahoo, Yahoo Smush.it
|
8 |
Requires at least: 3.5
|
9 |
Tested up to: 4.3
|
10 |
-
Stable tag: 2.0.6.
|
11 |
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
12 |
|
13 |
Reduce image file sizes, improve performance and boost your SEO using the free <a href="https://premium.wpmudev.org/">WPMU DEV</a> WordPress Smush API.
|
@@ -81,18 +81,6 @@ Yahoo's Smush.it API is gone forever. So WPMU DEV built our own free API that is
|
|
81 |
|
82 |
== Changelog ==
|
83 |
|
84 |
-
= 2.0.6.3 =
|
85 |
-
|
86 |
-
* Fixed: Change File permission after replacing image
|
87 |
-
* Fixed: Directory path for files
|
88 |
-
* Fixed: Workaround for Auto Smush issue on Hostgator
|
89 |
-
* Fixed: Smush button doesn't works in media library dialog on post screen, when add media is clicked
|
90 |
-
(https://wordpress.org/support/topic/like-wp-smush-a-lot)
|
91 |
-
* New: Show number of images smushed in stats column
|
92 |
-
* Added: Support for WP Retina 2x Plugin
|
93 |
-
* Added: Filter `WP_SMUSH_API_TIMEOUT` to change the default time out value from 60s
|
94 |
-
* Added: Smush original image option (Pro Only)
|
95 |
-
|
96 |
= 2.0.6.2 =
|
97 |
|
98 |
* Use string for text domain instead of PHP Constant ( WordPress Guideline )
|
1 |
=== WP Smush ===
|
2 |
Plugin Name: WP Smush
|
3 |
+
Version: 2.0.6.2
|
4 |
Author: WPMU DEV
|
5 |
Author URI: http://premium.wpmudev.org/
|
6 |
Contributors: WPMUDEV, alexdunae
|
7 |
Tags: Attachment,Attachments,Compress,Compress Image File,Compress Image Size,Compress JPG,Compressed JPG, Compression Image,Image,Images,JPG,Optimise,Optimize,Photo,Photos,Pictures,PNG,Reduce Image Size,Smush,Smush.it,Upload,WordPress Compression,WordPress Image Tool,Yahoo, Yahoo Smush.it
|
8 |
Requires at least: 3.5
|
9 |
Tested up to: 4.3
|
10 |
+
Stable tag: 2.0.6.2
|
11 |
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
12 |
|
13 |
Reduce image file sizes, improve performance and boost your SEO using the free <a href="https://premium.wpmudev.org/">WPMU DEV</a> WordPress Smush API.
|
81 |
|
82 |
== Changelog ==
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
= 2.0.6.2 =
|
85 |
|
86 |
* Use string for text domain instead of PHP Constant ( WordPress Guideline )
|
wp-smush.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WP Smush
|
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/wp-smushit/
|
5 |
Description: Reduce image file sizes, improve performance and boost your SEO using the free <a href="https://premium.wpmudev.org/">WPMU DEV</a> WordPress Smush API.
|
6 |
Author: WPMU DEV
|
7 |
-
Version: 2.0.6.
|
8 |
Author URI: http://premium.wpmudev.org/
|
9 |
Textdomain: wp-smushit
|
10 |
*/
|
@@ -36,15 +36,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
36 |
* Constants
|
37 |
*/
|
38 |
$prefix = 'WP_SMUSH_';
|
39 |
-
$version = '2.0.6.
|
40 |
-
|
41 |
-
|
42 |
-
* Set the default timeout for API request and AJAX timeout
|
43 |
-
*/
|
44 |
-
$timeout = apply_filters( 'WP_SMUSH_API_TIMEOUT', 60 );
|
45 |
-
|
46 |
-
$smush_constants = array(
|
47 |
-
'VERSION' => $version,
|
48 |
'BASENAME' => plugin_basename( __FILE__ ),
|
49 |
'API' => 'https://smushpro.wpmudev.org/1.0/',
|
50 |
'UA' => 'WP Smush/' . $version . '; ' . network_home_url(),
|
@@ -53,94 +47,870 @@ $smush_constants = array(
|
|
53 |
'MAX_BYTES' => 1000000,
|
54 |
'PREMIUM_MAX_BYTES' => 32000000,
|
55 |
'PREFIX' => 'wp-smush-',
|
56 |
-
'TIMEOUT' =>
|
|
|
57 |
);
|
58 |
|
59 |
-
foreach ( $
|
60 |
if ( ! defined( $prefix . $const_name ) ) {
|
61 |
define( $prefix . $const_name, $constant_val );
|
62 |
}
|
63 |
}
|
64 |
-
//Include main class
|
65 |
-
require_once WP_SMUSH_DIR . 'lib/class-wp-smush.php';
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
if (
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
// Register the current plugin.
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
/* 4 Email Button CTA */
|
82 |
-
__( 'Get Fast', 'wp-smushit' ),
|
83 |
-
/* 5 getdrip Plugin param */
|
84 |
-
'Smush'
|
85 |
-
);
|
86 |
|
87 |
// The rating message contains 2 variables: user-name, plugin-name
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
$show_stats = true;
|
109 |
-
}
|
110 |
-
|
111 |
-
$message = "Hey %s, you've been using %s for a while now, and we hope you're happy with it.";
|
112 |
-
|
113 |
-
//Conditionally Show stats in rating message
|
114 |
-
if ( $show_stats ) {
|
115 |
-
$message .= sprintf( " You've smushed <strong>%s</strong> from %d images already, improving the speed and SEO ranking of this site!", $savings['human'], $image_count );
|
116 |
-
}
|
117 |
-
$message .= " We've spent countless hours developing this free plugin for you, and we would really appreciate it if you dropped us a quick rating!";
|
118 |
-
|
119 |
-
return $message;
|
120 |
}
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
function wp_smush_email_message( $message ) {
|
128 |
-
$message = "You're awesome for installing %s! Site speed isn't all image optimization though, so we've collected all the best speed resources we know in a single email - just for users of WP Smush!";
|
129 |
-
|
130 |
-
return $message;
|
131 |
}
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/wp-smushit/
|
5 |
Description: Reduce image file sizes, improve performance and boost your SEO using the free <a href="https://premium.wpmudev.org/">WPMU DEV</a> WordPress Smush API.
|
6 |
Author: WPMU DEV
|
7 |
+
Version: 2.0.6.2
|
8 |
Author URI: http://premium.wpmudev.org/
|
9 |
Textdomain: wp-smushit
|
10 |
*/
|
36 |
* Constants
|
37 |
*/
|
38 |
$prefix = 'WP_SMUSH_';
|
39 |
+
$version = '2.0.6.1';
|
40 |
+
$smush_constatns = array(
|
41 |
+
'VERSON' => $version,
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
'BASENAME' => plugin_basename( __FILE__ ),
|
43 |
'API' => 'https://smushpro.wpmudev.org/1.0/',
|
44 |
'UA' => 'WP Smush/' . $version . '; ' . network_home_url(),
|
47 |
'MAX_BYTES' => 1000000,
|
48 |
'PREMIUM_MAX_BYTES' => 32000000,
|
49 |
'PREFIX' => 'wp-smush-',
|
50 |
+
'TIMEOUT' => 30
|
51 |
+
|
52 |
);
|
53 |
|
54 |
+
foreach ( $smush_constatns as $const_name => $constant_val ) {
|
55 |
if ( ! defined( $prefix . $const_name ) ) {
|
56 |
define( $prefix . $const_name, $constant_val );
|
57 |
}
|
58 |
}
|
|
|
|
|
59 |
|
60 |
+
require_once WP_SMUSH_DIR . "lib/class-wp-smush-migrate.php";
|
61 |
+
|
62 |
+
if ( ! class_exists( 'WpSmush' ) ) {
|
63 |
+
|
64 |
+
class WpSmush {
|
65 |
+
|
66 |
+
var $version = WP_SMUSH_VERSON;
|
67 |
+
|
68 |
+
var $is_pro;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Meta key for api validity
|
72 |
+
*
|
73 |
+
*/
|
74 |
+
const VALIDITY_KEY = "wp-smush-valid";
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Api server url to check api key validity
|
78 |
+
*
|
79 |
+
*/
|
80 |
+
const API_SERVER = 'https://premium.wpmudev.org/wdp-un.php?action=smushit_check';
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Meta key to save smush result to db
|
84 |
+
*
|
85 |
+
*
|
86 |
+
*/
|
87 |
+
const SMUSHED_META_KEY = 'wp-smpro-smush-data';
|
88 |
+
|
89 |
+
/**
|
90 |
+
* Meta key to save migrated version
|
91 |
+
*
|
92 |
+
*/
|
93 |
+
const MIGRATED_VERSION = "wp-smush-migrated-version";
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Constructor
|
97 |
+
*/
|
98 |
+
function __construct() {
|
99 |
+
/**
|
100 |
+
* Hooks
|
101 |
+
*/
|
102 |
+
//Check if auto is enabled
|
103 |
+
$auto_smush = get_option( WP_SMUSH_PREFIX . 'auto' );
|
104 |
+
|
105 |
+
//Keep the uto smush on by default
|
106 |
+
if ( $auto_smush === false ) {
|
107 |
+
$auto_smush = 1;
|
108 |
+
}
|
109 |
+
|
110 |
+
if ( $auto_smush ) {
|
111 |
+
add_filter( 'wp_generate_attachment_metadata', array(
|
112 |
+
$this,
|
113 |
+
'filter_generate_attachment_metadata'
|
114 |
+
), 10, 2 );
|
115 |
+
}
|
116 |
+
add_filter( 'manage_media_columns', array( $this, 'columns' ) );
|
117 |
+
add_action( 'manage_media_custom_column', array( $this, 'custom_column' ), 10, 2 );
|
118 |
+
add_action( 'admin_init', array( $this, 'admin_init' ) );
|
119 |
+
add_action( "admin_init", array( $this, "migrate" ) );
|
120 |
+
|
121 |
+
}
|
122 |
+
|
123 |
+
function admin_init() {
|
124 |
+
load_plugin_textdomain( 'wp-smushit', false, dirname( WP_SMUSH_BASENAME ) . '/languages/' );
|
125 |
+
wp_enqueue_script( 'common' );
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Process an image with Smush.
|
130 |
+
*
|
131 |
+
* Returns an array of the $file $results.
|
132 |
+
*
|
133 |
+
* @param string $file Full absolute path to the image file
|
134 |
+
* @param string $file_url Optional full URL to the image file
|
135 |
+
*
|
136 |
+
* @returns array
|
137 |
+
*/
|
138 |
+
function do_smushit( $file_path = '', $file_url = '' ) {
|
139 |
+
$errors = new WP_Error();
|
140 |
+
if ( empty( $file_path ) ) {
|
141 |
+
$errors->add( "empty_path", __( "File path is empty", 'wp-smushit' ) );
|
142 |
+
}
|
143 |
+
|
144 |
+
if ( empty( $file_url ) ) {
|
145 |
+
$errors->add( "empty_url", __( "File URL is empty", 'wp-smushit' ) );
|
146 |
+
}
|
147 |
+
|
148 |
+
// check that the file exists
|
149 |
+
if ( ! file_exists( $file_path ) || ! is_file( $file_path ) ) {
|
150 |
+
$errors->add( "file_not_found", sprintf( __( "Could not find %s", 'wp-smushit' ), $file_path ) );
|
151 |
+
}
|
152 |
+
|
153 |
+
// check that the file is writable
|
154 |
+
if ( ! is_writable( dirname( $file_path ) ) ) {
|
155 |
+
$errors->add( "not_writable", sprintf( __( "%s is not writable", 'wp-smushit' ), dirname( $file_path ) ) );
|
156 |
+
}
|
157 |
+
|
158 |
+
$file_size = file_exists( $file_path ) ? filesize( $file_path ) : 0;
|
159 |
+
|
160 |
+
//Check if premium user
|
161 |
+
$max_size = $this->is_pro() ? WP_SMUSH_PREMIUM_MAX_BYTES : WP_SMUSH_MAX_BYTES;
|
162 |
+
|
163 |
+
//Check if file exists
|
164 |
+
if ( $file_size == 0 ) {
|
165 |
+
$errors->add( "image_not_found", sprintf( __( 'Skipped (%s), image not found.', 'wp-smushit' ), $this->format_bytes( $file_size ) ) );
|
166 |
+
}
|
167 |
+
|
168 |
+
//Check size limit
|
169 |
+
if ( $file_size > $max_size ) {
|
170 |
+
$errors->add( "size_limit", sprintf( __( 'Skipped (%s), size limit exceeded.', 'wp-smushit' ), $this->format_bytes( $file_size ) ) );
|
171 |
+
}
|
172 |
+
|
173 |
+
if ( count( $errors->get_error_messages() ) ) {
|
174 |
+
return $errors;
|
175 |
+
}
|
176 |
+
|
177 |
+
/** Send image for smushing, and fetch the response */
|
178 |
+
$response = $this->_post( $file_path, $file_size );
|
179 |
+
|
180 |
+
if ( ! $response['success'] ) {
|
181 |
+
$errors->add( "false_response", $response['message'] );
|
182 |
+
}
|
183 |
+
//If there is no data
|
184 |
+
if ( empty( $response['data'] ) ) {
|
185 |
+
$errors->add( "no_data", __( 'Unknown API error', 'wp-smushit' ) );
|
186 |
+
}
|
187 |
+
|
188 |
+
if ( count( $errors->get_error_messages() ) ) {
|
189 |
+
return $errors;
|
190 |
+
}
|
191 |
+
|
192 |
+
//If there are no savings, or image returned is bigger in size
|
193 |
+
if ( ( ! empty( $response['data']->bytes_saved ) && intval( $response['data']->bytes_saved ) <= 0 )
|
194 |
+
|| empty( $response['data']->image )
|
195 |
+
) {
|
196 |
+
return $response;
|
197 |
+
}
|
198 |
+
$tempfile = $file_path . ".tmp";
|
199 |
+
|
200 |
+
//Add the file as tmp
|
201 |
+
file_put_contents( $tempfile, $response['data']->image );
|
202 |
+
|
203 |
+
//handle backups if enabled
|
204 |
+
$backup = get_option( WP_SMUSH_PREFIX . 'backup' );
|
205 |
+
if ( $backup && $this->is_pro() ) {
|
206 |
+
$path = pathinfo( $file_path );
|
207 |
+
$backup_name = trailingslashit( $path['dirname'] ) . $path['filename'] . ".bak." . $path['extension'];
|
208 |
+
@copy( $file_path, $backup_name );
|
209 |
+
}
|
210 |
+
|
211 |
+
//replace the file
|
212 |
+
$success = @rename( $tempfile, $file_path );
|
213 |
+
|
214 |
+
//if tempfile still exists, unlink it
|
215 |
+
if ( file_exists( $tempfile ) ) {
|
216 |
+
unlink( $tempfile );
|
217 |
+
}
|
218 |
+
|
219 |
+
//If file renaming was successful
|
220 |
+
if ( ! $success ) {
|
221 |
+
copy( $tempfile, $file_path );
|
222 |
+
unlink( $tempfile );
|
223 |
+
}
|
224 |
+
|
225 |
+
return $response;
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Fills $placeholder array with values from $data array
|
230 |
+
*
|
231 |
+
* @param array $placeholders
|
232 |
+
* @param array $data
|
233 |
+
*
|
234 |
+
* @return array
|
235 |
+
*/
|
236 |
+
private function _array_fill_placeholders( array $placeholders, array $data ) {
|
237 |
+
$placeholders['percent'] = $data['compression'];
|
238 |
+
$placeholders['bytes'] = $data['bytes_saved'];
|
239 |
+
$placeholders['size_before'] = $data['before_size'];
|
240 |
+
$placeholders['size_after'] = $data['after_size'];
|
241 |
+
$placeholders['time'] = $data['time'];
|
242 |
+
|
243 |
+
return $placeholders;
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Returns signature for single size of the smush api message to be saved to db;
|
248 |
+
*
|
249 |
+
* @return array
|
250 |
+
*/
|
251 |
+
private function _get_size_signature() {
|
252 |
+
return array(
|
253 |
+
'percent' => - 1,
|
254 |
+
'bytes' => - 1,
|
255 |
+
'size_before' => - 1,
|
256 |
+
'size_after' => - 1,
|
257 |
+
'time' => - 1
|
258 |
+
);
|
259 |
+
}
|
260 |
+
|
261 |
+
/**
|
262 |
+
* Read the image paths from an attachment's meta data and process each image
|
263 |
+
* with wp_smushit().
|
264 |
+
*
|
265 |
+
* This method also adds a `wp_smushit` meta key for use in the media library.
|
266 |
+
* Called after `wp_generate_attachment_metadata` is completed.
|
267 |
+
*
|
268 |
+
* @param $meta
|
269 |
+
* @param null $ID
|
270 |
+
*
|
271 |
+
* @return mixed
|
272 |
+
*/
|
273 |
+
function resize_from_meta_data( $meta, $ID = null ) {
|
274 |
+
|
275 |
+
//Flag to check, if original size image needs to be smushed or not
|
276 |
+
$smush_full = true;
|
277 |
+
$errors = new WP_Error();
|
278 |
+
$stats = array(
|
279 |
+
"stats" => array_merge( $this->_get_size_signature(), array(
|
280 |
+
'api_version' => - 1,
|
281 |
+
'lossy' => - 1
|
282 |
+
)
|
283 |
+
),
|
284 |
+
'sizes' => array()
|
285 |
+
);
|
286 |
+
|
287 |
+
$size_before = $size_after = $compression = $total_time = $bytes_saved = 0;
|
288 |
+
|
289 |
+
if ( $ID && wp_attachment_is_image( $ID ) === false ) {
|
290 |
+
return $meta;
|
291 |
+
}
|
292 |
+
|
293 |
+
//File path and URL for original image
|
294 |
+
$attachment_file_path = get_attached_file( $ID );
|
295 |
+
$attachment_file_url = wp_get_attachment_url( $ID );
|
296 |
+
|
297 |
+
// If images has other registered size, smush them first
|
298 |
+
if ( ! empty( $meta['sizes'] ) ) {
|
299 |
+
|
300 |
+
foreach ( $meta['sizes'] as $size_key => $size_data ) {
|
301 |
+
|
302 |
+
//if there is a large size, then we will set a flag to leave the original untouched
|
303 |
+
if ( $size_key == 'large' ) {
|
304 |
+
$smush_full = false;
|
305 |
+
}
|
306 |
+
|
307 |
+
// We take the original image. The 'sizes' will all match the same URL and
|
308 |
+
// path. So just get the dirname and replace the filename.
|
309 |
+
|
310 |
+
$attachment_file_path_size = trailingslashit( dirname( $attachment_file_path ) ) . $size_data['file'];
|
311 |
+
$attachment_file_url_size = trailingslashit( dirname( $attachment_file_url ) ) . $size_data['file'];
|
312 |
+
|
313 |
+
//Store details for each size key
|
314 |
+
$response = $this->do_smushit( $attachment_file_path_size, $attachment_file_url_size );
|
315 |
+
|
316 |
+
if ( is_wp_error( $response ) ) {
|
317 |
+
return $response;
|
318 |
+
}
|
319 |
+
|
320 |
+
if ( ! empty( $response['data'] ) ) {
|
321 |
+
$stats['sizes'][ $size_key ] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $response['data'] );
|
322 |
+
}
|
323 |
+
|
324 |
+
//Total Stats, store all data in bytes
|
325 |
+
if ( isset( $response['data'] ) ) {
|
326 |
+
list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
|
327 |
+
= $this->_update_stats_data( $response['data'], $size_before, $size_after, $total_time, $bytes_saved );
|
328 |
+
} else {
|
329 |
+
$errors->add( "image_size_error" . $size_key, sprintf( __( "Size '%s' not processed correctly", 'wp-smushit' ), $size_key ) );
|
330 |
+
}
|
331 |
+
|
332 |
+
if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
|
333 |
+
$stats['stats']['api_version'] = $response['data']->api_version;
|
334 |
+
$stats['stats']['lossy'] = $response['data']->lossy;
|
335 |
+
}
|
336 |
+
}
|
337 |
+
}
|
338 |
+
|
339 |
+
//If original size is supposed to be smushed
|
340 |
+
if ( $smush_full ) {
|
341 |
+
|
342 |
+
$full_image_response = $this->do_smushit( $attachment_file_path, $attachment_file_url );
|
343 |
+
|
344 |
+
if ( is_wp_error( $full_image_response ) ) {
|
345 |
+
return $full_image_response;
|
346 |
+
}
|
347 |
+
|
348 |
+
if ( ! empty( $full_image_response['data'] ) ) {
|
349 |
+
$stats['sizes']['full'] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $full_image_response['data'] );
|
350 |
+
} else {
|
351 |
+
$errors->add( "image_size_error", __( "Size 'full' not processed correctly", 'wp-smushit' ) );
|
352 |
+
}
|
353 |
+
|
354 |
+
//Update stats
|
355 |
+
if ( isset( $full_image_response['data'] ) ) {
|
356 |
+
list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
|
357 |
+
= $this->_update_stats_data( $full_image_response['data'], $size_before, $size_after, $total_time, $bytes_saved );
|
358 |
+
} else {
|
359 |
+
$errors->add( "image_size_error", __( "Size 'full' not processed correctly", 'wp-smushit' ) );
|
360 |
+
}
|
361 |
+
|
362 |
+
//Api version and lossy, for some images, full image i skipped and for other images only full exists
|
363 |
+
//so have to add code again
|
364 |
+
if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
|
365 |
+
$stats['stats']['api_version'] = $full_image_response['data']->api_version;
|
366 |
+
$stats['stats']['lossy'] = $full_image_response['data']->lossy;
|
367 |
+
}
|
368 |
+
|
369 |
+
|
370 |
+
}
|
371 |
+
|
372 |
+
$has_errors = (bool) count( $errors->get_error_messages() );
|
373 |
+
|
374 |
+
list( $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['percent'], $stats['stats']['bytes'] ) =
|
375 |
+
array( $size_before, $size_after, $total_time, $compression, $bytes_saved );
|
376 |
+
|
377 |
+
//Set smush status for all the images, store it in wp-smpro-smush-data
|
378 |
+
if ( ! $has_errors ) {
|
379 |
+
|
380 |
+
$existing_stats = get_post_meta( $ID, self::SMUSHED_META_KEY, true );
|
381 |
+
|
382 |
+
if ( ! empty( $existing_stats ) ) {
|
383 |
+
//Update total bytes saved, and compression percent
|
384 |
+
$stats['stats']['bytes'] = isset( $existing_stats['stats']['bytes'] ) ? $existing_stats['stats']['bytes'] + $stats['stats']['bytes'] : $stats['stats']['bytes'];
|
385 |
+
$stats['stats']['percent'] = isset( $existing_stats['stats']['percent'] ) ? $existing_stats['stats']['percent'] + $stats['stats']['percent'] : $stats['stats']['percent'];
|
386 |
+
|
387 |
+
//Update stats for each size
|
388 |
+
if ( ! empty( $existing_stats['sizes'] ) && ! empty( $stats['sizes'] ) ) {
|
389 |
+
|
390 |
+
foreach ( $existing_stats['sizes'] as $size_name => $size_stats ) {
|
391 |
+
//if stats for a particular size doesn't exists
|
392 |
+
if ( empty( $stats['sizes'][$size_name] ) ) {
|
393 |
+
$stats['sizes'][$size_name] = $existing_stats['sizes'][$size_name];
|
394 |
+
} else {
|
395 |
+
//Update compression percent and bytes saved for each size
|
396 |
+
$stats['sizes'][$size_name]->bytes = $stats['sizes'][$size_name]->bytes + $existing_stats['sizes'][$size_name]->bytes;
|
397 |
+
$stats['sizes'][$size_name]->percent = $stats['sizes'][$size_name]->percent + $existing_stats['sizes'][$size_name]->percent;
|
398 |
+
}
|
399 |
+
}
|
400 |
+
}
|
401 |
+
}
|
402 |
+
update_post_meta( $ID, self::SMUSHED_META_KEY, $stats );
|
403 |
+
}
|
404 |
+
|
405 |
+
return $meta;
|
406 |
+
}
|
407 |
+
|
408 |
+
/**
|
409 |
+
* Read the image paths from an attachment's meta data and process each image
|
410 |
+
* with wp_smushit()
|
411 |
+
*
|
412 |
+
* Filters wp_generate_attachment_metadata
|
413 |
+
*
|
414 |
+
* @uses WpSmush::resize_from_meta_data
|
415 |
+
*
|
416 |
+
* @param $meta
|
417 |
+
* @param null $ID
|
418 |
+
*
|
419 |
+
* @return mixed
|
420 |
+
*/
|
421 |
+
function filter_generate_attachment_metadata( $meta, $ID = null ) {
|
422 |
+
$this->resize_from_meta_data( $meta, $ID );
|
423 |
+
|
424 |
+
return $meta;
|
425 |
+
}
|
426 |
+
|
427 |
+
|
428 |
+
/**
|
429 |
+
* Posts an image to Smush.
|
430 |
+
*
|
431 |
+
* @param $file_path path of file to send to Smush
|
432 |
+
* @param $file_size
|
433 |
+
*
|
434 |
+
* @return bool|array array containing success status, and stats
|
435 |
+
*/
|
436 |
+
function _post( $file_path, $file_size ) {
|
437 |
+
|
438 |
+
$data = false;
|
439 |
+
|
440 |
+
$file = @fopen( $file_path, 'r' );
|
441 |
+
$file_data = fread( $file, $file_size );
|
442 |
+
$headers = array(
|
443 |
+
'accept' => 'application/json', // The API returns JSON
|
444 |
+
'content-type' => 'application/binary', // Set content type to binary
|
445 |
+
);
|
446 |
+
|
447 |
+
//Check if premium member, add API key
|
448 |
+
$api_key = $this->_get_api_key();
|
449 |
+
if ( ! empty( $api_key ) ) {
|
450 |
+
$headers['apikey'] = $api_key;
|
451 |
+
}
|
452 |
+
|
453 |
+
//Check if lossy compression allowed and add it to headers
|
454 |
+
$lossy = get_option( WP_SMUSH_PREFIX . 'lossy' );
|
455 |
+
|
456 |
+
if ( $lossy && $this->is_pro() ) {
|
457 |
+
$headers['lossy'] = 'true';
|
458 |
+
} else {
|
459 |
+
$headers['lossy'] = 'false';
|
460 |
+
}
|
461 |
+
|
462 |
+
$args = array(
|
463 |
+
'headers' => $headers,
|
464 |
+
'body' => $file_data,
|
465 |
+
'timeout' => WP_SMUSH_TIMEOUT,
|
466 |
+
'user-agent' => WP_SMUSH_UA
|
467 |
+
);
|
468 |
+
$result = wp_remote_post( WP_SMUSH_API, $args );
|
469 |
+
|
470 |
+
//Close file connection
|
471 |
+
fclose( $file );
|
472 |
+
unset( $file_data );//free memory
|
473 |
+
if ( is_wp_error( $result ) ) {
|
474 |
+
//Handle error
|
475 |
+
$data['message'] = sprintf( __( 'Error posting to API: %s', 'wp-smushit' ), $result->get_error_message() );
|
476 |
+
$data['success'] = false;
|
477 |
+
unset( $result ); //free memory
|
478 |
+
return $data;
|
479 |
+
} else if ( '200' != wp_remote_retrieve_response_code( $result ) ) {
|
480 |
+
//Handle error
|
481 |
+
$data['message'] = sprintf( __( 'Error posting to API: %s %s', 'wp-smushit' ), wp_remote_retrieve_response_code( $result ), wp_remote_retrieve_response_message( $result ) );
|
482 |
+
$data['success'] = false;
|
483 |
+
unset( $result ); //free memory
|
484 |
+
|
485 |
+
return $data;
|
486 |
+
}
|
487 |
+
|
488 |
+
//If there is a response and image was successfully optimised
|
489 |
+
$response = json_decode( $result['body'] );
|
490 |
+
if ( $response && $response->success == true ) {
|
491 |
+
|
492 |
+
//If there is any savings
|
493 |
+
if ( $response->data->bytes_saved > 0 ) {
|
494 |
+
$image = base64_decode( $response->data->image ); //base64_decode is necessary to send binary img over JSON, no security problems here!
|
495 |
+
$image_md5 = md5( $response->data->image );
|
496 |
+
if ( $response->data->image_md5 != $image_md5 ) {
|
497 |
+
//Handle error
|
498 |
+
$data['message'] = __( 'Smush data corrupted, try again.', 'wp-smushit' );
|
499 |
+
$data['success'] = false;
|
500 |
+
unset( $image );//free memory
|
501 |
+
} else {
|
502 |
+
$data['success'] = true;
|
503 |
+
$data['data'] = $response->data;
|
504 |
+
$data['data']->image = $image;
|
505 |
+
unset( $image );//free memory
|
506 |
+
}
|
507 |
+
} else {
|
508 |
+
//just return the data
|
509 |
+
$data['success'] = true;
|
510 |
+
$data['data'] = $response->data;
|
511 |
+
}
|
512 |
+
} else {
|
513 |
+
//Server side error, get message from response
|
514 |
+
$data['message'] = ! empty( $response->data ) ? $response->data : __( "Image couldn't be smushed", 'wp-smushit' );
|
515 |
+
$data['success'] = false;
|
516 |
+
}
|
517 |
+
|
518 |
+
unset( $result );//free memory
|
519 |
+
unset( $response );//free memory
|
520 |
+
return $data;
|
521 |
+
}
|
522 |
+
|
523 |
+
|
524 |
+
/**
|
525 |
+
* Print column header for Smush results in the media library using
|
526 |
+
* the `manage_media_columns` hook.
|
527 |
+
*/
|
528 |
+
function columns( $defaults ) {
|
529 |
+
$defaults['smushit'] = 'WP Smush';
|
530 |
+
|
531 |
+
return $defaults;
|
532 |
+
}
|
533 |
+
|
534 |
+
/**
|
535 |
+
* Return the filesize in a humanly readable format.
|
536 |
+
* Taken from http://www.php.net/manual/en/function.filesize.php#91477
|
537 |
+
*/
|
538 |
+
function format_bytes( $bytes, $precision = 2 ) {
|
539 |
+
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
|
540 |
+
$bytes = max( $bytes, 0 );
|
541 |
+
$pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
|
542 |
+
$pow = min( $pow, count( $units ) - 1 );
|
543 |
+
$bytes /= pow( 1024, $pow );
|
544 |
+
|
545 |
+
return round( $bytes, $precision ) . ' ' . $units[ $pow ];
|
546 |
+
}
|
547 |
+
|
548 |
+
/**
|
549 |
+
* Print column data for Smush results in the media library using
|
550 |
+
* the `manage_media_custom_column` hook.
|
551 |
+
*/
|
552 |
+
function custom_column( $column_name, $id ) {
|
553 |
+
if ( 'smushit' == $column_name ) {
|
554 |
+
$this->set_status( $id );
|
555 |
+
}
|
556 |
+
}
|
557 |
+
|
558 |
+
/**
|
559 |
+
* Check if user is premium member, check for api key
|
560 |
+
*
|
561 |
+
* @return mixed|string
|
562 |
+
*/
|
563 |
+
function is_pro() {
|
564 |
+
|
565 |
+
if ( isset( $this->is_pro ) ) return $this->is_pro;
|
566 |
+
|
567 |
+
//no api key set, always false
|
568 |
+
$api_key = $this->_get_api_key();
|
569 |
+
if ( empty( $api_key ) ) {
|
570 |
+
return false;
|
571 |
+
}
|
572 |
+
|
573 |
+
$key = "wp-smush-premium-" . substr( $api_key, -10, 10); //add last 10 chars of apikey to transient key in case it changes
|
574 |
+
if ( false === ( $valid = get_site_transient( $key ) ) ) {
|
575 |
+
// call api
|
576 |
+
$url = self::API_SERVER . '&key=' . urlencode( $api_key );
|
577 |
+
|
578 |
+
$request = wp_remote_get( $url, array(
|
579 |
+
"user-agent" => WP_SMUSH_UA,
|
580 |
+
"timeout" => 3
|
581 |
+
)
|
582 |
+
);
|
583 |
+
|
584 |
+
if ( ! is_wp_error( $request ) && '200' == wp_remote_retrieve_response_code( $request ) ) {
|
585 |
+
$result = json_decode( wp_remote_retrieve_body( $request ) );
|
586 |
+
if ( $result && $result->success ) {
|
587 |
+
$valid = true;
|
588 |
+
set_site_transient( $key, 1, 12 * HOUR_IN_SECONDS );
|
589 |
+
} else {
|
590 |
+
$valid = false;
|
591 |
+
set_site_transient( $key, 0, 30 * MINUTE_IN_SECONDS ); //cache failure much shorter
|
592 |
+
}
|
593 |
+
|
594 |
+
} else {
|
595 |
+
$valid = false;
|
596 |
+
set_site_transient( $key, 0, 5 * MINUTE_IN_SECONDS ); //cache network failure even shorter, we don't want a request every pageload
|
597 |
+
}
|
598 |
+
|
599 |
+
}
|
600 |
+
|
601 |
+
$this->is_pro = (bool) $valid;
|
602 |
+
return $this->is_pro;
|
603 |
+
}
|
604 |
+
|
605 |
+
/**
|
606 |
+
* Returns api key
|
607 |
+
*
|
608 |
+
* @return mixed
|
609 |
+
*/
|
610 |
+
private function _get_api_key() {
|
611 |
+
if ( defined( 'WPMUDEV_APIKEY' ) ) {
|
612 |
+
$api_key = WPMUDEV_APIKEY;
|
613 |
+
} else {
|
614 |
+
$api_key = get_site_option( 'wpmudev_apikey' );
|
615 |
+
}
|
616 |
+
|
617 |
+
return $api_key;
|
618 |
+
}
|
619 |
+
|
620 |
+
|
621 |
+
/**
|
622 |
+
* Checks if image is already smushed
|
623 |
+
*
|
624 |
+
* @param int $id
|
625 |
+
* @param array $data
|
626 |
+
*
|
627 |
+
* @return bool|mixed
|
628 |
+
*/
|
629 |
+
function is_smushed( $id, $data = null ) {
|
630 |
+
|
631 |
+
//For new images
|
632 |
+
$wp_is_smushed = get_post_meta( $id, 'wp-is-smushed', true );
|
633 |
+
|
634 |
+
//Not smushed, backward compatibility, check attachment metadata
|
635 |
+
if ( ! $wp_is_smushed && $data !== null ) {
|
636 |
+
if ( isset( $data['wp_smushit'] ) && ! empty( $data['wp_smushit'] ) ) {
|
637 |
+
$wp_is_smushed = true;
|
638 |
+
}
|
639 |
+
}
|
640 |
+
|
641 |
+
return $wp_is_smushed;
|
642 |
+
}
|
643 |
+
|
644 |
+
/**
|
645 |
+
* Returns size saved from the api call response
|
646 |
+
*
|
647 |
+
* @param string $message
|
648 |
+
*
|
649 |
+
* @return string|bool
|
650 |
+
*/
|
651 |
+
function get_saved_size( $message ) {
|
652 |
+
if ( preg_match( '/\((.*)\)/', $message, $matches ) ) {
|
653 |
+
return isset( $matches[1] ) ? $matches[1] : false;
|
654 |
+
}
|
655 |
+
|
656 |
+
return false;
|
657 |
+
}
|
658 |
+
|
659 |
+
/**
|
660 |
+
* Set send button status
|
661 |
+
*
|
662 |
+
* @param $id
|
663 |
+
* @param bool $echo
|
664 |
+
* @param bool $text_only
|
665 |
+
*
|
666 |
+
* @return string|void
|
667 |
+
*/
|
668 |
+
function set_status( $id, $echo = true, $text_only = false ) {
|
669 |
+
$status_txt = $button_txt = '';
|
670 |
+
$show_button = false;
|
671 |
+
|
672 |
+
//Stats are not received properly, otherwise
|
673 |
+
wp_cache_delete( $id, 'post_meta' );
|
674 |
+
|
675 |
+
$wp_smush_data = get_post_meta( $id, self::SMUSHED_META_KEY, true );
|
676 |
+
// if the image is smushed
|
677 |
+
if ( ! empty( $wp_smush_data ) ) {
|
678 |
+
|
679 |
+
$bytes = isset( $wp_smush_data['stats']['bytes'] ) ? $wp_smush_data['stats']['bytes'] : 0;
|
680 |
+
$bytes_readable = ! empty( $bytes ) ? $this->format_bytes( $bytes ) : '';
|
681 |
+
$percent = isset( $wp_smush_data['stats']['percent'] ) ? $wp_smush_data['stats']['percent'] : 0;
|
682 |
+
$percent = $percent < 0 ? 0 : $percent;
|
683 |
+
|
684 |
+
if ( isset( $wp_smush_data['stats']['size_before'] ) && $wp_smush_data['stats']['size_before'] == 0 ) {
|
685 |
+
$status_txt = __( 'Error processing request', 'wp-smushit' );
|
686 |
+
$show_button = true;
|
687 |
+
} else {
|
688 |
+
if ( $bytes == 0 || $percent == 0 ) {
|
689 |
+
$status_txt = __( 'Already Optimized', 'wp-smushit' );
|
690 |
+
} elseif ( ! empty( $percent ) && ! empty( $bytes_readable ) ) {
|
691 |
+
$status_txt = sprintf( __( "Reduced by %s ( %01.1f%% )", 'wp-smushit' ), $bytes_readable, number_format_i18n( $percent, 2, '.', '' ) );
|
692 |
+
}
|
693 |
+
}
|
694 |
+
|
695 |
+
//IF current compression is lossy
|
696 |
+
if ( ! empty( $wp_smush_data ) && ! empty( $wp_smush_data['stats'] ) ) {
|
697 |
+
$lossy = !empty( $wp_smush_data['stats']['lossy'] ) ? $wp_smush_data['stats']['lossy'] : '';
|
698 |
+
$is_lossy = $lossy == 1 ? true : false;
|
699 |
+
}
|
700 |
+
|
701 |
+
//Check if Lossy enabled
|
702 |
+
$opt_lossy = WP_SMUSH_PREFIX . 'lossy';
|
703 |
+
$opt_lossy_val = get_option( $opt_lossy, false );
|
704 |
+
|
705 |
+
//Check image type
|
706 |
+
$image_type = get_post_mime_type( $id );
|
707 |
+
|
708 |
+
//Check if premium user, compression was lossless, and lossy compression is enabled
|
709 |
+
if ( $this->is_pro() && ! $is_lossy && $opt_lossy_val && $image_type != 'image/gif' ) {
|
710 |
+
// the button text
|
711 |
+
$button_txt = __( 'Super-Smush', 'wp-smushit' );
|
712 |
+
$show_button = true;
|
713 |
+
}
|
714 |
+
} else {
|
715 |
+
|
716 |
+
// the status
|
717 |
+
$status_txt = __( 'Not processed', 'wp-smushit' );
|
718 |
+
|
719 |
+
// we need to show the smush button
|
720 |
+
$show_button = true;
|
721 |
+
|
722 |
+
// the button text
|
723 |
+
$button_txt = __( 'Smush Now!', 'wp-smushit' );
|
724 |
+
}
|
725 |
+
if ( $text_only ) {
|
726 |
+
return $status_txt;
|
727 |
+
}
|
728 |
+
|
729 |
+
$text = $this->column_html( $id, $status_txt, $button_txt, $show_button, $wp_smush_data, $echo );
|
730 |
+
if ( ! $echo ) {
|
731 |
+
return $text;
|
732 |
+
}
|
733 |
+
}
|
734 |
+
|
735 |
+
/**
|
736 |
+
* Print the column html
|
737 |
+
*
|
738 |
+
* @param string $id Media id
|
739 |
+
* @param string $status_txt Status text
|
740 |
+
* @param string $button_txt Button label
|
741 |
+
* @param boolean $show_button Whether to shoe the button
|
742 |
+
*
|
743 |
+
* @return null
|
744 |
+
*/
|
745 |
+
function column_html( $id, $status_txt = "", $button_txt = "", $show_button = true, $smushed = false, $echo = true ) {
|
746 |
+
$allowed_images = array( 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' );
|
747 |
+
|
748 |
+
// don't proceed if attachment is not image, or if image is not a jpg, png or gif
|
749 |
+
if ( ! wp_attachment_is_image( $id ) || ! in_array( get_post_mime_type( $id ), $allowed_images ) ) {
|
750 |
+
return;
|
751 |
+
}
|
752 |
+
|
753 |
+
$class = $smushed ? '' : ' hidden';
|
754 |
+
$html = '
|
755 |
+
<p class="smush-status' . $class . '">' . $status_txt . '</p>';
|
756 |
+
// if we aren't showing the button
|
757 |
+
if ( ! $show_button ) {
|
758 |
+
if ( $echo ) {
|
759 |
+
echo $html;
|
760 |
+
|
761 |
+
return;
|
762 |
+
} else {
|
763 |
+
if ( ! $smushed ) {
|
764 |
+
$class = ' currently-smushing';
|
765 |
+
} else {
|
766 |
+
$class = ' smushed';
|
767 |
+
}
|
768 |
+
|
769 |
+
return '<div class="smush-wrap' . $class . '">' . $html . '</div>';
|
770 |
+
}
|
771 |
+
}
|
772 |
+
if ( ! $echo ) {
|
773 |
+
$html .= '
|
774 |
+
<button class="button button-primary wp-smush-send" data-id="' . $id . '">
|
775 |
+
<span>' . $button_txt . '</span>
|
776 |
+
</button>';
|
777 |
+
if ( ! $smushed ) {
|
778 |
+
$class = ' unsmushed';
|
779 |
+
} else {
|
780 |
+
$class = ' smushed';
|
781 |
+
}
|
782 |
+
|
783 |
+
return '<div class="smush-wrap' . $class . '">' . $html . '</div>';
|
784 |
+
} else {
|
785 |
+
$html .= '<button class="button wp-smush-send" data-id="' . $id . '">
|
786 |
+
<span>' . $button_txt . '</span>
|
787 |
+
</button>';
|
788 |
+
echo $html;
|
789 |
+
}
|
790 |
+
}
|
791 |
+
|
792 |
+
/**
|
793 |
+
* Migrates smushit api message to the latest structure
|
794 |
+
*
|
795 |
+
*
|
796 |
+
* @return void
|
797 |
+
*/
|
798 |
+
function migrate() {
|
799 |
+
|
800 |
+
if ( ! version_compare( $this->version, "1.7.1", "lte" ) ) {
|
801 |
+
return;
|
802 |
+
}
|
803 |
+
|
804 |
+
$migrated_version = get_option( self::MIGRATED_VERSION );
|
805 |
+
|
806 |
+
if ( $migrated_version === $this->version ) {
|
807 |
+
return;
|
808 |
+
}
|
809 |
+
|
810 |
+
global $wpdb;
|
811 |
+
|
812 |
+
$q = $wpdb->prepare( "SELECT * FROM `" . $wpdb->postmeta . "` WHERE `meta_key`=%s AND `meta_value` LIKE %s ", "_wp_attachment_metadata", "%wp_smushit%" );
|
813 |
+
$results = $wpdb->get_results( $q );
|
814 |
+
|
815 |
+
if ( count( $results ) < 1 ) {
|
816 |
+
return;
|
817 |
+
}
|
818 |
+
|
819 |
+
$migrator = new WpSmushMigrate();
|
820 |
+
foreach ( $results as $attachment_meta ) {
|
821 |
+
$migrated_message = $migrator->migrate_api_message( maybe_unserialize( $attachment_meta->meta_value ) );
|
822 |
+
if ( $migrated_message !== array() ) {
|
823 |
+
update_post_meta( $attachment_meta->post_id, self::SMUSHED_META_KEY, $migrated_message );
|
824 |
+
}
|
825 |
+
}
|
826 |
+
|
827 |
+
update_option( self::MIGRATED_VERSION, $this->version );
|
828 |
+
|
829 |
+
}
|
830 |
+
|
831 |
+
/**
|
832 |
+
* @param Object $response_data
|
833 |
+
* @param $size_before
|
834 |
+
* @param $size_after
|
835 |
+
* @param $total_time
|
836 |
+
* @param $bytes_saved
|
837 |
+
*
|
838 |
+
* @return array
|
839 |
+
*/
|
840 |
+
private function _update_stats_data( $response_data, $size_before, $size_after, $total_time, $bytes_saved ) {
|
841 |
+
$size_before += ! empty( $response_data->before_size ) ? (int) $response_data->before_size : 0;
|
842 |
+
$size_after += ( ! empty( $response_data->after_size ) && $response_data->after_size > 0 ) ? (int) $response_data->after_size : (int) $response_data->before_size;
|
843 |
+
$total_time += ! empty( $response_data->time ) ? (float) $response_data->time : 0;
|
844 |
+
$bytes_saved += ( ! empty( $response_data->bytes_saved ) && $response_data->bytes_saved > 0 ) ? $response_data->bytes_saved : 0;
|
845 |
+
$compression = ( $bytes_saved > 0 && $size_before > 0 ) ? ( ( $bytes_saved / $size_before ) * 100 ) : 0;
|
846 |
+
|
847 |
+
return array( $size_before, $size_after, $total_time, $compression, $bytes_saved );
|
848 |
+
}
|
849 |
+
}
|
850 |
+
|
851 |
+
global $WpSmush;
|
852 |
+
$WpSmush = new WpSmush();
|
853 |
+
|
854 |
+
}
|
855 |
+
|
856 |
+
//Include Admin classes
|
857 |
+
require_once( WP_SMUSH_DIR . '/lib/class-wp-smush-bulk.php' );
|
858 |
+
require_once( WP_SMUSH_DIR . '/lib/class-wp-smush-admin.php' );
|
859 |
+
|
860 |
+
//require_once( WP_SMUSH_DIR . '/extras/dash-notice/wpmudev-dash-notification.php' );
|
861 |
+
require_once( WP_SMUSH_DIR . '/extras/free-dashboard/module.php' );
|
862 |
|
863 |
// Register the current plugin.
|
864 |
+
do_action(
|
865 |
+
'wdev-register-plugin',
|
866 |
+
/* 1 Plugin ID */ plugin_basename( __FILE__ ), /* Plugin ID */
|
867 |
+
/* 2 Plugin Title */ 'WP Smush',
|
868 |
+
/* 3 https://wordpress.org */ '/plugins/wp-smushit/',
|
869 |
+
/* 4 Email Button CTA */ __( 'Get Fast', 'wp-smushit' ),
|
870 |
+
/* 5 getdrip Plugin param */ 'Smush'
|
871 |
+
);
|
|
|
|
|
|
|
|
|
|
|
872 |
|
873 |
// The rating message contains 2 variables: user-name, plugin-name
|
874 |
+
add_filter(
|
875 |
+
'wdev-rating-message-' . plugin_basename( __FILE__ ),
|
876 |
+
'wp_smush_rating_message'
|
877 |
+
);
|
878 |
+
|
879 |
+
/**
|
880 |
+
* Filters the rating message, include stats if greater than 1Mb
|
881 |
+
* @param $message
|
882 |
+
*
|
883 |
+
* @return string
|
884 |
+
*/
|
885 |
+
function wp_smush_rating_message( $message ) {
|
886 |
+
global $wpsmushit_admin;
|
887 |
+
$savings = $wpsmushit_admin->global_stats();
|
888 |
+
$image_count = $wpsmushit_admin->total_count();
|
889 |
+
$show_stats = false;
|
890 |
+
|
891 |
+
//If there is any saving, greater than 1Mb, show stats
|
892 |
+
if( !empty( $savings ) && !empty( $savings['bytes'] ) && $savings['bytes'] > 1048576 ) {
|
893 |
+
$show_stats = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
894 |
}
|
895 |
|
896 |
+
$message = "Hey %s, you've been using %s for a while now, and we hope you're happy with it.";
|
897 |
+
|
898 |
+
//Conditionally Show stats in rating message
|
899 |
+
if( $show_stats ) {
|
900 |
+
$message .= sprintf( " You've smushed <strong>%s</strong> from %d images already, improving the speed and SEO ranking of this site!", $savings['human'], $image_count );
|
|
|
|
|
|
|
|
|
901 |
}
|
902 |
+
$message .= " We've spent countless hours developing this free plugin for you, and we would really appreciate it if you dropped us a quick rating!";
|
903 |
+
|
904 |
+
return $message;
|
905 |
+
}
|
906 |
+
|
907 |
+
// The email message contains 1 variable: plugin-name
|
908 |
+
add_filter(
|
909 |
+
'wdev-email-message-' . plugin_basename( __FILE__ ),
|
910 |
+
'wp_smush_email_message'
|
911 |
+
);
|
912 |
+
function wp_smush_email_message( $message ) {
|
913 |
+
$message = "You're awesome for installing %s! Site speed isn't all image optimization though, so we've collected all the best speed resources we know in a single email - just for users of WP Smush!";
|
914 |
+
return $message;
|
915 |
+
}
|
916 |
+
// All done!
|