Image optimization & Lazy Load by Optimole - Version 2.2.2

Version Description

Download this release

Release Info

Developer optimole
Plugin Icon 128x128 Image optimization & Lazy Load by Optimole
Version 2.2.2
Comparing to
See all releases

Code changes from version 2.2.1 to 2.2.2

CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
#### [Version 2.2.1](https://github.com/Codeinwp/optimole-wp/compare/v2.2.0...v2.2.1) (2019-10-21)
2
3
* **Bug Fixes**
1
+ #### [Version 2.2.2](https://github.com/Codeinwp/optimole-wp/compare/v2.2.1...v2.2.2) (2019-11-04)
2
+
3
+ * **Bug Fixes**
4
+ * ignore rescale on GIF and SVG when lazyload is active ([d4e63b6](https://github.com/Codeinwp/optimole-wp/commit/d4e63b6))
5
+ * improve compatibility with Thrive Architect ([55a5952](https://github.com/Codeinwp/optimole-wp/commit/55a5952))
6
+ * improve generic placeholder computed width/height when the source size is unknown ([0c3cc3f](https://github.com/Codeinwp/optimole-wp/commit/0c3cc3f))
7
+ * sign only URLs that don't use an whitelisted domain. ([7813bf9](https://github.com/Codeinwp/optimole-wp/commit/7813bf9))
8
+ * strip retina based prefix to use original url ([948c667](https://github.com/Codeinwp/optimole-wp/commit/948c667))
9
+
10
#### [Version 2.2.1](https://github.com/Codeinwp/optimole-wp/compare/v2.2.0...v2.2.1) (2019-10-21)
11
12
* **Bug Fixes**
README.md CHANGED
@@ -89,6 +89,17 @@ Premium users will be able to optimize images for more than 25k monthly active u
89
90
## Changelog ##
91
92
#### [Version 2.2.1](https://github.com/Codeinwp/optimole-wp/compare/v2.2.0...v2.2.1) (2019-10-21)
93
94
* **Bug Fixes**
89
90
## Changelog ##
91
92
+ #### [Version 2.2.2](https://github.com/Codeinwp/optimole-wp/compare/v2.2.1...v2.2.2) (2019-11-04)
93
+
94
+ * **Bug Fixes**
95
+ * ignore rescale on GIF and SVG when lazyload is active ([d4e63b6](https://github.com/Codeinwp/optimole-wp/commit/d4e63b6))
96
+ * improve compatibility with Thrive Architect ([55a5952](https://github.com/Codeinwp/optimole-wp/commit/55a5952))
97
+ * improve generic placeholder computed width/height when the source size is unknown ([0c3cc3f](https://github.com/Codeinwp/optimole-wp/commit/0c3cc3f))
98
+ * sign only URLs that don't use an whitelisted domain. ([7813bf9](https://github.com/Codeinwp/optimole-wp/commit/7813bf9))
99
+ * strip retina based prefix to use original url ([948c667](https://github.com/Codeinwp/optimole-wp/commit/948c667))
100
+
101
+
102
+
103
#### [Version 2.2.1](https://github.com/Codeinwp/optimole-wp/compare/v2.2.0...v2.2.1) (2019-10-21)
104
105
* **Bug Fixes**
inc/app_replacer.php CHANGED
@@ -254,8 +254,10 @@ abstract class Optml_App_Replacer {
254
255
$content_parts = parse_url( content_url() );
256
257
- $this->upload_resource['content_path'] = $content_parts['path'];
258
- $this->upload_resource['content_host'] = $content_parts['scheme'] . '://' . $content_parts['host'];
259
260
$service_data = $this->settings->get( 'service_data' );
261
@@ -364,7 +366,7 @@ abstract class Optml_App_Replacer {
364
**/
365
public function strip_image_size_from_url( $url ) {
366
367
- if ( preg_match( '#(-\d+x\d+(?:_c)?)\.(' . implode( '|', array_keys( Optml_Config::$extensions ) ) . '){1}$#i', $url, $src_parts ) ) {
368
$stripped_url = str_replace( $src_parts[1], '', $url );
369
// Extracts the file path to the image minus the base url
370
$file_path = substr( $stripped_url, strpos( $stripped_url, $this->upload_resource['url'] ) + $this->upload_resource['url_length'] );
254
255
$content_parts = parse_url( content_url() );
256
257
+ $this->upload_resource['content_path'] = $content_parts['path'];
258
+ $this->upload_resource['content_folder'] = ltrim( $content_parts['path'], '/' );
259
+ $this->upload_resource['content_folder_length'] = strlen( $this->upload_resource['content_folder'] );
260
+ $this->upload_resource['content_host'] = $content_parts['scheme'] . '://' . $content_parts['host'];
261
262
$service_data = $this->settings->get( 'service_data' );
263
366
**/
367
public function strip_image_size_from_url( $url ) {
368
369
+ if ( preg_match( '#(-\d+x\d+(?:_c)?|(@2x))\.(' . implode( '|', array_keys( Optml_Config::$extensions ) ) . '){1}$#i', $url, $src_parts ) ) {
370
$stripped_url = str_replace( $src_parts[1], '', $url );
371
// Extracts the file path to the image minus the base url
372
$file_path = substr( $stripped_url, strpos( $stripped_url, $this->upload_resource['url'] ) + $this->upload_resource['url_length'] );
inc/lazyload_replacer.php CHANGED
@@ -10,6 +10,7 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
10
use Optml_Normalizer;
11
use Optml_Validator;
12
13
/**
14
* Cached object instance.
15
*
@@ -91,8 +92,8 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
91
$saved_watchers = str_replace( [ "\n", "\r" ], ',', $saved_watchers );
92
$saved_watchers = explode( ',', $saved_watchers );
93
$all_watchers = array_merge( $default_watchers, $saved_watchers );
94
- $all_watchers = apply_filters( 'optml_lazyload_bg_selectors', $all_watchers );
95
- $all_watchers = array_filter(
96
$all_watchers,
97
function ( $value ) {
98
return ! empty( $value ) && strlen( $value ) >= 2;
@@ -177,15 +178,18 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
177
if ( ! $this->can_lazyload_for( $original_url, $full_tag ) ) {
178
return Optml_Tag_Replacer::instance()->regular_tag_replace( $new_tag, $original_url, $new_url, $optml_args, $is_slashed );
179
}
180
- if ( ! self::$is_lazyload_placeholder && ! $this->is_valid_gif( $original_url ) ) {
181
$optml_args['quality'] = 'eco';
182
$optml_args['resize'] = [];
183
$low_url = apply_filters( 'optml_content_url', $is_slashed ? stripslashes( $original_url ) : $original_url, $optml_args );
184
$low_url = $is_slashed ? addcslashes( $low_url, '/' ) : $low_url;
185
} else {
186
- $low_url = self::get_svg_for(
187
isset( $optml_args['width'] ) ? $optml_args['width'] : '100%',
188
- isset( $optml_args['height'] ) ? $optml_args['height'] : '100%'
189
);
190
}
191
@@ -193,9 +197,19 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
193
194
if ( $this->should_add_data_tag( $full_tag ) ) {
195
$opt_format = ' data-opt-src="%s" ';
196
$opt_format = $is_slashed ? addslashes( $opt_format ) : $opt_format;
197
}
198
-
199
$new_url = $is_slashed ? addcslashes( $new_url, '/' ) : $new_url;
200
201
$opt_src = sprintf( $opt_format, $new_url );
@@ -220,14 +234,6 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
220
221
$new_tag = str_replace( 'srcset=', 'old-srcset=', $new_tag );
222
223
- if ( $this->is_valid_gif( $original_url ) ) {
224
- if ( strpos( $new_tag, 'class=' ) === - 1 ) {
225
- $new_tag = str_replace( '<img', '<img class="optimole-lazy-only"', $new_tag );
226
- } else {
227
- $new_tag = str_replace( 'class="', 'class="optimole-lazy-only ', $new_tag );
228
- }
229
- }
230
-
231
if ( ! $this->should_add_noscript( $new_tag ) ) {
232
return $new_tag;
233
}
@@ -295,27 +301,41 @@ final class Optml_Lazyload_Replacer extends Optml_App_Replacer {
295
/**
296
* Get SVG markup with specific width/height.
297
*
298
- * @param int $width Markup Width.
299
- * @param int $height Markup Height.
300
*
301
* @return string SVG code.
302
*/
303
- public static function get_svg_for( $width, $height ) {
304
$width = ! is_numeric( $width ) ? '100%' : $width;
305
$height = ! is_numeric( $height ) ? '100%' : $height;
306
307
- static $SVG = '<svg xmlns="http://www.w3.org/2000/svg" width="#width#" height="#height#" style=""> <rect id="backgroundrect" width="100%" height="100%" x="0" y="0" fill="#FFFFFF" stroke="none"/> <g style="" class="currentLayer"> <rect fill="#ffffff" stroke="#ffffff" stroke-width="2" stroke-linejoin="round" stroke-dashoffset="" fill-rule="nonzero" style="color: rgb(0, 0, 0);" class="selected" stroke-opacity="1" fill-opacity="1"/></g></svg>';
308
-
309
- return 'data:image/svg+xml,' . rawurlencode(
310
str_replace(
311
[ '#width#', '#height#' ],
312
[
313
$width,
314
$height,
315
],
316
- $SVG
317
- )
318
- );
319
}
320
321
/**
10
use Optml_Normalizer;
11
use Optml_Validator;
12
13
+ const SVG_PLACEHOLDER = 'data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%20#width#%20#height#%22%20width%3D%22#width#%22%20height%3D%22#height#%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3C%2Fsvg%3E';
14
/**
15
* Cached object instance.
16
*
92
$saved_watchers = str_replace( [ "\n", "\r" ], ',', $saved_watchers );
93
$saved_watchers = explode( ',', $saved_watchers );
94
$all_watchers = array_merge( $default_watchers, $saved_watchers );
95
+ $all_watchers = apply_filters( 'optml_lazyload_bg_selectors', $all_watchers );
96
+ $all_watchers = array_filter(
97
$all_watchers,
98
function ( $value ) {
99
return ! empty( $value ) && strlen( $value ) >= 2;
178
if ( ! $this->can_lazyload_for( $original_url, $full_tag ) ) {
179
return Optml_Tag_Replacer::instance()->regular_tag_replace( $new_tag, $original_url, $new_url, $optml_args, $is_slashed );
180
}
181
+ $should_ignore_rescale = ! $this->is_valid_mimetype_from_url( $original_url, [ 'gif' => true, 'svg' => true ] );
182
+
183
+ if ( ! self::$is_lazyload_placeholder && ! $should_ignore_rescale ) {
184
$optml_args['quality'] = 'eco';
185
$optml_args['resize'] = [];
186
$low_url = apply_filters( 'optml_content_url', $is_slashed ? stripslashes( $original_url ) : $original_url, $optml_args );
187
$low_url = $is_slashed ? addcslashes( $low_url, '/' ) : $low_url;
188
} else {
189
+ $low_url = $this->get_svg_for(
190
isset( $optml_args['width'] ) ? $optml_args['width'] : '100%',
191
+ isset( $optml_args['height'] ) ? $optml_args['height'] : '100%',
192
+ ( $should_ignore_rescale ? null : $original_url )
193
);
194
}
195
197
198
if ( $this->should_add_data_tag( $full_tag ) ) {
199
$opt_format = ' data-opt-src="%s" ';
200
+ if ( $should_ignore_rescale ) {
201
+ if ( strpos( $new_tag, 'class=' ) === false ) {
202
+ $opt_format .= ' class="optimole-lazy-only" ';
203
+ } else {
204
+ $new_tag = str_replace(
205
+ ( $is_slashed ? 'class=\"' : 'class="' ),
206
+ ( $is_slashed ? 'class=\"optimole-lazy-only ' : 'class="optimole-lazy-only ' ),
207
+ $new_tag
208
+ );
209
+ }
210
+ }
211
$opt_format = $is_slashed ? addslashes( $opt_format ) : $opt_format;
212
}
213
$new_url = $is_slashed ? addcslashes( $new_url, '/' ) : $new_url;
214
215
$opt_src = sprintf( $opt_format, $new_url );
234
235
$new_tag = str_replace( 'srcset=', 'old-srcset=', $new_tag );
236
237
if ( ! $this->should_add_noscript( $new_tag ) ) {
238
return $new_tag;
239
}
301
/**
302
* Get SVG markup with specific width/height.
303
*
304
+ * @param int $width Markup Width.
305
+ * @param int $height Markup Height.
306
+ * @param string|null $url Original URL.
307
*
308
* @return string SVG code.
309
*/
310
+ public function get_svg_for( $width, $height, $url = null ) {
311
+
312
+ if ( $url !== null && ! is_numeric( $width ) ) {
313
+ $url = strtok( $url, '?' );
314
+ $key = crc32( $url );
315
+ $sizes = wp_cache_get( $key, 'optml_sources' );
316
+ if ( $sizes === false ) {
317
+ $filepath = substr( $url, strpos( $url, $this->upload_resource['content_folder'] ) + $this->upload_resource['content_folder_length'] );
318
+ $filepath = WP_CONTENT_DIR . $filepath;
319
+ if ( is_file( $filepath ) ) {
320
+ $sizes = getimagesize( $filepath );
321
+ wp_cache_add( $key, [ $sizes[0], $sizes[1] ], 'optml_sources', DAY_IN_SECONDS );
322
+ }
323
+ }
324
+ list( $width, $height ) = $sizes;
325
+ }
326
+
327
$width = ! is_numeric( $width ) ? '100%' : $width;
328
$height = ! is_numeric( $height ) ? '100%' : $height;
329
330
+ return
331
str_replace(
332
[ '#width#', '#height#' ],
333
[
334
$width,
335
$height,
336
],
337
+ self::SVG_PLACEHOLDER
338
+ );
339
}
340
341
/**
inc/manager.php CHANGED
@@ -145,6 +145,9 @@ final class Optml_Manager {
145
if ( array_key_exists( 'et_fb', $_GET ) && ! empty( $_GET['et_fb'] ) ) {
146
return false; // @codeCoverageIgnore
147
}
148
if ( array_key_exists( 'context', $_GET ) && $_GET['context'] == 'edit' ) {
149
return false; // @codeCoverageIgnore
150
}
145
if ( array_key_exists( 'et_fb', $_GET ) && ! empty( $_GET['et_fb'] ) ) {
146
return false; // @codeCoverageIgnore
147
}
148
+ if ( array_key_exists( 'tve', $_GET ) && $_GET['tve'] == 'true' ) {
149
+ return false; // @codeCoverageIgnore
150
+ }
151
if ( array_key_exists( 'context', $_GET ) && $_GET['context'] == 'edit' ) {
152
return false; // @codeCoverageIgnore
153
}
inc/url_replacer.php CHANGED
@@ -175,7 +175,7 @@ final class Optml_Url_Replacer extends Optml_App_Replacer {
175
$args = apply_filters( 'optml_image_args', $args, $original_url );
176
177
$arguments = [
178
- 'signed' => $this->settings->use_lazyload() ? false : $this->is_allowed_site,
179
'apply_watermark' => apply_filters( 'optml_apply_watermark_for', true, $url ),
180
181
];
175
$args = apply_filters( 'optml_image_args', $args, $original_url );
176
177
$arguments = [
178
+ 'signed' => $this->settings->use_lazyload() ? false : ! $this->is_allowed_site,
179
'apply_watermark' => apply_filters( 'optml_apply_watermark_for', true, $url ),
180
181
];
optimole-wp.php CHANGED
@@ -2,7 +2,7 @@
2
/**
3
* Plugin Name: Image optimization service by Optimole
4
* Description: Complete handling of your website images.
5
- * Version: 2.2.1
6
* Author: Optimole
7
* Author URI: https://optimole.com
8
* License: GPL-2.0+
@@ -75,7 +75,7 @@ function optml() {
75
define( 'OPTML_URL', plugin_dir_url( __FILE__ ) );
76
define( 'OPTML_JS_CDN', 'd5jmkjjpb7yfg.cloudfront.net' );
77
define( 'OPTML_PATH', plugin_dir_path( __FILE__ ) );
78
- define( 'OPTML_VERSION', '2.2.1' );
79
define( 'OPTML_NAMESPACE', 'optml' );
80
define( 'OPTML_BASEFILE', __FILE__ );
81
// Fallback for old PHP versions when this constant is not defined.
2
/**
3
* Plugin Name: Image optimization service by Optimole
4
* Description: Complete handling of your website images.
5
+ * Version: 2.2.2
6
* Author: Optimole
7
* Author URI: https://optimole.com
8
* License: GPL-2.0+
75
define( 'OPTML_URL', plugin_dir_url( __FILE__ ) );
76
define( 'OPTML_JS_CDN', 'd5jmkjjpb7yfg.cloudfront.net' );
77
define( 'OPTML_PATH', plugin_dir_path( __FILE__ ) );
78
+ define( 'OPTML_VERSION', '2.2.2' );
79
define( 'OPTML_NAMESPACE', 'optml' );
80
define( 'OPTML_BASEFILE', __FILE__ );
81
// Fallback for old PHP versions when this constant is not defined.
readme.txt CHANGED
@@ -89,6 +89,17 @@ Premium users will be able to optimize images for more than 25k monthly active u
89
90
== Changelog ==
91
92
#### [Version 2.2.1](https://github.com/Codeinwp/optimole-wp/compare/v2.2.0...v2.2.1) (2019-10-21)
93
94
* **Bug Fixes**
89
90
== Changelog ==
91
92
+ #### [Version 2.2.2](https://github.com/Codeinwp/optimole-wp/compare/v2.2.1...v2.2.2) (2019-11-04)
93
+
94
+ * **Bug Fixes**
95
+ * ignore rescale on GIF and SVG when lazyload is active ([d4e63b6](https://github.com/Codeinwp/optimole-wp/commit/d4e63b6))
96
+ * improve compatibility with Thrive Architect ([55a5952](https://github.com/Codeinwp/optimole-wp/commit/55a5952))
97
+ * improve generic placeholder computed width/height when the source size is unknown ([0c3cc3f](https://github.com/Codeinwp/optimole-wp/commit/0c3cc3f))
98
+ * sign only URLs that don't use an whitelisted domain. ([7813bf9](https://github.com/Codeinwp/optimole-wp/commit/7813bf9))
99
+ * strip retina based prefix to use original url ([948c667](https://github.com/Codeinwp/optimole-wp/commit/948c667))
100
+
101
+
102
+
103
#### [Version 2.2.1](https://github.com/Codeinwp/optimole-wp/compare/v2.2.0...v2.2.1) (2019-10-21)
104
105
* **Bug Fixes**
themeisle-hash.json CHANGED
@@ -1 +1 @@
1
- {"optimole-wp.php":"84f033dfeb05d06ea2df793c500d2826"}
1
+ {"optimole-wp.php":"0ed470bcb2672d46cabfb9686ec89a08"}
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
5
require_once __DIR__ . '/composer/autoload_real.php';
6
7
- return ComposerAutoloaderInit7ce5d1c453ee2878dfe9aca19ec5dc50::getLoader();
4
5
require_once __DIR__ . '/composer/autoload_real.php';
6
7
+ return ComposerAutoloaderInite61b636f227c47a35d771dd885d9769f::getLoader();
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
3
// autoload_real.php @generated by Composer
4
5
- class ComposerAutoloaderInit7ce5d1c453ee2878dfe9aca19ec5dc50
6
{
7
private static $loader;
8
@@ -19,15 +19,15 @@ class ComposerAutoloaderInit7ce5d1c453ee2878dfe9aca19ec5dc50
19
return self::$loader;
20
}
21
22
- spl_autoload_register(array('ComposerAutoloaderInit7ce5d1c453ee2878dfe9aca19ec5dc50', 'loadClassLoader'), true, true);
23
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInit7ce5d1c453ee2878dfe9aca19ec5dc50', 'loadClassLoader'));
25
26
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
if ($useStaticLoader) {
28
require_once __DIR__ . '/autoload_static.php';
29
30
- call_user_func(\Composer\Autoload\ComposerStaticInit7ce5d1c453ee2878dfe9aca19ec5dc50::getInitializer($loader));
31
} else {
32
$map = require __DIR__ . '/autoload_namespaces.php';
33
foreach ($map as $namespace => $path) {
@@ -48,19 +48,19 @@ class ComposerAutoloaderInit7ce5d1c453ee2878dfe9aca19ec5dc50
48
$loader->register(true);
49
50
if ($useStaticLoader) {
51
- $includeFiles = Composer\Autoload\ComposerStaticInit7ce5d1c453ee2878dfe9aca19ec5dc50::$files;
52
} else {
53
$includeFiles = require __DIR__ . '/autoload_files.php';
54
}
55
foreach ($includeFiles as $fileIdentifier => $file) {
56
- composerRequire7ce5d1c453ee2878dfe9aca19ec5dc50($fileIdentifier, $file);
57
}
58
59
return $loader;
60
}
61
}
62
63
- function composerRequire7ce5d1c453ee2878dfe9aca19ec5dc50($fileIdentifier, $file)
64
{
65
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
require $file;
2
3
// autoload_real.php @generated by Composer
4
5
+ class ComposerAutoloaderInite61b636f227c47a35d771dd885d9769f
6
{
7
private static $loader;
8
19
return self::$loader;
20
}
21
22
+ spl_autoload_register(array('ComposerAutoloaderInite61b636f227c47a35d771dd885d9769f', 'loadClassLoader'), true, true);
23
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInite61b636f227c47a35d771dd885d9769f', 'loadClassLoader'));
25
26
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
if ($useStaticLoader) {
28
require_once __DIR__ . '/autoload_static.php';
29
30
+ call_user_func(\Composer\Autoload\ComposerStaticInite61b636f227c47a35d771dd885d9769f::getInitializer($loader));
31
} else {
32
$map = require __DIR__ . '/autoload_namespaces.php';
33
foreach ($map as $namespace => $path) {
48
$loader->register(true);
49
50
if ($useStaticLoader) {
51
+ $includeFiles = Composer\Autoload\ComposerStaticInite61b636f227c47a35d771dd885d9769f::$files;
52
} else {
53
$includeFiles = require __DIR__ . '/autoload_files.php';
54
}
55
foreach ($includeFiles as $fileIdentifier => $file) {
56
+ composerRequiree61b636f227c47a35d771dd885d9769f($fileIdentifier, $file);
57
}
58
59
return $loader;
60
}
61
}
62
63
+ function composerRequiree61b636f227c47a35d771dd885d9769f($fileIdentifier, $file)
64
{
65
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
5
namespace Composer\Autoload;
6
7
- class ComposerStaticInit7ce5d1c453ee2878dfe9aca19ec5dc50
8
{
9
public static $files = array (
10
'9fef4034ed73e26a337d9856ea126f7f' => __DIR__ . '/..' . '/codeinwp/themeisle-sdk/load.php',
4
5
namespace Composer\Autoload;
6
7
+ class ComposerStaticInite61b636f227c47a35d771dd885d9769f
8
{
9
public static $files = array (
10
'9fef4034ed73e26a337d9856ea126f7f' => __DIR__ . '/..' . '/codeinwp/themeisle-sdk/load.php',