EWWW Image Optimizer - Version 6.2.5

Version Description

  • added: Easy IO and Lazy Load support for AJAX responses from FacetWP
  • changed: Vimeo videos excluded from iframe lazy load
  • changed: use 'bg-image-crop' class on elements with CSS background images that need to be cropped by auto-scaling
  • fixed: sub-folder multi-site installs which use separate domains could not activate Easy IO, define EXACTDN_SUB_FOLDER to override
  • fixed: Lazy Load PNG placeholders cannot be cached if the WP_CONTENT_DIR location is read-only (notably on Pantheon servers)
  • fixed: is_amp() called too early
  • fixed: Fusion Builder (Avada) does not load when Lazy Load, WebP, or Easy IO options are enabled
  • fixed: png_alpha() check uses more memory than is available, causing some uploads to fail
Download this release

Release Info

Developer nosilver4u
Plugin Icon 128x128 EWWW Image Optimizer
Version 6.2.5
Comparing to
See all releases

Code changes from version 6.2.4 to 6.2.5

changelog.txt CHANGED
@@ -1,3 +1,13 @@
 
 
 
 
 
 
 
 
 
 
1
  = 6.2.4 =
2
  * added: Multi-site domain-based installs can activate/register sites en masse, and directly upon site creation
3
  * changed: improved db upgrade routine for updated column
1
+ = 6.2.5 =
2
+ * added: Easy IO and Lazy Load support for AJAX responses from FacetWP
3
+ * changed: Vimeo videos excluded from iframe lazy load
4
+ * changed: use 'bg-image-crop' class on elements with CSS background images that need to be cropped by auto-scaling
5
+ * fixed: sub-folder multi-site installs which use separate domains could not activate Easy IO, define EXACTDN_SUB_FOLDER to override
6
+ * fixed: Lazy Load PNG placeholders cannot be cached if the WP_CONTENT_DIR location is read-only (notably on Pantheon servers)
7
+ * fixed: is_amp() called too early
8
+ * fixed: Fusion Builder (Avada) does not load when Lazy Load, WebP, or Easy IO options are enabled
9
+ * fixed: png_alpha() check uses more memory than is available, causing some uploads to fail
10
+
11
  = 6.2.4 =
12
  * added: Multi-site domain-based installs can activate/register sites en masse, and directly upon site creation
13
  * changed: improved db upgrade routine for updated column
classes/class-eio-base.php CHANGED
@@ -99,11 +99,11 @@ if ( ! class_exists( 'EIO_Base' ) ) {
99
  $this->home_domain = $this->parse_url( $this->home_url, PHP_URL_HOST );
100
  if ( strpos( $child_class_path, 'plugins/ewww' ) ) {
101
  $this->content_url = content_url( 'ewww/' );
102
- $this->content_dir = WP_CONTENT_DIR . '/ewww/';
103
  $this->version = EWWW_IMAGE_OPTIMIZER_VERSION;
104
  } elseif ( strpos( $child_class_path, 'plugins/easy' ) ) {
105
  $this->content_url = content_url( 'easyio/' );
106
- $this->content_dir = WP_CONTENT_DIR . '/easyio/';
107
  $this->version = EASYIO_VERSION;
108
  $this->prefix = 'easyio_';
109
  } else {
@@ -122,7 +122,8 @@ if ( ! class_exists( 'EIO_Base' ) ) {
122
  */
123
  $this->content_url();
124
  $this->debug_message( '<b>' . __METHOD__ . '()</b>' );
125
- $this->debug_message( "plugin content_url: $this->content_url" );
 
126
  $this->debug_message( "home url: $this->home_url" );
127
  $this->debug_message( "relative home url: $this->relative_home_url" );
128
  $this->debug_message( "home domain: $this->home_domain" );
@@ -130,6 +131,29 @@ if ( ! class_exists( 'EIO_Base' ) ) {
130
  $this->debug_message( "site/upload domain: $this->upload_domain" );
131
  }
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  /**
134
  * Saves the in-memory debug log to a logfile in the plugin folder.
135
  *
@@ -355,6 +379,12 @@ if ( ! class_exists( 'EIO_Base' ) ) {
355
  * @return bool True for an AMP endpoint, false otherwise.
356
  */
357
  function is_amp() {
 
 
 
 
 
 
358
  if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
359
  return true;
360
  }
99
  $this->home_domain = $this->parse_url( $this->home_url, PHP_URL_HOST );
100
  if ( strpos( $child_class_path, 'plugins/ewww' ) ) {
101
  $this->content_url = content_url( 'ewww/' );
102
+ $this->content_dir = $this->set_content_dir( '/ewww/' );
103
  $this->version = EWWW_IMAGE_OPTIMIZER_VERSION;
104
  } elseif ( strpos( $child_class_path, 'plugins/easy' ) ) {
105
  $this->content_url = content_url( 'easyio/' );
106
+ $this->content_dir = $this->set_content_dir( '/easyio/' );
107
  $this->version = EASYIO_VERSION;
108
  $this->prefix = 'easyio_';
109
  } else {
122
  */
123
  $this->content_url();
124
  $this->debug_message( '<b>' . __METHOD__ . '()</b>' );
125
+ $this->debug_message( "plugin (resource) content_url: $this->content_url" );
126
+ $this->debug_message( "plugin (resource) content_dir: $this->content_dir" );
127
  $this->debug_message( "home url: $this->home_url" );
128
  $this->debug_message( "relative home url: $this->relative_home_url" );
129
  $this->debug_message( "home domain: $this->home_domain" );
131
  $this->debug_message( "site/upload domain: $this->upload_domain" );
132
  }
133
 
134
+ /**
135
+ * Finds a writable location to store plugin resources.
136
+ *
137
+ * Checks to see if the wp-content/ directory is writable, and uses the upload dir
138
+ * as fall-back. If neither location works, the original wp-content/ folder will be
139
+ * used, and other functions will need to make sure the resource folder is writable.
140
+ *
141
+ * @param string $sub_folder The sub-folder to use for plugin resources, with slashes on both ends.
142
+ * @return string The full path to a writable plugin resource folder.
143
+ */
144
+ function set_content_dir( $sub_folder ) {
145
+ $content_dir = WP_CONTENT_DIR . $sub_folder;
146
+ if ( ! is_writable( WP_CONTENT_DIR ) || ! empty( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {
147
+ $upload_dir = wp_get_upload_dir();
148
+ if ( false === strpos( $upload_dir['basedir'], '://' ) && is_writable( $upload_dir['basedir'] ) ) {
149
+ $content_dir = $upload_dir['basedir'] . $sub_folder;
150
+ // Also need to update the corresponding URL.
151
+ $this->content_url = $upload_dir['baseurl'] . $sub_folder;
152
+ }
153
+ }
154
+ return $content_dir;
155
+ }
156
+
157
  /**
158
  * Saves the in-memory debug log to a logfile in the plugin folder.
159
  *
379
  * @return bool True for an AMP endpoint, false otherwise.
380
  */
381
  function is_amp() {
382
+ if ( ! did_action( 'parse_query' ) ) {
383
+ return false;
384
+ }
385
+ if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
386
+ return true;
387
+ }
388
  if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
389
  return true;
390
  }
classes/class-eio-js-webp.php CHANGED
@@ -154,6 +154,9 @@ class EIO_JS_Webp extends EIO_Page_Parser {
154
  if ( false !== strpos( $uri, '?brizy-edit' ) ) {
155
  return false;
156
  }
 
 
 
157
  if ( false !== strpos( $uri, 'cornerstone=' ) || false !== strpos( $uri, 'cornerstone-endpoint' ) ) {
158
  return false;
159
  }
@@ -172,6 +175,9 @@ class EIO_JS_Webp extends EIO_Page_Parser {
172
  if ( false !== strpos( $uri, 'et_fb=' ) ) {
173
  return false;
174
  }
 
 
 
175
  if ( false !== strpos( $uri, '?fl_builder' ) ) {
176
  return false;
177
  }
@@ -187,8 +193,15 @@ class EIO_JS_Webp extends EIO_Page_Parser {
187
  if ( ! empty( $_POST['action'] ) && 'tatsu_get_concepts' === sanitize_text_field( wp_unslash( $_POST['action'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
188
  return false;
189
  }
 
 
 
 
190
  global $wp_query;
191
- if ( ! isset( $wp_query ) ) {
 
 
 
192
  return $should_process;
193
  }
194
  if ( $this->is_amp() ) {
@@ -202,10 +215,6 @@ class EIO_JS_Webp extends EIO_Page_Parser {
202
  $this->debug_message( 'is_feed' );
203
  return false;
204
  }
205
- if ( is_customize_preview() ) {
206
- $this->debug_message( 'is_customize_preview' );
207
- return false;
208
- }
209
  if ( is_preview() ) {
210
  $this->debug_message( 'is_preview' );
211
  return false;
@@ -356,7 +365,7 @@ class EIO_JS_Webp extends EIO_Page_Parser {
356
  }
357
 
358
  $body_tags = $this->get_elements_from_html( $buffer, 'body' );
359
- $body_webp_script = '<script>if(ewww_webp_supported){document.body.classList.add("webp-support");}</script>';
360
  if ( $this->is_iterable( $body_tags ) && ! empty( $body_tags[0] ) && false !== strpos( $body_tags[0], '<body' ) ) {
361
  // Add the WebP script right after the opening tag.
362
  $buffer = str_replace( $body_tags[0], $body_tags[0] . "\n" . $body_webp_script, $buffer );
154
  if ( false !== strpos( $uri, '?brizy-edit' ) ) {
155
  return false;
156
  }
157
+ if ( false !== strpos( $uri, '&builder=true' ) ) {
158
+ return false;
159
+ }
160
  if ( false !== strpos( $uri, 'cornerstone=' ) || false !== strpos( $uri, 'cornerstone-endpoint' ) ) {
161
  return false;
162
  }
175
  if ( false !== strpos( $uri, 'et_fb=' ) ) {
176
  return false;
177
  }
178
+ if ( false !== strpos( $uri, 'fb-edit=' ) ) {
179
+ return false;
180
+ }
181
  if ( false !== strpos( $uri, '?fl_builder' ) ) {
182
  return false;
183
  }
193
  if ( ! empty( $_POST['action'] ) && 'tatsu_get_concepts' === sanitize_text_field( wp_unslash( $_POST['action'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
194
  return false;
195
  }
196
+ if ( is_customize_preview() ) {
197
+ $this->debug_message( 'is_customize_preview' );
198
+ return false;
199
+ }
200
  global $wp_query;
201
+ if ( ! isset( $wp_query ) || ! ( $wp_query instanceof WP_Query ) ) {
202
+ return $should_process;
203
+ }
204
+ if ( ! did_action( 'parse_query' ) ) {
205
  return $should_process;
206
  }
207
  if ( $this->is_amp() ) {
215
  $this->debug_message( 'is_feed' );
216
  return false;
217
  }
 
 
 
 
218
  if ( is_preview() ) {
219
  $this->debug_message( 'is_preview' );
220
  return false;
365
  }
366
 
367
  $body_tags = $this->get_elements_from_html( $buffer, 'body' );
368
+ $body_webp_script = '<script data-cfasync="false">if(ewww_webp_supported){document.body.classList.add("webp-support");}</script>';
369
  if ( $this->is_iterable( $body_tags ) && ! empty( $body_tags[0] ) && false !== strpos( $body_tags[0], '<body' ) ) {
370
  // Add the WebP script right after the opening tag.
371
  $buffer = str_replace( $body_tags[0], $body_tags[0] . "\n" . $body_webp_script, $buffer );
classes/class-eio-lazy-load.php CHANGED
@@ -111,6 +111,9 @@ if ( ! class_exists( 'EIO_Lazy_Load' ) ) {
111
 
112
  add_filter( 'vc_get_vc_grid_data_response', array( $this, 'filter_page_output' ) );
113
 
 
 
 
114
  if ( class_exists( 'ExactDN' ) && $this->get_option( $this->prefix . 'exactdn' ) ) {
115
  global $exactdn;
116
  $this->exactdn_domain = $exactdn->get_exactdn_domain();
@@ -189,6 +192,9 @@ if ( ! class_exists( 'EIO_Lazy_Load' ) ) {
189
  if ( false !== strpos( $uri, '?brizy-edit' ) ) {
190
  return false;
191
  }
 
 
 
192
  if ( false !== strpos( $uri, 'cornerstone=' ) || false !== strpos( $uri, 'cornerstone-endpoint' ) ) {
193
  return false;
194
  }
@@ -207,6 +213,9 @@ if ( ! class_exists( 'EIO_Lazy_Load' ) ) {
207
  if ( false !== strpos( $uri, 'et_fb=' ) ) {
208
  return false;
209
  }
 
 
 
210
  if ( false !== strpos( $uri, '?fl_builder' ) ) {
211
  return false;
212
  }
@@ -222,8 +231,15 @@ if ( ! class_exists( 'EIO_Lazy_Load' ) ) {
222
  if ( ! empty( $_POST['action'] ) && 'tatsu_get_concepts' === sanitize_text_field( wp_unslash( $_POST['action'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
223
  return false;
224
  }
 
 
 
 
225
  global $wp_query;
226
- if ( ! isset( $wp_query ) ) {
 
 
 
227
  return $should_process;
228
  }
229
  if ( $this->is_amp() ) {
@@ -237,10 +253,6 @@ if ( ! class_exists( 'EIO_Lazy_Load' ) ) {
237
  $this->debug_message( 'is_feed' );
238
  return false;
239
  }
240
- if ( is_customize_preview() ) {
241
- $this->debug_message( 'is_customize_preview' );
242
- return false;
243
- }
244
  if ( is_preview() ) {
245
  $this->debug_message( 'is_preview' );
246
  return false;
@@ -298,7 +310,7 @@ if ( ! class_exists( 'EIO_Lazy_Load' ) ) {
298
  // If JS WebP isn't running, set ewww_webp_supported to false so we have something defined.
299
  if ( ! class_exists( 'EIO_JS_Webp' ) ) {
300
  $body_tags = $this->get_elements_from_html( $buffer, 'body' );
301
- $body_webp_script = '<script>var ewww_webp_supported=false;</script>';
302
  if ( $this->is_iterable( $body_tags ) && ! empty( $body_tags[0] ) && false !== strpos( $body_tags[0], '<body' ) ) {
303
  // Add the WebP script right after the opening tag.
304
  $buffer = str_replace( $body_tags[0], $body_tags[0] . "\n" . $body_webp_script, $buffer );
@@ -710,6 +722,32 @@ if ( ! class_exists( 'EIO_Lazy_Load' ) ) {
710
  return $element;
711
  }
712
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
713
  /**
714
  * Validate the user-defined exclusions.
715
  */
@@ -889,6 +927,7 @@ if ( ! class_exists( 'EIO_Lazy_Load' ) ) {
889
  'data-no-lazy=',
890
  'lazyload',
891
  'skip-lazy',
 
892
  'about:blank',
893
  ),
894
  $this->user_exclusions
111
 
112
  add_filter( 'vc_get_vc_grid_data_response', array( $this, 'filter_page_output' ) );
113
 
114
+ // Filter for FacetWP JSON responses.
115
+ add_filter( 'facetwp_render_output', array( $this, 'filter_facetwp_json_output' ) );
116
+
117
  if ( class_exists( 'ExactDN' ) && $this->get_option( $this->prefix . 'exactdn' ) ) {
118
  global $exactdn;
119
  $this->exactdn_domain = $exactdn->get_exactdn_domain();
192
  if ( false !== strpos( $uri, '?brizy-edit' ) ) {
193
  return false;
194
  }
195
+ if ( false !== strpos( $uri, '&builder=true' ) ) {
196
+ return false;
197
+ }
198
  if ( false !== strpos( $uri, 'cornerstone=' ) || false !== strpos( $uri, 'cornerstone-endpoint' ) ) {
199
  return false;
200
  }
213
  if ( false !== strpos( $uri, 'et_fb=' ) ) {
214
  return false;
215
  }
216
+ if ( false !== strpos( $uri, 'fb-edit=' ) ) {
217
+ return false;
218
+ }
219
  if ( false !== strpos( $uri, '?fl_builder' ) ) {
220
  return false;
221
  }
231
  if ( ! empty( $_POST['action'] ) && 'tatsu_get_concepts' === sanitize_text_field( wp_unslash( $_POST['action'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
232
  return false;
233
  }
234
+ if ( is_customize_preview() ) {
235
+ $this->debug_message( 'is_customize_preview' );
236
+ return false;
237
+ }
238
  global $wp_query;
239
+ if ( ! isset( $wp_query ) || ! ( $wp_query instanceof WP_Query ) ) {
240
+ return $should_process;
241
+ }
242
+ if ( ! did_action( 'parse_query' ) ) {
243
  return $should_process;
244
  }
245
  if ( $this->is_amp() ) {
253
  $this->debug_message( 'is_feed' );
254
  return false;
255
  }
 
 
 
 
256
  if ( is_preview() ) {
257
  $this->debug_message( 'is_preview' );
258
  return false;
310
  // If JS WebP isn't running, set ewww_webp_supported to false so we have something defined.
311
  if ( ! class_exists( 'EIO_JS_Webp' ) ) {
312
  $body_tags = $this->get_elements_from_html( $buffer, 'body' );
313
+ $body_webp_script = '<script data-cfasync="false">var ewww_webp_supported=false;</script>';
314
  if ( $this->is_iterable( $body_tags ) && ! empty( $body_tags[0] ) && false !== strpos( $body_tags[0], '<body' ) ) {
315
  // Add the WebP script right after the opening tag.
316
  $buffer = str_replace( $body_tags[0], $body_tags[0] . "\n" . $body_webp_script, $buffer );
722
  return $element;
723
  }
724
 
725
+ /**
726
+ * Parse template data from FacetWP that will be included in JSON response.
727
+ * https://facetwp.com/documentation/developers/output/facetwp_render_output/
728
+ *
729
+ * @param array $output The full array of FacetWP data.
730
+ * @return array The FacetWP data with lazy loaded images.
731
+ */
732
+ function filter_facetwp_json_output( $output ) {
733
+ $this->debug_message( '<b>' . __METHOD__ . '()</b>' );
734
+ if ( empty( $output['template'] ) || ! is_string( $output['template'] ) ) {
735
+ $this->debug_message( 'no template data available' );
736
+ if ( $this->function_exists( 'print_r' ) ) {
737
+ $this->debug_message( print_r( $output, true ) );
738
+ }
739
+ return $output;
740
+ }
741
+
742
+ $template = $this->filter_page_output( $output['template'] );
743
+ if ( $template ) {
744
+ $this->debug_message( 'template data modified' );
745
+ $output['template'] = $template;
746
+ }
747
+
748
+ return $output;
749
+ }
750
+
751
  /**
752
  * Validate the user-defined exclusions.
753
  */
927
  'data-no-lazy=',
928
  'lazyload',
929
  'skip-lazy',
930
+ 'vimeo',
931
  'about:blank',
932
  ),
933
  $this->user_exclusions
classes/class-eio-picture-webp.php CHANGED
@@ -114,6 +114,9 @@ class EIO_Picture_Webp extends EIO_Page_Parser {
114
  if ( false !== strpos( $uri, '?brizy-edit' ) ) {
115
  return false;
116
  }
 
 
 
117
  if ( false !== strpos( $uri, 'cornerstone=' ) || false !== strpos( $uri, 'cornerstone-endpoint' ) ) {
118
  return false;
119
  }
@@ -132,6 +135,9 @@ class EIO_Picture_Webp extends EIO_Page_Parser {
132
  if ( false !== strpos( $uri, 'et_fb=' ) ) {
133
  return false;
134
  }
 
 
 
135
  if ( false !== strpos( $uri, '?fl_builder' ) ) {
136
  return false;
137
  }
@@ -147,8 +153,15 @@ class EIO_Picture_Webp extends EIO_Page_Parser {
147
  if ( ! empty( $_POST['action'] ) && 'tatsu_get_concepts' === sanitize_text_field( wp_unslash( $_POST['action'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
148
  return false;
149
  }
 
 
 
 
150
  global $wp_query;
151
- if ( ! isset( $wp_query ) ) {
 
 
 
152
  return $should_process;
153
  }
154
  if ( $this->is_amp() ) {
@@ -162,10 +175,6 @@ class EIO_Picture_Webp extends EIO_Page_Parser {
162
  $this->debug_message( 'is_feed' );
163
  return false;
164
  }
165
- if ( is_customize_preview() ) {
166
- $this->debug_message( 'is_customize_preview' );
167
- return false;
168
- }
169
  if ( is_preview() ) {
170
  $this->debug_message( 'is_preview' );
171
  return false;
114
  if ( false !== strpos( $uri, '?brizy-edit' ) ) {
115
  return false;
116
  }
117
+ if ( false !== strpos( $uri, '&builder=true' ) ) {
118
+ return false;
119
+ }
120
  if ( false !== strpos( $uri, 'cornerstone=' ) || false !== strpos( $uri, 'cornerstone-endpoint' ) ) {
121
  return false;
122
  }
135
  if ( false !== strpos( $uri, 'et_fb=' ) ) {
136
  return false;
137
  }
138
+ if ( false !== strpos( $uri, 'fb-edit=' ) ) {
139
+ return false;
140
+ }
141
  if ( false !== strpos( $uri, '?fl_builder' ) ) {
142
  return false;
143
  }
153
  if ( ! empty( $_POST['action'] ) && 'tatsu_get_concepts' === sanitize_text_field( wp_unslash( $_POST['action'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
154
  return false;
155
  }
156
+ if ( is_customize_preview() ) {
157
+ $this->debug_message( 'is_customize_preview' );
158
+ return false;
159
+ }
160
  global $wp_query;
161
+ if ( ! isset( $wp_query ) || ! ( $wp_query instanceof WP_Query ) ) {
162
+ return $should_process;
163
+ }
164
+ if ( ! did_action( 'parse_query' ) ) {
165
  return $should_process;
166
  }
167
  if ( $this->is_amp() ) {
175
  $this->debug_message( 'is_feed' );
176
  return false;
177
  }
 
 
 
 
178
  if ( is_preview() ) {
179
  $this->debug_message( 'is_preview' );
180
  return false;
classes/class-exactdn.php CHANGED
@@ -72,6 +72,14 @@ if ( ! class_exists( 'ExactDN' ) ) {
72
  */
73
  private $exactdn_domain = false;
74
 
 
 
 
 
 
 
 
 
75
  /**
76
  * The Easy IO Plan/Tier ID
77
  *
@@ -121,6 +129,25 @@ if ( ! class_exists( 'ExactDN' ) ) {
121
  return;
122
  }
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  if ( ! $this->scheme ) {
125
  $site_url = get_home_url();
126
  $scheme = 'http';
@@ -139,23 +166,25 @@ if ( ! class_exists( 'ExactDN' ) ) {
139
  $this->scheme = $scheme;
140
  }
141
 
142
- $uri = add_query_arg( null, null );
143
- $this->debug_message( "request uri is $uri" );
144
-
145
- if ( '/robots.txt' === $uri || '/sitemap.xml' === $uri ) {
146
- return;
147
- }
148
-
149
- add_filter( 'exactdn_skip_page', array( $this, 'skip_page' ), 10, 2 );
150
-
151
- /**
152
- * Allow pre-empting the parsers by page.
153
- *
154
- * @param bool Whether to skip parsing the page.
155
- * @param string $uri The URL of the page.
156
- */
157
- if ( apply_filters( 'exactdn_skip_page', false, $uri ) ) {
158
- return;
 
 
159
  }
160
 
161
  // Make sure we have an ExactDN domain to use.
@@ -200,8 +229,6 @@ if ( ! class_exists( 'ExactDN' ) ) {
200
  add_filter( 'wp_calculate_image_srcset', array( $this, 'filter_srcset_array' ), 1001, 5 );
201
  add_filter( 'wp_calculate_image_sizes', array( $this, 'filter_sizes' ), 1, 2 ); // Early so themes can still filter.
202
 
203
- /* add_filter( 'fl_builder_render_assets_inline', '__return_true' ); */
204
-
205
  // Filter for FacetWP JSON responses.
206
  add_filter( 'facetwp_render_output', array( $this, 'filter_facetwp_json_output' ) );
207
 
@@ -652,7 +679,7 @@ if ( ! class_exists( 'ExactDN' ) ) {
652
  return $this->sanitize_domain( EXACTDN_DOMAIN );
653
  }
654
  if ( is_multisite() ) {
655
- if ( ! SUBDOMAIN_INSTALL ) {
656
  return $this->sanitize_domain( get_site_option( $this->prefix . 'exactdn_domain' ) );
657
  }
658
  }
@@ -681,7 +708,7 @@ if ( ! class_exists( 'ExactDN' ) ) {
681
  return get_option( $this->prefix . 'exactdn_' . $option_name );
682
  }
683
  if ( is_multisite() ) {
684
- if ( ! SUBDOMAIN_INSTALL ) {
685
  return get_site_option( $this->prefix . 'exactdn_' . $option_name );
686
  }
687
  }
@@ -703,7 +730,7 @@ if ( ! class_exists( 'ExactDN' ) ) {
703
  return false;
704
  }
705
  if ( is_multisite() ) {
706
- if ( ! SUBDOMAIN_INSTALL ) {
707
  update_site_option( $this->prefix . 'exactdn_domain', $domain );
708
  return $domain;
709
  }
@@ -725,7 +752,7 @@ if ( ! class_exists( 'ExactDN' ) ) {
725
  return update_option( $this->prefix . 'exactdn_' . $option_name, $option_value, $autoload );
726
  }
727
  if ( is_multisite() ) {
728
- if ( ! SUBDOMAIN_INSTALL ) {
729
  return update_site_option( $this->prefix . 'exactdn_' . $option_name, $option_value );
730
  }
731
  }
@@ -2946,24 +2973,30 @@ if ( ! class_exists( 'ExactDN' ) ) {
2946
  if ( false !== strpos( $uri, '?brizy-edit' ) ) {
2947
  return true;
2948
  }
 
 
 
2949
  if ( false !== strpos( $uri, 'cornerstone=' ) || false !== strpos( $uri, 'cornerstone-endpoint' ) ) {
2950
  return true;
2951
  }
2952
- if ( false !== strpos( $uri, 'et_fb=' ) ) {
2953
  return true;
2954
  }
2955
- if ( false !== strpos( $uri, 'tatsu=' ) ) {
2956
  return true;
2957
  }
2958
- if ( false !== strpos( $uri, 'ct_builder=' ) ) {
2959
  return true;
2960
  }
2961
- if ( false !== strpos( $uri, 'ct_render_shortcode=' ) || false !== strpos( $uri, 'action=oxy_render' ) ) {
2962
  return true;
2963
  }
2964
  if ( false !== strpos( $uri, '?fl_builder' ) ) {
2965
  return true;
2966
  }
 
 
 
2967
  return $skip;
2968
  }
2969
 
72
  */
73
  private $exactdn_domain = false;
74
 
75
+ /**
76
+ * Is this a sub-folder network/multi-site install?
77
+ *
78
+ * @access private
79
+ * @var bool $sub_folder
80
+ */
81
+ private $sub_folder = false;
82
+
83
  /**
84
  * The Easy IO Plan/Tier ID
85
  *
129
  return;
130
  }
131
 
132
+ $uri = add_query_arg( null, null );
133
+ $this->debug_message( "request uri is $uri" );
134
+
135
+ if ( '/robots.txt' === $uri || '/sitemap.xml' === $uri ) {
136
+ return;
137
+ }
138
+
139
+ add_filter( 'exactdn_skip_page', array( $this, 'skip_page' ), 10, 2 );
140
+
141
+ /**
142
+ * Allow pre-empting the parsers by page.
143
+ *
144
+ * @param bool Whether to skip parsing the page.
145
+ * @param string $uri The URL of the page.
146
+ */
147
+ if ( apply_filters( 'exactdn_skip_page', false, $uri ) ) {
148
+ return;
149
+ }
150
+
151
  if ( ! $this->scheme ) {
152
  $site_url = get_home_url();
153
  $scheme = 'http';
166
  $this->scheme = $scheme;
167
  }
168
 
169
+ if ( is_multisite() && defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) {
170
+ $this->debug_message( 'working in sub-domain mode' );
171
+ } elseif ( is_multisite() ) {
172
+ if ( defined( 'EXACTDN_SUB_FOLDER' ) && EXACTDN_SUB_FOLDER ) {
173
+ $this->sub_folder = true;
174
+ $this->debug_message( 'working in sub-folder mode due to constant override' );
175
+ } elseif ( defined( 'EXACTDN_SUB_FOLDER' ) ) {
176
+ $this->debug_message( 'working in sub-domain mode due to constant override' );
177
+ } elseif ( get_site_option( 'exactdn_sub_folder' ) ) {
178
+ $this->sub_folder = true;
179
+ $this->debug_message( 'working in sub-folder mode due to global option' );
180
+ } elseif ( get_current_blog_id() > 1 ) {
181
+ $network_site_url = network_site_url();
182
+ $network_domain = $this->parse_url( $network_site_url, PHP_URL_HOST );
183
+ if ( $network_domain === $this->upload_domain ) {
184
+ $this->sub_folder = true;
185
+ $this->debug_message( 'working in sub-folder mode due to matching domain' );
186
+ }
187
+ }
188
  }
189
 
190
  // Make sure we have an ExactDN domain to use.
229
  add_filter( 'wp_calculate_image_srcset', array( $this, 'filter_srcset_array' ), 1001, 5 );
230
  add_filter( 'wp_calculate_image_sizes', array( $this, 'filter_sizes' ), 1, 2 ); // Early so themes can still filter.
231
 
 
 
232
  // Filter for FacetWP JSON responses.
233
  add_filter( 'facetwp_render_output', array( $this, 'filter_facetwp_json_output' ) );
234
 
679
  return $this->sanitize_domain( EXACTDN_DOMAIN );
680
  }
681
  if ( is_multisite() ) {
682
+ if ( $this->sub_folder ) {
683
  return $this->sanitize_domain( get_site_option( $this->prefix . 'exactdn_domain' ) );
684
  }
685
  }
708
  return get_option( $this->prefix . 'exactdn_' . $option_name );
709
  }
710
  if ( is_multisite() ) {
711
+ if ( $this->sub_folder ) {
712
  return get_site_option( $this->prefix . 'exactdn_' . $option_name );
713
  }
714
  }
730
  return false;
731
  }
732
  if ( is_multisite() ) {
733
+ if ( $this->sub_folder ) {
734
  update_site_option( $this->prefix . 'exactdn_domain', $domain );
735
  return $domain;
736
  }
752
  return update_option( $this->prefix . 'exactdn_' . $option_name, $option_value, $autoload );
753
  }
754
  if ( is_multisite() ) {
755
+ if ( $this->sub_folder ) {
756
  return update_site_option( $this->prefix . 'exactdn_' . $option_name, $option_value );
757
  }
758
  }
2973
  if ( false !== strpos( $uri, '?brizy-edit' ) ) {
2974
  return true;
2975
  }
2976
+ if ( false !== strpos( $uri, '&builder=true' ) ) {
2977
+ return true;
2978
+ }
2979
  if ( false !== strpos( $uri, 'cornerstone=' ) || false !== strpos( $uri, 'cornerstone-endpoint' ) ) {
2980
  return true;
2981
  }
2982
+ if ( false !== strpos( $uri, 'ct_builder=' ) ) {
2983
  return true;
2984
  }
2985
+ if ( false !== strpos( $uri, 'ct_render_shortcode=' ) || false !== strpos( $uri, 'action=oxy_render' ) ) {
2986
  return true;
2987
  }
2988
+ if ( false !== strpos( $uri, 'et_fb=' ) ) {
2989
  return true;
2990
  }
2991
+ if ( false !== strpos( $uri, 'fb-edit=' ) ) {
2992
  return true;
2993
  }
2994
  if ( false !== strpos( $uri, '?fl_builder' ) ) {
2995
  return true;
2996
  }
2997
+ if ( false !== strpos( $uri, 'tatsu=' ) ) {
2998
+ return true;
2999
+ }
3000
  return $skip;
3001
  }
3002
 
common.php CHANGED
@@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
14
  exit;
15
  }
16
 
17
- define( 'EWWW_IMAGE_OPTIMIZER_VERSION', '624' );
18
 
19
  // Initialize a couple globals.
20
  $eio_debug = '';
@@ -736,17 +736,6 @@ function ewww_image_optimizer_save_network_settings() {
736
  $ewww_image_optimizer_allow_tracking = empty( $_POST['ewww_image_optimizer_allow_tracking'] ) ? false : $ewwwio_tracking->check_for_settings_optin( (bool) $_POST['ewww_image_optimizer_allow_tracking'] );
737
  update_site_option( 'ewww_image_optimizer_allow_tracking', $ewww_image_optimizer_allow_tracking );
738
  add_action( 'network_admin_notices', 'ewww_image_optimizer_network_settings_saved' );
739
- // TODO: we probably don't need this bit anymore with the new multi-site activation.
740
- if ( ! empty( $_POST['ewww_image_optimizer_exactdn'] ) && ! class_exists( 'ExactDN' ) ) {
741
- /**
742
- * Page Parsing class for working with HTML content.
743
- */
744
- require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'classes/class-eio-page-parser.php' );
745
- /**
746
- * ExactDN class for parsing image urls and rewriting them.
747
- */
748
- require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'classes/class-exactdn.php' );
749
- }
750
  } elseif (
751
  isset( $_POST['ewww_image_optimizer_allow_multisite_override_active'] ) &&
752
  current_user_can( 'manage_network_options' ) &&
@@ -3142,9 +3131,10 @@ function ewww_image_optimizer_settings_link( $links ) {
3142
  /**
3143
  * Check for GD support of both PNG and JPG.
3144
  *
 
3145
  * @return string The version of GD if full support is detected.
3146
  */
3147
- function ewww_image_optimizer_gd_support() {
3148
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
3149
  if ( function_exists( 'gd_info' ) ) {
3150
  $gd_support = gd_info();
@@ -3416,6 +3406,7 @@ function ewww_image_optimizer_add_file_exclusion( $file_path ) {
3416
  $ignore_folders[] = $file_path;
3417
  ewww_image_optimizer_set_option( 'ewww_image_optimizer_exclude_paths', $ignore_folders );
3418
  }
 
3419
  /**
3420
  * Sanitize the list of disabled resizes.
3421
  *
@@ -4702,10 +4693,14 @@ function ewww_image_optimizer_exactdn_activate_ajax() {
4702
  if ( empty( $_REQUEST['ewww_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['ewww_wpnonce'] ), 'ewww-image-optimizer-settings' ) ) {
4703
  die( wp_json_encode( array( 'error' => esc_html__( 'Access token has expired, please reload the page.', 'ewww-image-optimizer' ) ) ) );
4704
  }
4705
- if ( is_multisite() && defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) {
 
 
4706
  update_option( 'ewww_image_optimizer_exactdn', true );
 
 
4707
  } else {
4708
- ewww_image_optimizer_set_option( 'ewww_image_optimizer_exactdn', true );
4709
  }
4710
  if ( ! class_exists( 'ExactDN' ) ) {
4711
  /**
@@ -6729,6 +6724,11 @@ function ewww_image_optimizer_remote_fetch( $id, $meta ) {
6729
  }
6730
  ewwwio_debug_message( "S3 Uploads fullsize path: $s3_path" );
6731
  ewwwio_debug_message( "unfiltered fullsize path: $filename" );
 
 
 
 
 
6732
  if ( ! is_dir( dirname( $filename ) ) ) {
6733
  wp_mkdir_p( dirname( $filename ) );
6734
  }
@@ -7463,8 +7463,8 @@ function ewww_image_optimizer_resize_upload( $file ) {
7463
  } else {
7464
  list( $newwidth, $newheight ) = wp_constrain_dimensions( $oldwidth, $oldheight, $maxwidth, $maxheight );
7465
  }
7466
- if ( ! ewwwio_check_memory_available( ( $oldwidth * $oldwidth + $newwidth * $newheight ) * 4.8 ) ) { // 4.8 = 24-bit or 3 bytes per pixel multiplied by a factor of 1.6 for extra wiggle room.
7467
- $memory_required = ( $oldwidth * $oldwidth + $newwidth * $newheight ) * 4.8;
7468
  ewwwio_debug_message( "possibly insufficient memory for resizing operation: $memory_required" );
7469
  if ( function_exists( 'wp_raise_memory_limit' ) ) {
7470
  add_filter( 'image_memory_limit', 'ewww_image_optimizer_raise_memory_limit' );
@@ -9109,24 +9109,26 @@ function ewww_image_optimizer_png_alpha( $filename ) {
9109
  if ( false !== strpos( $filename, '../' ) ) {
9110
  return false;
9111
  }
9112
- global $eio_filesystem;
9113
- ewwwio_get_filesystem();
9114
- $file_contents = $eio_filesystem->get_contents( $filename );
9115
- // Determine what color type is stored in the file.
9116
- $color_type = ord( substr( $file_contents, 25, 1 ) );
9117
- ewwwio_debug_message( "color type: $color_type" );
9118
- // If we do not have GD and the PNG color type is RGB alpha or Grayscale alpha.
9119
- if ( ! ewww_image_optimizer_gd_support() && ( 4 === $color_type || 6 === $color_type ) ) {
9120
- ewwwio_debug_message( 'transparency found' );
9121
- return true;
 
 
 
 
9122
  } elseif ( ewww_image_optimizer_gd_support() ) {
9123
  $image = imagecreatefrompng( $filename );
9124
  if ( imagecolortransparent( $image ) >= 0 ) {
9125
  ewwwio_debug_message( 'transparency found' );
9126
  return true;
9127
  }
9128
- list( $width, $height ) = wp_getimagesize( $filename );
9129
- ewwwio_debug_message( "image dimensions: $width x $height" );
9130
  ewwwio_debug_message( 'preparing to scan image' );
9131
  for ( $y = 0; $y < $height; $y++ ) {
9132
  for ( $x = 0; $x < $width; $x++ ) {
@@ -11041,7 +11043,7 @@ function ewwwio_debug_info() {
11041
  } else {
11042
  ewwwio_debug_message( 'not external cache' );
11043
  }
11044
- ewww_image_optimizer_gd_support();
11045
  ewww_image_optimizer_gmagick_support();
11046
  ewww_image_optimizer_imagick_support();
11047
  if ( PHP_OS !== 'WINNT' && ! ewww_image_optimizer_full_cloud() && ! EWWW_IMAGE_OPTIMIZER_NOEXEC ) {
@@ -11757,6 +11759,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
11757
  global $eio_hs_beacon;
11758
  global $exactdn;
11759
  global $eio_alt_webp;
 
11760
  $total_savings = 0;
11761
  if ( 'network-multisite' === $network ) {
11762
  $total_sizes = ewww_image_optimizer_savings();
@@ -11770,6 +11773,45 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
11770
  $debug_info = $eio_debug;
11771
  ewww_image_optimizer_temp_debug_clear();
11772
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11773
  if ( empty( $network ) ) {
11774
  $network = 'singlesite';
11775
  }
@@ -11871,7 +11913,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
11871
  $speed_score += 20;
11872
  }
11873
  $exactdn_enabled = true;
11874
- if ( is_multisite() && is_network_admin() && defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) {
11875
  $exactdn_savings = 0;
11876
  } else {
11877
  $exactdn_savings = $exactdn->savings();
@@ -11897,7 +11939,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
11897
  delete_site_option( 'ewww_image_optimizer_exactdn_suspended' );
11898
  }
11899
  $exactdn_network_enabled = 0;
11900
- if ( $exactdn_enabled && is_multisite() && is_network_admin() && defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) {
11901
  $exactdn_network_enabled = ewww_image_optimizer_easyio_network_activated();
11902
  }
11903
  $easymode = false;
@@ -12510,7 +12552,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
12510
  <p style='color: red'><?php esc_html_e( 'Inactive, please disable the Image Accelerator option on the Jetpack Dashboard.', 'ewww-image-optimizer' ); ?></p>
12511
  <?php elseif ( false !== strpos( $easyio_site_url, 'localhost' ) ) : ?>
12512
  <p class="description" style="font-weight: bolder"><?php esc_html_e( 'Easy IO cannot be activated on localhost installs.', 'ewww-image-optimizer' ); ?></p>
12513
- <?php elseif ( 'network-multisite' === $network && defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) : ?>
12514
  <?php if ( 1 > $exactdn_network_enabled ) : ?>
12515
  <p class="ewwwio-easy-setup-instructions">
12516
  <?php if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) : ?>
@@ -13434,7 +13476,7 @@ AddType image/webp .webp</pre>
13434
  <?php ob_end_clean(); ?>
13435
  <div id='ewww-resize-settings'>
13436
  <table class='form-table'>
13437
- <?php echo ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ? wp_kses_post( $exactdn_settings_row ) : '' ); ?>
13438
  <?php endif; ?>
13439
  <!-- RIGHT HERE is where we begin/clear buffer for network-singlesite (non-override version). -->
13440
  <!-- Though the buffer will need to be started right the form begins. -->
@@ -13807,7 +13849,8 @@ function ewww_image_optimizer_easyio_network_activated() {
13807
  if ( ewww_image_optimizer_iterable( $blogs ) ) {
13808
  foreach ( $blogs as $blog ) {
13809
  $total++;
13810
- switch_to_blog( $blog['blog_id'] );
 
13811
  if ( get_option( 'ewww_image_optimizer_exactdn' ) && get_option( 'ewww_image_optimizer_exactdn_verified' ) ) {
13812
  ewwwio_debug_message( "blog $blog_id active" );
13813
  $active++;
@@ -14019,6 +14062,12 @@ function ewww_image_optimizer_autoptimize_js_exclude( $jsexcludes = '', $content
14019
  * @return bool True for an AMP endpoint, false otherwise.
14020
  */
14021
  function ewww_image_optimizer_is_amp() {
 
 
 
 
 
 
14022
  if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
14023
  return true;
14024
  }
14
  exit;
15
  }
16
 
17
+ define( 'EWWW_IMAGE_OPTIMIZER_VERSION', '625' );
18
 
19
  // Initialize a couple globals.
20
  $eio_debug = '';
736
  $ewww_image_optimizer_allow_tracking = empty( $_POST['ewww_image_optimizer_allow_tracking'] ) ? false : $ewwwio_tracking->check_for_settings_optin( (bool) $_POST['ewww_image_optimizer_allow_tracking'] );
737
  update_site_option( 'ewww_image_optimizer_allow_tracking', $ewww_image_optimizer_allow_tracking );
738
  add_action( 'network_admin_notices', 'ewww_image_optimizer_network_settings_saved' );
 
 
 
 
 
 
 
 
 
 
 
739
  } elseif (
740
  isset( $_POST['ewww_image_optimizer_allow_multisite_override_active'] ) &&
741
  current_user_can( 'manage_network_options' ) &&
3131
  /**
3132
  * Check for GD support of both PNG and JPG.
3133
  *
3134
+ * @param bool $cache Whether to use a cached result.
3135
  * @return string The version of GD if full support is detected.
3136
  */
3137
+ function ewww_image_optimizer_gd_support( $cache = true ) {
3138
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
3139
  if ( function_exists( 'gd_info' ) ) {
3140
  $gd_support = gd_info();
3406
  $ignore_folders[] = $file_path;
3407
  ewww_image_optimizer_set_option( 'ewww_image_optimizer_exclude_paths', $ignore_folders );
3408
  }
3409
+
3410
  /**
3411
  * Sanitize the list of disabled resizes.
3412
  *
4693
  if ( empty( $_REQUEST['ewww_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['ewww_wpnonce'] ), 'ewww-image-optimizer-settings' ) ) {
4694
  die( wp_json_encode( array( 'error' => esc_html__( 'Access token has expired, please reload the page.', 'ewww-image-optimizer' ) ) ) );
4695
  }
4696
+ if ( is_multisite() && defined( 'EXACTDN_SUB_FOLDER' ) && EXACTDN_SUB_FOLDER ) {
4697
+ update_site_option( 'ewww_image_optimizer_exactdn', true );
4698
+ } elseif ( defined( 'EXACTDN_SUB_FOLDER' ) ) {
4699
  update_option( 'ewww_image_optimizer_exactdn', true );
4700
+ } elseif ( is_multisite() && get_site_option( 'exactdn_sub_folder' ) ) {
4701
+ update_site_option( 'ewww_image_optimizer_exactdn', true );
4702
  } else {
4703
+ update_option( 'ewww_image_optimizer_exactdn', true );
4704
  }
4705
  if ( ! class_exists( 'ExactDN' ) ) {
4706
  /**
6724
  }
6725
  ewwwio_debug_message( "S3 Uploads fullsize path: $s3_path" );
6726
  ewwwio_debug_message( "unfiltered fullsize path: $filename" );
6727
+ if ( is_dir( $upload_path ) && ! is_writable( $upload_path ) ) {
6728
+ return false;
6729
+ } elseif ( ! is_dir( $upload_path ) && ! is_writable( WP_CONTENT_DIR ) ) {
6730
+ return false;
6731
+ }
6732
  if ( ! is_dir( dirname( $filename ) ) ) {
6733
  wp_mkdir_p( dirname( $filename ) );
6734
  }
7463
  } else {
7464
  list( $newwidth, $newheight ) = wp_constrain_dimensions( $oldwidth, $oldheight, $maxwidth, $maxheight );
7465
  }
7466
+ if ( ! ewwwio_check_memory_available( ( $oldwidth * $oldheight + $newwidth * $newheight ) * 4.8 ) ) { // 4.8 = 24-bit or 3 bytes per pixel multiplied by a factor of 1.6 for extra wiggle room.
7467
+ $memory_required = ( $oldwidth * $oldheight + $newwidth * $newheight ) * 4.8;
7468
  ewwwio_debug_message( "possibly insufficient memory for resizing operation: $memory_required" );
7469
  if ( function_exists( 'wp_raise_memory_limit' ) ) {
7470
  add_filter( 'image_memory_limit', 'ewww_image_optimizer_raise_memory_limit' );
9109
  if ( false !== strpos( $filename, '../' ) ) {
9110
  return false;
9111
  }
9112
+ list( $width, $height ) = wp_getimagesize( $filename );
9113
+ ewwwio_debug_message( "image dimensions: $width x $height" );
9114
+ if ( ! ewww_image_optimizer_gd_support() || ! ewwwio_check_memory_available( ( $width * $height ) * 4.8 ) ) { // 4.8 = 24-bit or 3 bytes per pixel multiplied by a factor of 1.6 for extra wiggle room.
9115
+ global $eio_filesystem;
9116
+ ewwwio_get_filesystem();
9117
+ $file_contents = $eio_filesystem->get_contents( $filename );
9118
+ // Determine what color type is stored in the file.
9119
+ $color_type = ord( substr( $file_contents, 25, 1 ) );
9120
+ unset( $file_contents );
9121
+ ewwwio_debug_message( "color type: $color_type" );
9122
+ if ( 4 === $color_type || 6 === $color_type ) {
9123
+ ewwwio_debug_message( 'transparency found' );
9124
+ return true;
9125
+ }
9126
  } elseif ( ewww_image_optimizer_gd_support() ) {
9127
  $image = imagecreatefrompng( $filename );
9128
  if ( imagecolortransparent( $image ) >= 0 ) {
9129
  ewwwio_debug_message( 'transparency found' );
9130
  return true;
9131
  }
 
 
9132
  ewwwio_debug_message( 'preparing to scan image' );
9133
  for ( $y = 0; $y < $height; $y++ ) {
9134
  for ( $x = 0; $x < $width; $x++ ) {
11043
  } else {
11044
  ewwwio_debug_message( 'not external cache' );
11045
  }
11046
+ ewww_image_optimizer_gd_support( false );
11047
  ewww_image_optimizer_gmagick_support();
11048
  ewww_image_optimizer_imagick_support();
11049
  if ( PHP_OS !== 'WINNT' && ! ewww_image_optimizer_full_cloud() && ! EWWW_IMAGE_OPTIMIZER_NOEXEC ) {
11759
  global $eio_hs_beacon;
11760
  global $exactdn;
11761
  global $eio_alt_webp;
11762
+ global $wpdb;
11763
  $total_savings = 0;
11764
  if ( 'network-multisite' === $network ) {
11765
  $total_sizes = ewww_image_optimizer_savings();
11773
  $debug_info = $eio_debug;
11774
  ewww_image_optimizer_temp_debug_clear();
11775
 
11776
+ $exactdn_sub_folder = false;
11777
+ if ( is_multisite() && is_network_admin() ) {
11778
+ if ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) {
11779
+ update_site_option( 'exactdn_sub_folder', false );
11780
+ } else {
11781
+ $network_site_url = network_site_url();
11782
+ $sub_folder = true;
11783
+ ewwwio_debug_message( "network site url: $network_site_url" );
11784
+ $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d LIMIT 500", $wpdb->siteid ), ARRAY_A );
11785
+ if ( ewww_image_optimizer_iterable( $blogs ) ) {
11786
+ $indices = array( 0, 1, 2 );
11787
+ if ( function_exists( 'array_key_last' ) ) {
11788
+ $indices[] = array_key_last( $blogs );
11789
+ } else {
11790
+ $indices[] = 3;
11791
+ }
11792
+ foreach ( $indices as $index ) {
11793
+ if ( ! empty( $blogs[ $index ]['blog_id'] ) ) {
11794
+ $sample_blog_id = $blogs[ $index ]['blog_id'];
11795
+ $sample_site_url = get_site_url( $sample_blog_id );
11796
+ ewwwio_debug_message( "blog $sample_blog_id url: $sample_site_url" );
11797
+ $sample_domain = wp_parse_url( $sample_site_url, PHP_URL_HOST );
11798
+ $site_domain = wp_parse_url( $network_site_url, PHP_URL_HOST );
11799
+ if ( $sample_domain && $site_domain && $site_domain !== $sample_domain ) {
11800
+ $sub_folder = false;
11801
+ }
11802
+ }
11803
+ }
11804
+ }
11805
+ update_site_option( 'exactdn_sub_folder', $sub_folder );
11806
+ }
11807
+ }
11808
+ $exactdn_sub_folder = (bool) get_site_option( 'exactdn_sub_folder' );
11809
+ if ( defined( 'EXACTDN_SUB_FOLDER' ) && EXACTDN_SUB_FOLDER ) {
11810
+ $exactdn_sub_folder = true;
11811
+ } elseif ( defined( 'EXACTDN_SUB_FOLDER' ) ) {
11812
+ $exactdn_sub_folder = false;
11813
+ }
11814
+
11815
  if ( empty( $network ) ) {
11816
  $network = 'singlesite';
11817
  }
11913
  $speed_score += 20;
11914
  }
11915
  $exactdn_enabled = true;
11916
+ if ( is_multisite() && is_network_admin() && empty( $exactdn->sub_folder ) ) {
11917
  $exactdn_savings = 0;
11918
  } else {
11919
  $exactdn_savings = $exactdn->savings();
11939
  delete_site_option( 'ewww_image_optimizer_exactdn_suspended' );
11940
  }
11941
  $exactdn_network_enabled = 0;
11942
+ if ( $exactdn_enabled && is_multisite() && is_network_admin() && empty( $exactdn_sub_folder ) ) {
11943
  $exactdn_network_enabled = ewww_image_optimizer_easyio_network_activated();
11944
  }
11945
  $easymode = false;
12552
  <p style='color: red'><?php esc_html_e( 'Inactive, please disable the Image Accelerator option on the Jetpack Dashboard.', 'ewww-image-optimizer' ); ?></p>
12553
  <?php elseif ( false !== strpos( $easyio_site_url, 'localhost' ) ) : ?>
12554
  <p class="description" style="font-weight: bolder"><?php esc_html_e( 'Easy IO cannot be activated on localhost installs.', 'ewww-image-optimizer' ); ?></p>
12555
+ <?php elseif ( 'network-multisite' === $network && empty( $exactdn_sub_folder ) ) : ?>
12556
  <?php if ( 1 > $exactdn_network_enabled ) : ?>
12557
  <p class="ewwwio-easy-setup-instructions">
12558
  <?php if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) : ?>
13476
  <?php ob_end_clean(); ?>
13477
  <div id='ewww-resize-settings'>
13478
  <table class='form-table'>
13479
+ <?php echo ( empty( $exactdn_sub_folder ) ? wp_kses_post( $exactdn_settings_row ) : '' ); ?>
13480
  <?php endif; ?>
13481
  <!-- RIGHT HERE is where we begin/clear buffer for network-singlesite (non-override version). -->
13482
  <!-- Though the buffer will need to be started right the form begins. -->
13849
  if ( ewww_image_optimizer_iterable( $blogs ) ) {
13850
  foreach ( $blogs as $blog ) {
13851
  $total++;
13852
+ $blog_id = $blog['blog_id'];
13853
+ switch_to_blog( $blog_id );
13854
  if ( get_option( 'ewww_image_optimizer_exactdn' ) && get_option( 'ewww_image_optimizer_exactdn_verified' ) ) {
13855
  ewwwio_debug_message( "blog $blog_id active" );
13856
  $active++;
14062
  * @return bool True for an AMP endpoint, false otherwise.
14063
  */
14064
  function ewww_image_optimizer_is_amp() {
14065
+ if ( ! did_action( 'parse_query' ) ) {
14066
+ return false;
14067
+ }
14068
+ if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
14069
+ return true;
14070
+ }
14071
  if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
14072
  return true;
14073
  }
ewww-image-optimizer.php CHANGED
@@ -13,7 +13,7 @@ Plugin Name: EWWW Image Optimizer
13
  Plugin URI: https://wordpress.org/plugins/ewww-image-optimizer/
14
  Description: Reduce file sizes for images within WordPress including NextGEN Gallery and GRAND FlAGallery. Uses jpegtran, optipng/pngout, and gifsicle.
15
  Author: Exactly WWW
16
- Version: 6.2.4
17
  Requires at least: 5.5
18
  Requires PHP: 7.1
19
  Author URI: https://ewww.io/
@@ -105,6 +105,19 @@ if ( ! defined( 'PHP_VERSION_ID' ) || PHP_VERSION_ID < 50600 ) {
105
  * EWWWIO_Tracking class for reporting anonymous site data.
106
  */
107
  require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'classes/class-ewwwio-tracking.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  } // End if().
109
 
110
  if ( ! function_exists( 'ewww_image_optimizer_unsupported_php' ) ) {
13
  Plugin URI: https://wordpress.org/plugins/ewww-image-optimizer/
14
  Description: Reduce file sizes for images within WordPress including NextGEN Gallery and GRAND FlAGallery. Uses jpegtran, optipng/pngout, and gifsicle.
15
  Author: Exactly WWW
16
+ Version: 6.2.5
17
  Requires at least: 5.5
18
  Requires PHP: 7.1
19
  Author URI: https://ewww.io/
105
  * EWWWIO_Tracking class for reporting anonymous site data.
106
  */
107
  require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'classes/class-ewwwio-tracking.php' );
108
+ /**
109
+ * The main function to return a single EIO_Base object to functions elsewhere.
110
+ *
111
+ * @return object object|EIO_Base The one true EIO_Base instance.
112
+ */
113
+ function eio_plugin() {
114
+ // TODO: create an intermediary EIO_Plugin class that inherits from EIO_Base. This
115
+ // can be used for things like defining constants, including other files, and adding hooks.
116
+ if ( method_exists( 'EIO_Base', 'instance' ) ) {
117
+ return EIO_Base::instance();
118
+ }
119
+ return new EIO_Base();
120
+ }
121
  } // End if().
122
 
123
  if ( ! function_exists( 'ewww_image_optimizer_unsupported_php' ) ) {
includes/lazysizes.min.js CHANGED
@@ -1 +1 @@
1
- if(void 0===ewww_webp_supported)var ewww_webp_supported=!1;function shouldAutoScale(e){if(1==eio_lazy_vars.skip_autoscale)return!1;if(e.hasAttributes())for(var t=e.attributes,a=/skip-autoscale/,i=t.length-1;0<=i;i--){if(a.test(t[i].name))return!1;if(a.test(t[i].value))return!1}return!0}function constrainSrc(e,t,a,i){if(null===e)return e;var r=/w=(\d+)/,n=/fit=(\d+),(\d+)/,o=/resize=(\d+),(\d+)/,s=decodeURIComponent(e);if("undefined"==typeof eio_lazy_vars&&(eio_lazy_vars={exactdn_domain:".exactdn.com"}),0<e.search("\\?")&&0<e.search(eio_lazy_vars.exactdn_domain)){var l=o.exec(s);if(l&&t<l[1])return s.replace(o,"resize="+t+","+a);var d=r.exec(e);if(d&&t<=d[1]){if("bg-cover"!==i&&"img-crop"!==i)return e.replace(r,"w="+t);var c=d[1]-t;return 20<c||a<1080?e.replace(r,"resize="+t+","+a):e}var u=n.exec(s);if(u&&t<u[1]){if("bg-cover"!==i&&"img-crop"!==i)return s.replace(n,"fit="+t+","+a);var f=u[1]-t,g=u[2]-a;return 20<f||20<g?e.replace(r,"resize="+t+","+a):e}if(!d&&!u&&!l)return"img"===i?e+"&fit="+t+","+a:"bg-cover"===i||"img-crop"===i?e+"&resize="+t+","+a:t<a?e+"&h="+a:e+"&w="+t}return-1==e.search("\\?")&&0<e.search(eio_lazy_vars.exactdn_domain)?"img"===i?e+"?fit="+t+","+a:"bg-cover"===i||"img-crop"===i?e+"?resize="+t+","+a:t<a?e+"?h="+a:e+"?w="+t:e}window.lazySizesConfig=window.lazySizesConfig||{},window.lazySizesConfig.expand=500<document.documentElement.clientHeight&&500<document.documentElement.clientWidth?1e3:740,50<eio_lazy_vars.threshold&&(window.lazySizesConfig.expand=eio_lazy_vars.threshold),function(e,t){var a=function(){t(e.lazySizes),e.removeEventListener("lazyunveilread",a,!0)};t=t.bind(null,e,e.document),"object"==typeof module&&module.exports?t(require("lazysizes")):e.lazySizes?a():e.addEventListener("lazyunveilread",a,!0)}(window,function(o,e,s){"use strict";var l;e.addEventListener&&(l=/\(|\)|\s|'/,addEventListener("lazybeforeunveil",function(e){var t,a;if(e.detail.instance==s&&(!e.defaultPrevented&&("none"==e.target.preload&&(e.target.preload="auto"),t=e.target.getAttribute("data-bg")))){ewww_webp_supported&&(a=e.target.getAttribute("data-bg-webp"))&&(t=a);var i=o.devicePixelRatio||1,r=Math.round(e.target.offsetWidth*i),n=Math.round(e.target.offsetHeight*i);shouldAutoScale(e.target)&&shouldAutoScale(e.target.parentNode)&&(t=o.lazySizes.hC(e.target,"wp-block-cover")?(o.lazySizes.hC(e.target,"has-parallax")?(r=Math.round(o.screen.width*i),n=Math.round(o.screen.height*i)):n<300&&(n=430),constrainSrc(t,r,n,"bg-cover")):o.lazySizes.hC(e.target,"elementor-bg")?constrainSrc(t,r,n,"bg-cover"):constrainSrc(t,r,n,"bg")),e.target.style.backgroundImage="url("+(l.test(t)?JSON.stringify(t):t)+")"}},!1))}),document.addEventListener("lazybeforesizes",function(e){e.target.getAttribute("data-src");void 0!==e.target._lazysizesWidth&&e.detail.width<e.target._lazysizesWidth&&(e.detail.width=e.target._lazysizesWidth)}),document.addEventListener("lazybeforeunveil",function(e){var t=e.target,a=t.getAttribute("data-srcset");if(t.naturalWidth&&!a&&1<t.naturalWidth&&1<t.naturalHeight){var i=window.devicePixelRatio||1,r=t.naturalWidth,n=t.naturalHeight,o=t.getAttribute("data-eio-rwidth"),s=t.getAttribute("data-eio-rheight");o&&r<o&&(r=o,n=s);var l=t.clientWidth&&1.25*t.clientWidth<r,d=t.clientHeight&&1.25*t.clientHeight<n;if(l||d){var c=Math.round(t.offsetWidth*i),u=Math.round(t.offsetHeight*i),f=t.getAttribute("data-src"),g=t.getAttribute("data-src-webp");if(ewww_webp_supported&&g&&-1==f.search("webp=1")&&(f=g),shouldAutoScale(t)&&shouldAutoScale(t.parentNode))if(window.lazySizes.hC(t,"et_pb_jt_filterable_grid_item_image")||window.lazySizes.hC(t,"ss-foreground-image")||window.lazySizes.hC(t,"img-crop"))h=constrainSrc(f,c,u,"img-crop");else if(window.lazySizes.hC(t,"ct-image")&&window.lazySizes.hC(t,"object-cover"))h=constrainSrc(f,c,u,"img-crop");else h=constrainSrc(f,c,u,"img");else var h=!1;h&&f!=h&&t.setAttribute("data-src",h)}}if(ewww_webp_supported){if(a){var z=t.getAttribute("data-srcset-webp");z&&t.setAttribute("data-srcset",z)}if(!(g=t.getAttribute("data-src-webp")))return;t.setAttribute("data-src",g)}}),function(e,t){var a=function(i,g,n){"use strict";var h,z;if(function(){var e,t={lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",preloadClass:"lazypreload",errorClass:"lazyerror",autosizesClass:"lazyautosizes",fastLoadedClass:"ls-is-cached",iframeLoadMode:0,srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",minSize:40,customMedia:{},init:!0,expFactor:1.5,hFac:.8,loadMode:2,loadHidden:!0,ricTimeout:0,throttleDelay:125};for(e in z=i.lazySizesConfig||i.lazysizesConfig||{},t)e in z||(z[e]=t[e])}(),!g||!g.getElementsByClassName)return{init:function(){},cfg:z,noSupport:!0};var v=g.documentElement,r=i.HTMLPictureElement,o="addEventListener",m="getAttribute",e=i[o].bind(i),p=i.setTimeout,a=i.requestAnimationFrame||p,s=i.requestIdleCallback,y=/^picture$/i,l=["load","error","lazyincluded","_lazyloaded"],d={},b=Array.prototype.forEach,c=function(e,t){return d[t]||(d[t]=new RegExp("(\\s|^)"+t+"(\\s|$)")),d[t].test(e[m]("class")||"")&&d[t]},w=function(e,t){c(e,t)||e.setAttribute("class",(e[m]("class")||"").trim()+" "+t)},_=function(e,t){var a;(a=c(e,t))&&e.setAttribute("class",(e[m]("class")||"").replace(a," "))},C=function(t,a,e){var i=e?o:"removeEventListener";e&&C(t,a),l.forEach(function(e){t[i](e,a)})},A=function(e,t,a,i,r){var n=g.createEvent("Event");return a||(a={}),a.instance=h,n.initEvent(t,!i,!r),n.detail=a,e.dispatchEvent(n),n},S=function(e,t){var a;!r&&(a=i.picturefill||z.pf)?(t&&t.src&&!e[m]("srcset")&&e.setAttribute("srcset",t.src),a({reevaluate:!0,elements:[e]})):t&&t.src&&(e.src=t.src)},u=function(e,t){return(getComputedStyle(e,null)||{})[t]},f=function(e,t,a){for(a=a||e.offsetWidth;a<z.minSize&&t&&!e._lazysizesWidth;)a=t.offsetWidth,t=t.parentNode;return a},E=(_e=[],Ce=[],Ae=_e,Se=function(){var e=Ae;for(Ae=_e.length?Ce:_e,we=!(be=!0);e.length;)e.shift()();be=!1},Ee=function(e,t){be&&!t?e.apply(this,arguments):(Ae.push(e),we||(we=!0,(g.hidden?p:a)(Se)))},Ee._lsFlush=Se,Ee),t=function(a,e){return e?function(){E(a)}:function(){var e=this,t=arguments;E(function(){a.apply(e,t)})}},x=function(e){var t,a,i=function(){t=null,e()},r=function(){var e=n.now()-a;e<99?p(r,99-e):(s||i)(i)};return function(){a=n.now(),t||(t=p(r,99))}},M=(ee=/^img$/i,te=/^iframe$/i,ae="onscroll"in i&&!/(gle|ing)bot/.test(navigator.userAgent),ie=0,re=0,ne=-1,oe=function(e){re--,(!e||re<0||!e.target)&&(re=0)},se=function(e){return null==J&&(J="hidden"==u(g.body,"visibility")),J||!("hidden"==u(e.parentNode,"visibility")&&"hidden"==u(e,"visibility"))},le=function(e,t){var a,i=e,r=se(e);for($-=t,U+=t,j-=t,q+=t;r&&(i=i.offsetParent)&&i!=g.body&&i!=v;)(r=0<(u(i,"opacity")||1))&&"visible"!=u(i,"overflow")&&(a=i.getBoundingClientRect(),r=q>a.left&&j<a.right&&U>a.top-1&&$<a.bottom+1);return r},de=function(){var e,t,a,i,r,n,o,s,l,d,c,u,f=h.elements;if((P=z.loadMode)&&re<8&&(e=f.length)){for(t=0,ne++;t<e;t++)if(f[t]&&!f[t]._lazyRace)if(!ae||h.prematureUnveil&&h.prematureUnveil(f[t]))ve(f[t]);else if((s=f[t][m]("data-expand"))&&(n=1*s)||(n=ie),d||(d=!z.expand||z.expand<1?500<v.clientHeight&&500<v.clientWidth?500:370:z.expand,h._defEx=d,c=d*z.expFactor,u=z.hFac,J=null,ie<c&&re<1&&2<ne&&2<P&&!g.hidden?(ie=c,ne=0):ie=1<P&&1<ne&&re<6?d:0),l!==n&&(O=innerWidth+n*u,I=innerHeight+n,o=-1*n,l=n),a=f[t].getBoundingClientRect(),(U=a.bottom)>=o&&($=a.top)<=I&&(q=a.right)>=o*u&&(j=a.left)<=O&&(U||q||j||$)&&(z.loadHidden||se(f[t]))&&(T&&re<3&&!s&&(P<3||ne<4)||le(f[t],n))){if(ve(f[t]),r=!0,9<re)break}else!r&&T&&!i&&re<4&&ne<4&&2<P&&(B[0]||z.preloadAfterLoad)&&(B[0]||!s&&(U||q||j||$||"auto"!=f[t][m](z.sizesAttr)))&&(i=B[0]||f[t]);i&&!r&&ve(i)}},G=de,Q=0,V=z.throttleDelay,X=z.ricTimeout,Y=function(){K=!1,Q=n.now(),G()},Z=s&&49<X?function(){s(Y,{timeout:X}),X!==z.ricTimeout&&(X=z.ricTimeout)}:t(function(){p(Y)},!0),ce=function(e){var t;(e=!0===e)&&(X=33),K||(K=!0,(t=V-(n.now()-Q))<0&&(t=0),e||t<9?Z():p(Z,t))},ue=function(e){var t=e.target;t._lazyCache?delete t._lazyCache:(oe(e),w(t,z.loadedClass),_(t,z.loadingClass),C(t,ge),A(t,"lazyloaded"))},fe=t(ue),ge=function(e){fe({target:e.target})},he=function(e){var t,a=e[m](z.srcsetAttr);(t=z.customMedia[e[m]("data-media")||e[m]("media")])&&e.setAttribute("media",t),a&&e.setAttribute("srcset",a)},ze=t(function(t,e,a,i,r){var n,o,s,l,d,c,u,f,g;(d=A(t,"lazybeforeunveil",e)).defaultPrevented||(i&&(a?w(t,z.autosizesClass):t.setAttribute("sizes",i)),o=t[m](z.srcsetAttr),n=t[m](z.srcAttr),r&&(s=t.parentNode,l=s&&y.test(s.nodeName||"")),c=e.firesLoad||"src"in t&&(o||n||l),d={target:t},w(t,z.loadingClass),c&&(clearTimeout(F),F=p(oe,2500),C(t,ge,!0)),l&&b.call(s.getElementsByTagName("source"),he),o?t.setAttribute("srcset",o):n&&!l&&(te.test(t.nodeName)?(f=n,0==(g=(u=t).getAttribute("data-load-mode")||z.iframeLoadMode)?u.contentWindow.location.replace(f):1==g&&(u.src=f)):t.src=n),r&&(o||l)&&S(t,{src:n})),t._lazyRace&&delete t._lazyRace,_(t,z.lazyClass),E(function(){var e=t.complete&&1<t.naturalWidth;c&&!e||(e&&w(t,z.fastLoadedClass),ue(d),t._lazyCache=!0,p(function(){"_lazyCache"in t&&delete t._lazyCache},9)),"lazy"==t.loading&&re--},!0)}),ve=function(e){if(!e._lazyRace){var t,a=ee.test(e.nodeName),i=a&&(e[m](z.sizesAttr)||e[m]("sizes")),r="auto"==i;(!r&&T||!a||!e[m]("src")&&!e.srcset||e.complete||c(e,z.errorClass)||!c(e,z.lazyClass))&&(t=A(e,"lazyunveilread").detail,r&&W.updateElem(e,!0,e.offsetWidth),e._lazyRace=!0,re++,ze(e,t,r,i,a))}},me=x(function(){z.loadMode=3,ce()}),pe=function(){3==z.loadMode&&(z.loadMode=2),me()},ye=function(){T||(n.now()-D<999?p(ye,999):(T=!0,z.loadMode=3,ce(),e("scroll",pe,!0)))},{_:function(){D=n.now(),h.elements=g.getElementsByClassName(z.lazyClass),B=g.getElementsByClassName(z.lazyClass+" "+z.preloadClass),e("scroll",ce,!0),e("resize",ce,!0),e("pageshow",function(e){if(e.persisted){var t=g.querySelectorAll("."+z.loadingClass);t.length&&t.forEach&&a(function(){t.forEach(function(e){e.complete&&ve(e)})})}}),i.MutationObserver?new MutationObserver(ce).observe(v,{childList:!0,subtree:!0,attributes:!0}):(v[o]("DOMNodeInserted",ce,!0),v[o]("DOMAttrModified",ce,!0),setInterval(ce,999)),e("hashchange",ce,!0),["focus","mouseover","click","load","transitionend","animationend"].forEach(function(e){g[o](e,ce,!0)}),/d$|^c/.test(g.readyState)?ye():(e("load",ye),g[o]("DOMContentLoaded",ce),p(ye,2e4)),h.elements.length?(de(),E._lsFlush()):ce()},checkElems:ce,unveil:ve,_aLSL:pe}),W=(H=t(function(e,t,a,i){var r,n,o;if(e._lazysizesWidth=i,i+="px",e.setAttribute("sizes",i),y.test(t.nodeName||""))for(r=t.getElementsByTagName("source"),n=0,o=r.length;n<o;n++)r[n].setAttribute("sizes",i);a.detail.dataAttr||S(e,a.detail)}),R=function(e,t,a){var i,r=e.parentNode;r&&(a=f(e,r,a),(i=A(e,"lazybeforesizes",{width:a,dataAttr:!!t})).defaultPrevented||(a=i.detail.width)&&a!==e._lazysizesWidth&&H(e,r,i,a))},k=x(function(){var e,t=N.length;if(t)for(e=0;e<t;e++)R(N[e])}),{_:function(){N=g.getElementsByClassName(z.autosizesClass),e("resize",k)},checkElems:k,updateElem:R}),L=function(){!L.i&&g.getElementsByClassName&&(L.i=!0,W._(),M._())};var N,H,R,k;var B,T,F,P,D,O,I,$,j,q,U,J,G,K,Q,V,X,Y,Z,ee,te,ae,ie,re,ne,oe,se,le,de,ce,ue,fe,ge,he,ze,ve,me,pe,ye;var be,we,_e,Ce,Ae,Se,Ee;return p(function(){z.init&&L()}),h={cfg:z,autoSizer:W,loader:M,init:L,uP:S,aC:w,rC:_,hC:c,fire:A,gW:f,rAF:E}}(e,e.document,Date);e.lazySizes=a,"object"==typeof module&&module.exports&&(module.exports=a)}("undefined"!=typeof window?window:{});
1
+ if(void 0===ewww_webp_supported)var ewww_webp_supported=!1;function shouldAutoScale(e){if(1==eio_lazy_vars.skip_autoscale)return!1;if(e.hasAttributes())for(var t=e.attributes,a=/skip-autoscale/,i=t.length-1;0<=i;i--){if(a.test(t[i].name))return!1;if(a.test(t[i].value))return!1}return!0}function constrainSrc(e,t,a,i){if(null===e)return e;var r=/w=(\d+)/,n=/fit=(\d+),(\d+)/,o=/resize=(\d+),(\d+)/,s=decodeURIComponent(e);if("undefined"==typeof eio_lazy_vars&&(eio_lazy_vars={exactdn_domain:".exactdn.com"}),0<e.search("\\?")&&0<e.search(eio_lazy_vars.exactdn_domain)){var l=o.exec(s);if(l&&t<l[1])return s.replace(o,"resize="+t+","+a);var d=r.exec(e);if(d&&t<=d[1]){if("bg-cover"!==i&&"img-crop"!==i)return e.replace(r,"w="+t);var c=d[1]-t;return 20<c||a<1080?e.replace(r,"resize="+t+","+a):e}var u=n.exec(s);if(u&&t<u[1]){if("bg-cover"!==i&&"img-crop"!==i)return s.replace(n,"fit="+t+","+a);var f=u[1]-t,g=u[2]-a;return 20<f||20<g?e.replace(r,"resize="+t+","+a):e}if(!d&&!u&&!l)return"img"===i?e+"&fit="+t+","+a:"bg-cover"===i||"img-crop"===i?e+"&resize="+t+","+a:t<a?e+"&h="+a:e+"&w="+t}return-1==e.search("\\?")&&0<e.search(eio_lazy_vars.exactdn_domain)?"img"===i?e+"?fit="+t+","+a:"bg-cover"===i||"img-crop"===i?e+"?resize="+t+","+a:t<a?e+"?h="+a:e+"?w="+t:e}window.lazySizesConfig=window.lazySizesConfig||{},window.lazySizesConfig.expand=500<document.documentElement.clientHeight&&500<document.documentElement.clientWidth?1e3:740,50<eio_lazy_vars.threshold&&(window.lazySizesConfig.expand=eio_lazy_vars.threshold),function(e,t){var a=function(){t(e.lazySizes),e.removeEventListener("lazyunveilread",a,!0)};t=t.bind(null,e,e.document),"object"==typeof module&&module.exports?t(require("lazysizes")):e.lazySizes?a():e.addEventListener("lazyunveilread",a,!0)}(window,function(o,e,s){"use strict";var l;e.addEventListener&&(l=/\(|\)|\s|'/,addEventListener("lazybeforeunveil",function(e){var t,a;if(e.detail.instance==s&&(!e.defaultPrevented&&("none"==e.target.preload&&(e.target.preload="auto"),t=e.target.getAttribute("data-bg")))){ewww_webp_supported&&(a=e.target.getAttribute("data-bg-webp"))&&(t=a);var i=o.devicePixelRatio||1,r=Math.round(e.target.offsetWidth*i),n=Math.round(e.target.offsetHeight*i);shouldAutoScale(e.target)&&shouldAutoScale(e.target.parentNode)&&(t=o.lazySizes.hC(e.target,"wp-block-cover")?(o.lazySizes.hC(e.target,"has-parallax")?(r=Math.round(o.screen.width*i),n=Math.round(o.screen.height*i)):n<300&&(n=430),constrainSrc(t,r,n,"bg-cover")):o.lazySizes.hC(e.target,"elementor-bg")?constrainSrc(t,r,n,"bg-cover"):o.lazySizes.hC(e.target,"bg-image-crop")?constrainSrc(t,r,n,"bg-cover"):constrainSrc(t,r,n,"bg")),e.target.style.backgroundImage="url("+(l.test(t)?JSON.stringify(t):t)+")"}},!1))}),document.addEventListener("lazybeforesizes",function(e){e.target.getAttribute("data-src");void 0!==e.target._lazysizesWidth&&e.detail.width<e.target._lazysizesWidth&&(e.detail.width=e.target._lazysizesWidth)}),document.addEventListener("lazybeforeunveil",function(e){var t=e.target,a=t.getAttribute("data-srcset");if(t.naturalWidth&&!a&&1<t.naturalWidth&&1<t.naturalHeight){var i=window.devicePixelRatio||1,r=t.naturalWidth,n=t.naturalHeight,o=t.getAttribute("data-eio-rwidth"),s=t.getAttribute("data-eio-rheight");o&&r<o&&(r=o,n=s);var l=t.clientWidth&&1.25*t.clientWidth<r,d=t.clientHeight&&1.25*t.clientHeight<n;if(l||d){var c=Math.round(t.offsetWidth*i),u=Math.round(t.offsetHeight*i),f=t.getAttribute("data-src"),g=t.getAttribute("data-src-webp");if(ewww_webp_supported&&g&&-1==f.search("webp=1")&&(f=g),shouldAutoScale(t)&&shouldAutoScale(t.parentNode))if(window.lazySizes.hC(t,"et_pb_jt_filterable_grid_item_image")||window.lazySizes.hC(t,"ss-foreground-image")||window.lazySizes.hC(t,"img-crop"))h=constrainSrc(f,c,u,"img-crop");else if(window.lazySizes.hC(t,"ct-image")&&window.lazySizes.hC(t,"object-cover"))h=constrainSrc(f,c,u,"img-crop");else h=constrainSrc(f,c,u,"img");else var h=!1;h&&f!=h&&t.setAttribute("data-src",h)}}if(ewww_webp_supported){if(a){var z=t.getAttribute("data-srcset-webp");z&&t.setAttribute("data-srcset",z)}if(!(g=t.getAttribute("data-src-webp")))return;t.setAttribute("data-src",g)}}),function(e,t){var a=function(i,g,n){"use strict";var h,z;if(function(){var e,t={lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",preloadClass:"lazypreload",errorClass:"lazyerror",autosizesClass:"lazyautosizes",fastLoadedClass:"ls-is-cached",iframeLoadMode:0,srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",minSize:40,customMedia:{},init:!0,expFactor:1.5,hFac:.8,loadMode:2,loadHidden:!0,ricTimeout:0,throttleDelay:125};for(e in z=i.lazySizesConfig||i.lazysizesConfig||{},t)e in z||(z[e]=t[e])}(),!g||!g.getElementsByClassName)return{init:function(){},cfg:z,noSupport:!0};var v=g.documentElement,r=i.HTMLPictureElement,o="addEventListener",m="getAttribute",e=i[o].bind(i),p=i.setTimeout,a=i.requestAnimationFrame||p,s=i.requestIdleCallback,y=/^picture$/i,l=["load","error","lazyincluded","_lazyloaded"],d={},b=Array.prototype.forEach,c=function(e,t){return d[t]||(d[t]=new RegExp("(\\s|^)"+t+"(\\s|$)")),d[t].test(e[m]("class")||"")&&d[t]},w=function(e,t){c(e,t)||e.setAttribute("class",(e[m]("class")||"").trim()+" "+t)},_=function(e,t){var a;(a=c(e,t))&&e.setAttribute("class",(e[m]("class")||"").replace(a," "))},C=function(t,a,e){var i=e?o:"removeEventListener";e&&C(t,a),l.forEach(function(e){t[i](e,a)})},A=function(e,t,a,i,r){var n=g.createEvent("Event");return a||(a={}),a.instance=h,n.initEvent(t,!i,!r),n.detail=a,e.dispatchEvent(n),n},S=function(e,t){var a;!r&&(a=i.picturefill||z.pf)?(t&&t.src&&!e[m]("srcset")&&e.setAttribute("srcset",t.src),a({reevaluate:!0,elements:[e]})):t&&t.src&&(e.src=t.src)},u=function(e,t){return(getComputedStyle(e,null)||{})[t]},f=function(e,t,a){for(a=a||e.offsetWidth;a<z.minSize&&t&&!e._lazysizesWidth;)a=t.offsetWidth,t=t.parentNode;return a},E=(_e=[],Ce=[],Ae=_e,Se=function(){var e=Ae;for(Ae=_e.length?Ce:_e,we=!(be=!0);e.length;)e.shift()();be=!1},Ee=function(e,t){be&&!t?e.apply(this,arguments):(Ae.push(e),we||(we=!0,(g.hidden?p:a)(Se)))},Ee._lsFlush=Se,Ee),t=function(a,e){return e?function(){E(a)}:function(){var e=this,t=arguments;E(function(){a.apply(e,t)})}},x=function(e){var t,a,i=function(){t=null,e()},r=function(){var e=n.now()-a;e<99?p(r,99-e):(s||i)(i)};return function(){a=n.now(),t||(t=p(r,99))}},M=(ee=/^img$/i,te=/^iframe$/i,ae="onscroll"in i&&!/(gle|ing)bot/.test(navigator.userAgent),ie=0,re=0,ne=-1,oe=function(e){re--,(!e||re<0||!e.target)&&(re=0)},se=function(e){return null==J&&(J="hidden"==u(g.body,"visibility")),J||!("hidden"==u(e.parentNode,"visibility")&&"hidden"==u(e,"visibility"))},le=function(e,t){var a,i=e,r=se(e);for($-=t,U+=t,j-=t,q+=t;r&&(i=i.offsetParent)&&i!=g.body&&i!=v;)(r=0<(u(i,"opacity")||1))&&"visible"!=u(i,"overflow")&&(a=i.getBoundingClientRect(),r=q>a.left&&j<a.right&&U>a.top-1&&$<a.bottom+1);return r},de=function(){var e,t,a,i,r,n,o,s,l,d,c,u,f=h.elements;if((P=z.loadMode)&&re<8&&(e=f.length)){for(t=0,ne++;t<e;t++)if(f[t]&&!f[t]._lazyRace)if(!ae||h.prematureUnveil&&h.prematureUnveil(f[t]))ve(f[t]);else if((s=f[t][m]("data-expand"))&&(n=1*s)||(n=ie),d||(d=!z.expand||z.expand<1?500<v.clientHeight&&500<v.clientWidth?500:370:z.expand,h._defEx=d,c=d*z.expFactor,u=z.hFac,J=null,ie<c&&re<1&&2<ne&&2<P&&!g.hidden?(ie=c,ne=0):ie=1<P&&1<ne&&re<6?d:0),l!==n&&(O=innerWidth+n*u,I=innerHeight+n,o=-1*n,l=n),a=f[t].getBoundingClientRect(),(U=a.bottom)>=o&&($=a.top)<=I&&(q=a.right)>=o*u&&(j=a.left)<=O&&(U||q||j||$)&&(z.loadHidden||se(f[t]))&&(T&&re<3&&!s&&(P<3||ne<4)||le(f[t],n))){if(ve(f[t]),r=!0,9<re)break}else!r&&T&&!i&&re<4&&ne<4&&2<P&&(B[0]||z.preloadAfterLoad)&&(B[0]||!s&&(U||q||j||$||"auto"!=f[t][m](z.sizesAttr)))&&(i=B[0]||f[t]);i&&!r&&ve(i)}},G=de,Q=0,V=z.throttleDelay,X=z.ricTimeout,Y=function(){K=!1,Q=n.now(),G()},Z=s&&49<X?function(){s(Y,{timeout:X}),X!==z.ricTimeout&&(X=z.ricTimeout)}:t(function(){p(Y)},!0),ce=function(e){var t;(e=!0===e)&&(X=33),K||(K=!0,(t=V-(n.now()-Q))<0&&(t=0),e||t<9?Z():p(Z,t))},ue=function(e){var t=e.target;t._lazyCache?delete t._lazyCache:(oe(e),w(t,z.loadedClass),_(t,z.loadingClass),C(t,ge),A(t,"lazyloaded"))},fe=t(ue),ge=function(e){fe({target:e.target})},he=function(e){var t,a=e[m](z.srcsetAttr);(t=z.customMedia[e[m]("data-media")||e[m]("media")])&&e.setAttribute("media",t),a&&e.setAttribute("srcset",a)},ze=t(function(t,e,a,i,r){var n,o,s,l,d,c,u,f,g;(d=A(t,"lazybeforeunveil",e)).defaultPrevented||(i&&(a?w(t,z.autosizesClass):t.setAttribute("sizes",i)),o=t[m](z.srcsetAttr),n=t[m](z.srcAttr),r&&(s=t.parentNode,l=s&&y.test(s.nodeName||"")),c=e.firesLoad||"src"in t&&(o||n||l),d={target:t},w(t,z.loadingClass),c&&(clearTimeout(F),F=p(oe,2500),C(t,ge,!0)),l&&b.call(s.getElementsByTagName("source"),he),o?t.setAttribute("srcset",o):n&&!l&&(te.test(t.nodeName)?(f=n,0==(g=(u=t).getAttribute("data-load-mode")||z.iframeLoadMode)?u.contentWindow.location.replace(f):1==g&&(u.src=f)):t.src=n),r&&(o||l)&&S(t,{src:n})),t._lazyRace&&delete t._lazyRace,_(t,z.lazyClass),E(function(){var e=t.complete&&1<t.naturalWidth;c&&!e||(e&&w(t,z.fastLoadedClass),ue(d),t._lazyCache=!0,p(function(){"_lazyCache"in t&&delete t._lazyCache},9)),"lazy"==t.loading&&re--},!0)}),ve=function(e){if(!e._lazyRace){var t,a=ee.test(e.nodeName),i=a&&(e[m](z.sizesAttr)||e[m]("sizes")),r="auto"==i;(!r&&T||!a||!e[m]("src")&&!e.srcset||e.complete||c(e,z.errorClass)||!c(e,z.lazyClass))&&(t=A(e,"lazyunveilread").detail,r&&W.updateElem(e,!0,e.offsetWidth),e._lazyRace=!0,re++,ze(e,t,r,i,a))}},me=x(function(){z.loadMode=3,ce()}),pe=function(){3==z.loadMode&&(z.loadMode=2),me()},ye=function(){T||(n.now()-D<999?p(ye,999):(T=!0,z.loadMode=3,ce(),e("scroll",pe,!0)))},{_:function(){D=n.now(),h.elements=g.getElementsByClassName(z.lazyClass),B=g.getElementsByClassName(z.lazyClass+" "+z.preloadClass),e("scroll",ce,!0),e("resize",ce,!0),e("pageshow",function(e){if(e.persisted){var t=g.querySelectorAll("."+z.loadingClass);t.length&&t.forEach&&a(function(){t.forEach(function(e){e.complete&&ve(e)})})}}),i.MutationObserver?new MutationObserver(ce).observe(v,{childList:!0,subtree:!0,attributes:!0}):(v[o]("DOMNodeInserted",ce,!0),v[o]("DOMAttrModified",ce,!0),setInterval(ce,999)),e("hashchange",ce,!0),["focus","mouseover","click","load","transitionend","animationend"].forEach(function(e){g[o](e,ce,!0)}),/d$|^c/.test(g.readyState)?ye():(e("load",ye),g[o]("DOMContentLoaded",ce),p(ye,2e4)),h.elements.length?(de(),E._lsFlush()):ce()},checkElems:ce,unveil:ve,_aLSL:pe}),W=(H=t(function(e,t,a,i){var r,n,o;if(e._lazysizesWidth=i,i+="px",e.setAttribute("sizes",i),y.test(t.nodeName||""))for(r=t.getElementsByTagName("source"),n=0,o=r.length;n<o;n++)r[n].setAttribute("sizes",i);a.detail.dataAttr||S(e,a.detail)}),R=function(e,t,a){var i,r=e.parentNode;r&&(a=f(e,r,a),(i=A(e,"lazybeforesizes",{width:a,dataAttr:!!t})).defaultPrevented||(a=i.detail.width)&&a!==e._lazysizesWidth&&H(e,r,i,a))},k=x(function(){var e,t=N.length;if(t)for(e=0;e<t;e++)R(N[e])}),{_:function(){N=g.getElementsByClassName(z.autosizesClass),e("resize",k)},checkElems:k,updateElem:R}),L=function(){!L.i&&g.getElementsByClassName&&(L.i=!0,W._(),M._())};var N,H,R,k;var B,T,F,P,D,O,I,$,j,q,U,J,G,K,Q,V,X,Y,Z,ee,te,ae,ie,re,ne,oe,se,le,de,ce,ue,fe,ge,he,ze,ve,me,pe,ye;var be,we,_e,Ce,Ae,Se,Ee;return p(function(){z.init&&L()}),h={cfg:z,autoSizer:W,loader:M,init:L,uP:S,aC:w,rC:_,hC:c,fire:A,gW:f,rAF:E}}(e,e.document,Date);e.lazySizes=a,"object"==typeof module&&module.exports&&(module.exports=a)}("undefined"!=typeof window?window:{});
includes/ls.unveilhooks.js CHANGED
@@ -60,6 +60,9 @@
60
  } else if (window.lazySizes.hC(e.target,'elementor-bg')){
61
  console.log('found elementor-bg with data-bg');
62
  bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
 
 
 
63
  } else {
64
  console.log('found other data-bg');
65
  bg = constrainSrc(bg,targetWidth,targetHeight,'bg');
60
  } else if (window.lazySizes.hC(e.target,'elementor-bg')){
61
  console.log('found elementor-bg with data-bg');
62
  bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
63
+ } else if (window.lazySizes.hC(e.target,'bg-image-crop')){
64
+ console.log('found bg-image-crop with data-bg');
65
+ bg = constrainSrc(bg,targetWidth,targetHeight,'bg-cover');
66
  } else {
67
  console.log('found other data-bg');
68
  bg = constrainSrc(bg,targetWidth,targetHeight,'bg');
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: optimize, image, convert, webp, resize, compress, lazy load, optimization,
5
  Requires at least: 5.5
6
  Tested up to: 5.8
7
  Requires PHP: 7.1
8
- Stable tag: 6.2.4
9
  License: GPLv3
10
 
11
  Smaller Images, Faster Sites, Happier Visitors. Comprehensive image optimization that doesn't require a degree in rocket science.
@@ -137,6 +137,16 @@ That's not a question, but since I made it up, I'll answer it. See this resource
137
  * Feature requests can be viewed and submitted on our [feedback portal](https://feedback.ewww.io/b/features)
138
  * If you would like to help translate this plugin in your language, [join the team](https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/)
139
 
 
 
 
 
 
 
 
 
 
 
140
  = 6.2.4 =
141
  * added: Multi-site domain-based installs can activate/register sites en masse, and directly upon site creation
142
  * changed: improved db upgrade routine for updated column
@@ -144,7 +154,6 @@ That's not a question, but since I made it up, I'll answer it. See this resource
144
  * fixed: local PNG placeholders enabled with Easy IO when placeholder folder is not writable
145
  * fixed: WebP Rewriters not detecting upload URL correctly for CDN support
146
  * fixed: iframe lazy loading breaks Gravity Forms and FacetWP when parsing JSON
147
- * fixed: is_amp() called too early
148
  * fixed: SQL error when running "wp-cli ewwwio optimize media" - props @komsitr
149
  * fixed: local savings query sometimes returns no results
150
  * fixed: PHP warnings when local tools are disabled
5
  Requires at least: 5.5
6
  Tested up to: 5.8
7
  Requires PHP: 7.1
8
+ Stable tag: 6.2.5
9
  License: GPLv3
10
 
11
  Smaller Images, Faster Sites, Happier Visitors. Comprehensive image optimization that doesn't require a degree in rocket science.
137
  * Feature requests can be viewed and submitted on our [feedback portal](https://feedback.ewww.io/b/features)
138
  * If you would like to help translate this plugin in your language, [join the team](https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/)
139
 
140
+ = 6.2.5 =
141
+ * added: Easy IO and Lazy Load support for AJAX responses from FacetWP
142
+ * changed: Vimeo videos excluded from iframe lazy load
143
+ * changed: use 'bg-image-crop' class on elements with CSS background images that need to be cropped by auto-scaling
144
+ * fixed: sub-folder multi-site installs which use separate domains could not activate Easy IO, define EXACTDN_SUB_FOLDER to override
145
+ * fixed: Lazy Load PNG placeholders cannot be cached if the WP_CONTENT_DIR location is read-only (notably on Pantheon servers)
146
+ * fixed: is_amp() called too early
147
+ * fixed: Fusion Builder (Avada) does not load when Lazy Load, WebP, or Easy IO options are enabled
148
+ * fixed: png_alpha() check uses more memory than is available, causing some uploads to fail
149
+
150
  = 6.2.4 =
151
  * added: Multi-site domain-based installs can activate/register sites en masse, and directly upon site creation
152
  * changed: improved db upgrade routine for updated column
154
  * fixed: local PNG placeholders enabled with Easy IO when placeholder folder is not writable
155
  * fixed: WebP Rewriters not detecting upload URL correctly for CDN support
156
  * fixed: iframe lazy loading breaks Gravity Forms and FacetWP when parsing JSON
 
157
  * fixed: SQL error when running "wp-cli ewwwio optimize media" - props @komsitr
158
  * fixed: local savings query sometimes returns no results
159
  * fixed: PHP warnings when local tools are disabled
unique.php CHANGED
@@ -157,6 +157,7 @@ function ewww_image_optimizer_set_defaults() {
157
  add_option( 'exactdn_all_the_things', true );
158
  add_option( 'exactdn_lossy', true );
159
  add_option( 'exactdn_exclude', '' );
 
160
  add_option( 'ewww_image_optimizer_lazy_load', false );
161
  add_option( 'ewww_image_optimizer_ll_autoscale', true );
162
  add_option( 'ewww_image_optimizer_ll_exclude', '' );
@@ -186,6 +187,7 @@ function ewww_image_optimizer_set_defaults() {
186
  add_site_option( 'ewww_image_optimizer_pngout_level', 2 );
187
  add_site_option( 'exactdn_all_the_things', true );
188
  add_site_option( 'exactdn_lossy', true );
 
189
  add_site_option( 'ewww_image_optimizer_ll_autoscale', true );
190
  }
191
 
157
  add_option( 'exactdn_all_the_things', true );
158
  add_option( 'exactdn_lossy', true );
159
  add_option( 'exactdn_exclude', '' );
160
+ add_option( 'exactdn_sub_folder', false );
161
  add_option( 'ewww_image_optimizer_lazy_load', false );
162
  add_option( 'ewww_image_optimizer_ll_autoscale', true );
163
  add_option( 'ewww_image_optimizer_ll_exclude', '' );
187
  add_site_option( 'ewww_image_optimizer_pngout_level', 2 );
188
  add_site_option( 'exactdn_all_the_things', true );
189
  add_site_option( 'exactdn_lossy', true );
190
+ add_site_option( 'exactdn_sub_folder', false );
191
  add_site_option( 'ewww_image_optimizer_ll_autoscale', true );
192
  }
193