Version Description
(2021-01-31) =
* [Fixed]
Encoding paths to files
* [Fixed]
Retaining PNG transparency using Gd method
* [Added]
Cron to convert images uploaded to Media Library
Download this release
Release Info
Developer | mateuszgbiorczyk |
Plugin | Converter for Media – Optimize images | Convert WebP & AVIF |
Version | 2.3.0 |
Comparing to | |
See all releases |
Code changes from version 2.2.0 to 2.3.0
- app/Convert/Dir.php +1 -1
- app/Media/Upload.php +12 -1
- app/Method/Gd.php +20 -2
- app/Method/MethodAbstract.php +4 -3
- app/Settings/Options.php +1 -0
- app/Settings/Values.php +1 -1
- public/build/js/scripts.js +1 -1
- readme.txt +9 -3
- webp-converter-for-media.php +2 -2
app/Convert/Dir.php
CHANGED
@@ -31,7 +31,7 @@
|
|
31 |
foreach ($paths as $path) {
|
32 |
if (in_array($path, $excludedDirs)) continue;
|
33 |
|
34 |
-
$currentPath = $dirPath . '/' . $path;
|
35 |
if (is_dir($currentPath)) {
|
36 |
$list = array_merge($list, $this->findFilesInDirectory($currentPath, $allowedExts, $excludedDirs));
|
37 |
} else if (in_array(strtolower(pathinfo($currentPath, PATHINFO_EXTENSION)), $allowedExts)) {
|
31 |
foreach ($paths as $path) {
|
32 |
if (in_array($path, $excludedDirs)) continue;
|
33 |
|
34 |
+
$currentPath = $dirPath . '/' . urlencode($path);
|
35 |
if (is_dir($currentPath)) {
|
36 |
$list = array_merge($list, $this->findFilesInDirectory($currentPath, $allowedExts, $excludedDirs));
|
37 |
} else if (in_array(strtolower(pathinfo($currentPath, PATHINFO_EXTENSION)), $allowedExts)) {
|
app/Media/Upload.php
CHANGED
@@ -25,8 +25,8 @@
|
|
25 |
|
26 |
$paths = array_diff($paths, $this->convertedPaths);
|
27 |
$this->convertedPaths = array_merge($this->convertedPaths, $paths);
|
|
|
28 |
|
29 |
-
do_action('webpc_convert_paths', $paths);
|
30 |
return $data;
|
31 |
}
|
32 |
|
@@ -50,4 +50,15 @@
|
|
50 |
$source = str_replace('\\', '/', $source);
|
51 |
return $source;
|
52 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
25 |
|
26 |
$paths = array_diff($paths, $this->convertedPaths);
|
27 |
$this->convertedPaths = array_merge($this->convertedPaths, $paths);
|
28 |
+
$this->initConversion($paths);
|
29 |
|
|
|
30 |
return $data;
|
31 |
}
|
32 |
|
50 |
$source = str_replace('\\', '/', $source);
|
51 |
return $source;
|
52 |
}
|
53 |
+
|
54 |
+
private function initConversion($paths)
|
55 |
+
{
|
56 |
+
$settings = apply_filters('webpc_get_values', []);
|
57 |
+
|
58 |
+
if (in_array('cron_conversion', $settings['features'])) {
|
59 |
+
wp_schedule_single_event((time() + 1), 'webpc_convert_paths', [$paths]);
|
60 |
+
} else {
|
61 |
+
do_action('webpc_convert_paths', $paths);
|
62 |
+
}
|
63 |
+
}
|
64 |
}
|
app/Method/Gd.php
CHANGED
@@ -52,10 +52,10 @@
|
|
52 |
throw $e;
|
53 |
}
|
54 |
|
55 |
-
return $this->updateImageResource($image);
|
56 |
}
|
57 |
|
58 |
-
private function updateImageResource($image)
|
59 |
{
|
60 |
if (!function_exists('imageistruecolor')) {
|
61 |
$e = new \Exception(sprintf('Server configuration: "%s" function is not available.', 'imageistruecolor'));
|
@@ -72,6 +72,24 @@
|
|
72 |
imagepalettetotruecolor($image);
|
73 |
}
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
return $image;
|
76 |
}
|
77 |
|
52 |
throw $e;
|
53 |
}
|
54 |
|
55 |
+
return $this->updateImageResource($image, $extension);
|
56 |
}
|
57 |
|
58 |
+
private function updateImageResource($image, $extension)
|
59 |
{
|
60 |
if (!function_exists('imageistruecolor')) {
|
61 |
$e = new \Exception(sprintf('Server configuration: "%s" function is not available.', 'imageistruecolor'));
|
72 |
imagepalettetotruecolor($image);
|
73 |
}
|
74 |
|
75 |
+
switch ($extension) {
|
76 |
+
case 'png':
|
77 |
+
if (!function_exists('imagealphablending')) {
|
78 |
+
$e = new \Exception(sprintf('Server configuration: "%s" function is not available.', 'imagealphablending'));
|
79 |
+
$e->status = 'server_configuration';
|
80 |
+
throw $e;
|
81 |
+
}
|
82 |
+
imagealphablending($image, false);
|
83 |
+
|
84 |
+
if (!function_exists('imagesavealpha')) {
|
85 |
+
$e = new \Exception(sprintf('Server configuration: "%s" function is not available.', 'imagesavealpha'));
|
86 |
+
$e->status = 'server_configuration';
|
87 |
+
throw $e;
|
88 |
+
}
|
89 |
+
imagesavealpha($image, true);
|
90 |
+
break;
|
91 |
+
}
|
92 |
+
|
93 |
return $image;
|
94 |
}
|
95 |
|
app/Method/MethodAbstract.php
CHANGED
@@ -56,13 +56,14 @@
|
|
56 |
|
57 |
public function getImageSourcePath($sourcePath)
|
58 |
{
|
59 |
-
|
60 |
-
|
|
|
61 |
$e->status = 'file_unreadable';
|
62 |
throw $e;
|
63 |
}
|
64 |
|
65 |
-
return $
|
66 |
}
|
67 |
|
68 |
public function getImageOutputPath($sourcePath)
|
56 |
|
57 |
public function getImageSourcePath($sourcePath)
|
58 |
{
|
59 |
+
$path = urldecode($sourcePath);
|
60 |
+
if (!$status = Server::checkIfFileExists($path)) {
|
61 |
+
$e = new \Exception(sprintf('Source path "%s" for image does not exist.', $path));
|
62 |
$e->status = 'file_unreadable';
|
63 |
throw $e;
|
64 |
}
|
65 |
|
66 |
+
return $path;
|
67 |
}
|
68 |
|
69 |
public function getImageOutputPath($sourcePath)
|
app/Settings/Options.php
CHANGED
@@ -97,6 +97,7 @@
|
|
97 |
'mod_expires' => __('Browser Caching for WebP files (saving images in browser cache memory)', 'webp-converter-for-media'),
|
98 |
'keep_metadata' => __('Keep images metadata stored in EXIF or XMP formats (only available for Imagick conversion method)', 'webp-converter-for-media'),
|
99 |
'cron_enabled' => __('Enable cron to automatically convert images from outside Media Library (images from Media Library are converted immediately after upload)', 'webp-converter-for-media'),
|
|
|
100 |
'referer_disabled' => __('Force redirections to WebP for all domains (by default, images in WebP are loaded only in domain of your website - when image is displayed via URL on another domain that original file is loaded)', 'webp-converter-for-media'),
|
101 |
'debug_enabled' => __('Log errors while converting to debug.log file (when debugging in WordPress is active)', 'webp-converter-for-media'),
|
102 |
],
|
97 |
'mod_expires' => __('Browser Caching for WebP files (saving images in browser cache memory)', 'webp-converter-for-media'),
|
98 |
'keep_metadata' => __('Keep images metadata stored in EXIF or XMP formats (only available for Imagick conversion method)', 'webp-converter-for-media'),
|
99 |
'cron_enabled' => __('Enable cron to automatically convert images from outside Media Library (images from Media Library are converted immediately after upload)', 'webp-converter-for-media'),
|
100 |
+
'cron_conversion' => __('Enable cron to convert images uploaded to Media Library to speed up process of adding images (deactivate this option if images added to Media Library are not automatically converted)', 'webp-converter-for-media'),
|
101 |
'referer_disabled' => __('Force redirections to WebP for all domains (by default, images in WebP are loaded only in domain of your website - when image is displayed via URL on another domain that original file is loaded)', 'webp-converter-for-media'),
|
102 |
'debug_enabled' => __('Log errors while converting to debug.log file (when debugging in WordPress is active)', 'webp-converter-for-media'),
|
103 |
],
|
app/Settings/Values.php
CHANGED
@@ -25,7 +25,7 @@
|
|
25 |
'extensions' => ['jpg', 'jpeg', 'png'],
|
26 |
'dirs' => ['uploads'],
|
27 |
'method' => ($methods) ? $methods[0] : '',
|
28 |
-
'features' => ['only_smaller', 'mod_expires', 'debug_enabled'],
|
29 |
'quality' => 85,
|
30 |
]);
|
31 |
return $this->cache;
|
25 |
'extensions' => ['jpg', 'jpeg', 'png'],
|
26 |
'dirs' => ['uploads'],
|
27 |
'method' => ($methods) ? $methods[0] : '',
|
28 |
+
'features' => ['only_smaller', 'mod_expires', 'cron_conversion', 'debug_enabled'],
|
29 |
'quality' => 85,
|
30 |
]);
|
31 |
return $this->cache;
|
public/build/js/scripts.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function(
|
1 |
+
!function(e){var t={};function r(s){if(t[s])return t[s].exports;var i=t[s]={i:s,l:!1,exports:{}};return e[s].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(s,i,function(t){return e[t]}.bind(null,i));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/",r(r.s=0)}([function(e,t,r){r(1),e.exports=r(2)},function(e,t,r){"use strict";function s(e,t){for(var r=0;r<t.length;r++){var s=t[r];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}r.r(t);var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.setVars()&&this.setEvents()}var t,r,i;return t=e,(r=[{key:"setVars",value:function(){if(this.buttonOpen=document.querySelector('[data-slug="webp-converter-for-media"] a[href*="action=deactivate"]'),this.modal=document.querySelector(".webpModal"),this.buttonOpen&&this.modal)return this.outer=this.modal.querySelector(".webpModal__outer"),this.form=this.outer.querySelector(".webpModal__form"),this.formOptions=this.form.querySelectorAll('[name="webpc_reason"]'),this.formComment=this.form.querySelector('[name="webpc_comment"]'),this.buttonSubmit=this.form.querySelector('button[type="submit"]'),this.buttonCancel=this.form.querySelector('button[type="button"]'),this.events={openModal:this.openModal.bind(this)},this.atts={optionPlaceholder:"data-placeholder"},!0}},{key:"setEvents",value:function(){var e=this;this.buttonOpen.addEventListener("click",this.events.openModal),this.buttonSubmit.addEventListener("click",this.submitForm.bind(this)),this.buttonCancel.addEventListener("click",this.cancelForm.bind(this)),this.outer.addEventListener("click",this.closeModal.bind(this)),this.form.addEventListener("click",(function(e){e.stopPropagation()}));for(var t=this.formOptions.length,r=function(t){e.formOptions[t].addEventListener("change",(function(){e.setCurrentOption(t)}))},s=0;s<t;s++)r(s)}},{key:"openModal",value:function(e){e.preventDefault(),this.buttonOpen.removeEventListener("click",this.events.openModal),this.modal.removeAttribute("hidden")}},{key:"closeModal",value:function(){this.modal.setAttribute("hidden","hidden")}},{key:"submitForm",value:function(e){var t=this;e.preventDefault(),this.closeModal(),setTimeout((function(){var e=new FormData(t.form),r=t.form.getAttribute("action"),s=new XMLHttpRequest;s.open("POST",r,!0),s.send(e),t.buttonOpen.click()}),0)}},{key:"cancelForm",value:function(e){var t=this;e.preventDefault(),this.closeModal(),setTimeout((function(){t.buttonOpen.click()}),0)}},{key:"setCurrentOption",value:function(e){this.formComment.value="";var t=this.formOptions[e].getAttribute(this.atts.optionPlaceholder);this.formComment.setAttribute("placeholder",t)}}])&&s(t.prototype,r),i&&s(t,i),e}();function n(e,t){for(var r=0;r<t.length;r++){var s=t[r];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.setVars()&&this.setEvents()}var t,r,s;return t=e,(r=[{key:"setVars",value:function(){if(this.notice=document.querySelector(".notice[data-notice=webp-converter]"),this.notice)return this.settings={ajaxUrl:this.notice.getAttribute("data-url"),ajaxAction:"webpc_notice",buttonCloseClass:".notice[data-notice=webp-converter] .notice-dismiss",buttonHideClass:".notice[data-notice=webp-converter] [data-permanently]"},this.status={isHidden:!1},!0}},{key:"setEvents",value:function(){var e=this,t=this.settings,r=t.buttonCloseClass,s=t.buttonHideClass;window.addEventListener("click",(function(t){t.target.matches(r)?e.hideNotice(!1):t.target.matches(s)&&(t.preventDefault(),e.hideNotice(!0))}))}},{key:"hideNotice",value:function(e){if(!this.status.isHidden){this.status.isHidden=!0;var t=this.settings,r=t.ajaxUrl,s=t.ajaxAction,i=t.buttonCloseClass;jQuery.ajax(r,{type:"POST",data:{action:s,is_permanently:e?1:0}}),document.querySelector(i).click()}}}])&&n(t.prototype,r),s&&n(t,s),e}();function a(e,t){for(var r=0;r<t.length;r++){var s=t[r];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}var u=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.setVars()&&this.setEvents()}var t,r,s;return t=e,(r=[{key:"setVars",value:function(){if(this.section=document.querySelector(".webpLoader"),this.section)return this.wrapper=this.section.querySelector(".webpLoader__status"),this.progress=this.wrapper.querySelector(".webpLoader__barProgress"),this.progressSize=this.section.querySelector(".webpLoader__sizeProgress"),this.errors=this.section.querySelector(".webpLoader__errors"),this.errorsInner=this.errors.querySelector(".webpLoader__errorsContentList"),this.errorsMessage=this.errors.querySelector(".webpLoader__errorsContentMessage"),this.success=this.section.querySelector(".webpLoader__success"),this.succesPopup=this.section.querySelector(".webpLoader__popup"),this.inputOptions=this.section.querySelectorAll('input[type="checkbox"]'),this.button=this.section.querySelector(".webpLoader__button"),this.data={count:0,max:0,items:[],size:{before:0,after:0},errors:[]},this.settings={isDisabled:!1,ajax:{urlPaths:this.section.getAttribute("data-api-paths"),urlRegenerate:this.section.getAttribute("data-api-regenerate"),errorMessage:this.section.getAttribute("data-api-error-message")},units:["kB","MB","GB"]},this.atts={progress:"data-percent"},this.classes={progressError:"webpLoader__barProgress--error",buttonDisabled:"webpLoader__button--disabled"},!0}},{key:"setEvents",value:function(){this.button.addEventListener("click",this.initRegenerate.bind(this))}},{key:"initRegenerate",value:function(e){if(e.preventDefault(),!this.settings.isDisabled){this.settings.isDisabled=!0,this.button.classList.add(this.classes.buttonDisabled);for(var t=this.inputOptions.length,r=0;r<t;r++)this.inputOptions[r].setAttribute("disabled",!0);this.wrapper.removeAttribute("hidden"),this.getImagesList()}}},{key:"getImagesList",value:function(){var e=this;jQuery.ajax(this.settings.ajax.urlPaths,{type:"POST",data:this.getDataForPathsRequest()}).done((function(t){e.data.items=t,e.data.max=t.length,e.regenerateNextImages()})).fail((function(){e.progress.classList.add(e.classes.progressError),e.errorsMessage.removeAttribute("hidden"),e.errors.removeAttribute("hidden")}))}},{key:"getDataForPathsRequest",value:function(){for(var e={},t=this.inputOptions.length,r=0;r<t;r++)e[this.inputOptions[r].getAttribute("name")]=this.inputOptions[r].checked?1:0;return e}},{key:"regenerateNextImages",value:function(){if(0===this.data.max&&this.updateProgress(),!(this.data.count>=this.data.max)){var e=this.data.items[this.data.count];this.data.count++,this.sendRequest(e)}}},{key:"sendRequest",value:function(e){var t=this;jQuery.ajax(this.settings.ajax.urlRegenerate,{type:"POST",data:{paths:e}}).done((function(e){t.updateErrors(e.errors),t.updateSize(e),t.updateProgress(),t.regenerateNextImages()})).fail((function(){var r=JSON.stringify(e),s=t.settings.ajax.errorMessage.replace("%s","<code>".concat(r,"</code>"));t.updateErrors([s]),t.regenerateNextImages()}))}},{key:"updateErrors",value:function(e){0!==e.length&&(this.data.errors=this.data.errors.concat(e),this.errorsInner.innerHTML=this.data.errors.join("<br>"),this.errors.removeAttribute("hidden"))}},{key:"updateSize",value:function(e){var t=this.data.size;t.before+=e.size.before,t.after+=e.size.after;var r=t.before-t.after;if(r<0&&(r=0),0!==r){var s=Math.round(100*(1-t.after/t.before));s<0&&(s=0);var i=-1;do{i++,r/=1024}while(r>1024);var n=r.toFixed(2),o=this.settings.units[i],a="".concat(n," ").concat(o," (").concat(s,"%)");this.progressSize.innerHTML=a}}},{key:"updateProgress",value:function(){var e=this.data.max>0?Math.floor(this.data.count/this.data.max*100):100;e>100&&(e=100),100===e&&(this.success.removeAttribute("hidden"),this.succesPopup.removeAttribute("hidden")),this.progress.setAttribute(this.atts.progress,e)}}])&&a(t.prototype,r),s&&a(t,s),e}();new function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),new i,new o,new u}},function(e,t){}]);
|
readme.txt
CHANGED
@@ -477,12 +477,18 @@ This is all very important to us and allows us to do even better things for you!
|
|
477 |
|
478 |
== Screenshots ==
|
479 |
|
480 |
-
1.
|
481 |
-
2. Screenshot
|
|
|
482 |
|
483 |
== Changelog ==
|
484 |
|
485 |
-
= 2.
|
|
|
|
|
|
|
|
|
|
|
486 |
* `[Added]` Support for WordPress Multisite
|
487 |
|
488 |
= 2.1.3 (2020-12-28) =
|
477 |
|
478 |
== Screenshots ==
|
479 |
|
480 |
+
1. How to start using plugin few moments?
|
481 |
+
2. Screenshot of the options panel
|
482 |
+
3. Screenshot when regenerating images
|
483 |
|
484 |
== Changelog ==
|
485 |
|
486 |
+
= 2.3.0 (2021-01-31) =
|
487 |
+
* `[Fixed]` Encoding paths to files
|
488 |
+
* `[Fixed]` Retaining PNG transparency using Gd method
|
489 |
+
* `[Added]` Cron to convert images uploaded to Media Library
|
490 |
+
|
491 |
+
= 2.2.0 (2021-01-13) =
|
492 |
* `[Added]` Support for WordPress Multisite
|
493 |
|
494 |
= 2.1.3 (2020-12-28) =
|
webp-converter-for-media.php
CHANGED
@@ -3,14 +3,14 @@
|
|
3 |
/*
|
4 |
Plugin Name: WebP Converter for Media
|
5 |
Description: Speed up your website by serving WebP images instead of standard formats JPEG, PNG and GIF.
|
6 |
-
Version: 2.
|
7 |
Author: Mateusz Gbiorczyk
|
8 |
Author URI: https://gbiorczyk.pl/
|
9 |
Text Domain: webp-converter-for-media
|
10 |
Network: true
|
11 |
*/
|
12 |
|
13 |
-
define('WEBPC_VERSION', '2.
|
14 |
define('WEBPC_FILE', __FILE__);
|
15 |
define('WEBPC_NAME', plugin_basename(__FILE__));
|
16 |
define('WEBPC_PATH', plugin_dir_path(__FILE__));
|
3 |
/*
|
4 |
Plugin Name: WebP Converter for Media
|
5 |
Description: Speed up your website by serving WebP images instead of standard formats JPEG, PNG and GIF.
|
6 |
+
Version: 2.3.0
|
7 |
Author: Mateusz Gbiorczyk
|
8 |
Author URI: https://gbiorczyk.pl/
|
9 |
Text Domain: webp-converter-for-media
|
10 |
Network: true
|
11 |
*/
|
12 |
|
13 |
+
define('WEBPC_VERSION', '2.3.0');
|
14 |
define('WEBPC_FILE', __FILE__);
|
15 |
define('WEBPC_NAME', plugin_basename(__FILE__));
|
16 |
define('WEBPC_PATH', plugin_dir_path(__FILE__));
|