Version Description
- added: preserve animations in GIF images during resize operations for sites using Imagick extension
- changed: EXACTDN_EXCLUDE applies to all resources, including images, CSS, JS, fonts, etc.
- changed: API/ExactDN preserves color profiles, even when removing image metadata
- changed: new queue table for bulk optimizer to avoid exceeding max packet size for MySQL
- changed: unit tests run on PHP 7.3 also
- fixed: too many settings updates when trying to prevent slow queries
- fixed: ExactDN rewrites urls to static HTML files
- fixed: ExactDN skips 1x url in some cases, causing browser upscaling
- fixed: PHP notice when EXACTDN_EXCLUDE is defined
- fixed: race condition in Alt WebP prevents Webp derivatives from replacing the originals
Download this release
Release Info
Developer | nosilver4u |
Plugin | EWWW Image Optimizer |
Version | 4.6.0 |
Comparing to | |
See all releases |
Code changes from version 4.5.3 to 4.6.0
- .travis.yml +11 -13
- aux-optimize.php +186 -1
- bulk.php +102 -47
- changelog.txt +12 -0
- classes/class-ewwwio-alt-webp.php +2 -2
- classes/class-ewwwio-gd-editor.php +5 -2
- classes/class-ewwwio-imagick-editor.php +352 -0
- classes/class-exactdn.php +98 -16
- common.php +78 -36
- ewww-image-optimizer.php +1 -1
- includes/load_webp.js +2 -4
- includes/load_webp.min.js +1 -1
- readme.txt +13 -1
- tests/test-convert.php +342 -0
- tests/test-optimize.php +2 -2
- tests/test-tables.php +123 -0
.travis.yml
CHANGED
@@ -19,32 +19,30 @@ php:
|
|
19 |
|
20 |
env:
|
21 |
- WP_VERSION=latest WP_MULTISITE=0
|
22 |
-
- WP_VERSION=4.
|
23 |
|
24 |
matrix:
|
25 |
include:
|
26 |
- php: 5.6
|
27 |
-
env: WP_VERSION=latest WP_MULTISITE=1
|
28 |
- php: 7.2
|
29 |
-
env: WP_VERSION=latest WP_MULTISITE=1
|
30 |
-
|
31 |
-
|
32 |
-
- sudo apt-get install -y php-codesniffer
|
33 |
|
34 |
before_script:
|
35 |
-
-
|
36 |
- phpenv config-rm xdebug.ini
|
37 |
-
-
|
38 |
- |
|
39 |
if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then
|
40 |
-
composer global require
|
41 |
else
|
42 |
-
composer global require
|
43 |
fi
|
44 |
- |
|
45 |
-
- composer global require wp-coding-standards/wpcs
|
46 |
-
- phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
|
47 |
|
48 |
script:
|
49 |
-
- phpcs --standard=phpcs.ruleset.xml --extensions=php
|
50 |
- phpunit
|
19 |
|
20 |
env:
|
21 |
- WP_VERSION=latest WP_MULTISITE=0
|
22 |
+
- WP_VERSION=4.9 WP_MULTISITE=0
|
23 |
|
24 |
matrix:
|
25 |
include:
|
26 |
- php: 5.6
|
27 |
+
env: WP_VERSION=latest WP_MULTISITE=1 WPSNIFF=1
|
28 |
- php: 7.2
|
29 |
+
env: WP_VERSION=latest WP_MULTISITE=1 WPSNIFF=1
|
30 |
+
- php: 7.3
|
31 |
+
env: WP_VERSION=latest
|
|
|
32 |
|
33 |
before_script:
|
34 |
+
- export PATH="$HOME/.config/composer/vendor/bin:$PATH"
|
35 |
- phpenv config-rm xdebug.ini
|
36 |
+
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
|
37 |
- |
|
38 |
if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then
|
39 |
+
composer global require phpunit/phpunit ^6
|
40 |
else
|
41 |
+
composer global require phpunit/phpunit ^5
|
42 |
fi
|
43 |
- |
|
44 |
+
- composer global require wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer
|
|
|
45 |
|
46 |
script:
|
47 |
+
- if [[ "$WPSNIFF" == "1" ]]; then phpcs --standard=phpcs.ruleset.xml --extensions=php .; fi
|
48 |
- phpunit
|
aux-optimize.php
CHANGED
@@ -73,8 +73,8 @@ function ewww_image_optimizer_aux_images() {
|
|
73 |
$help_instructions = esc_html__( 'Enable the Debugging option and refresh this page to include debugging information with your question.', 'ewww-image-optimizer' ) . ' ' .
|
74 |
esc_html__( 'This will allow us to assist you more quickly.', 'ewww-image-optimizer' );
|
75 |
if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) {
|
76 |
-
ewww_image_optimizer_options( 'debug-silent' );
|
77 |
global $ewww_debug;
|
|
|
78 |
$output .= '<p style="clear:both"><b>' . esc_html__( 'Debugging Information', 'ewww-image-optimizer' ) . ':</b> <button id="ewww-copy-debug" class="button button-secondary">' . esc_html__( 'Copy', 'ewww-image-optimizer' ) . '</button>';
|
79 |
if ( is_file( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'debug.log' ) ) {
|
80 |
$debug_log_url = plugins_url( '/debug.log', __FILE__ );
|
@@ -332,6 +332,168 @@ function ewww_image_optimizer_delete_pending() {
|
|
332 |
);
|
333 |
}
|
334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
/**
|
336 |
* Searches for images to optimize in a specific folder.
|
337 |
*
|
@@ -790,4 +952,27 @@ function ewww_image_optimizer_aux_images_cleanup( $auto = false ) {
|
|
790 |
add_action( 'wp_ajax_bulk_aux_images_table', 'ewww_image_optimizer_aux_images_table' );
|
791 |
add_action( 'wp_ajax_bulk_aux_images_table_count', 'ewww_image_optimizer_aux_images_table_count' );
|
792 |
add_action( 'wp_ajax_bulk_aux_images_remove', 'ewww_image_optimizer_aux_images_remove' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
793 |
?>
|
73 |
$help_instructions = esc_html__( 'Enable the Debugging option and refresh this page to include debugging information with your question.', 'ewww-image-optimizer' ) . ' ' .
|
74 |
esc_html__( 'This will allow us to assist you more quickly.', 'ewww-image-optimizer' );
|
75 |
if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) {
|
|
|
76 |
global $ewww_debug;
|
77 |
+
ewww_image_optimizer_options( 'debug-silent' );
|
78 |
$output .= '<p style="clear:both"><b>' . esc_html__( 'Debugging Information', 'ewww-image-optimizer' ) . ':</b> <button id="ewww-copy-debug" class="button button-secondary">' . esc_html__( 'Copy', 'ewww-image-optimizer' ) . '</button>';
|
79 |
if ( is_file( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'debug.log' ) ) {
|
80 |
$debug_log_url = plugins_url( '/debug.log', __FILE__ );
|
332 |
);
|
333 |
}
|
334 |
|
335 |
+
/**
|
336 |
+
* Retrieve the number images from the ewwwio_queue table.
|
337 |
+
*
|
338 |
+
* @since 4.6.0
|
339 |
+
*
|
340 |
+
* @param string $gallery The type of attachments to count from the queue. Default is media library.
|
341 |
+
* @global object $wpdb
|
342 |
+
*/
|
343 |
+
function ewww_image_optimizer_count_attachments( $gallery = 'media' ) {
|
344 |
+
global $wpdb;
|
345 |
+
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->ewwwio_queue WHERE gallery = %s", $gallery ) );
|
346 |
+
return $count;
|
347 |
+
}
|
348 |
+
|
349 |
+
/**
|
350 |
+
* Retrieve the number of un-scanned images from the ewwwio_queue table.
|
351 |
+
*
|
352 |
+
* @since 4.6.0
|
353 |
+
*
|
354 |
+
* @param string $gallery The type of attachments to count from the queue.
|
355 |
+
* @global object $wpdb
|
356 |
+
*/
|
357 |
+
function ewww_image_optimizer_count_unscanned_attachments( $gallery = 'media' ) {
|
358 |
+
global $wpdb;
|
359 |
+
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->ewwwio_queue WHERE gallery = %s AND scanned = 0", $gallery ) );
|
360 |
+
return $count;
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Retrieve unscanned images from the ewwwio_queue table.
|
365 |
+
*
|
366 |
+
* @since 4.6.0
|
367 |
+
*
|
368 |
+
* @param string $gallery The type of attachments for which to search.
|
369 |
+
* @param int $limit The maximum number of unscanned attachments to retrieve.
|
370 |
+
* @return array A list of unscanned attachments. Will always be an array of integers.
|
371 |
+
* @global object $wpdb
|
372 |
+
*/
|
373 |
+
function ewww_image_optimizer_get_unscanned_attachments( $gallery, $limit = 1000 ) {
|
374 |
+
global $wpdb;
|
375 |
+
// Retrieve the attachment IDs that were pre-loaded in the database.
|
376 |
+
$selected_ids = $wpdb->get_col( $wpdb->prepare( "SELECT attachment_id FROM $wpdb->ewwwio_queue WHERE gallery = %s AND scanned = 0 LIMIT %d", $gallery, $limit ) );
|
377 |
+
if ( empty( $selected_ids ) ) {
|
378 |
+
ewwwio_debug_message( 'no attachments found for scanning' );
|
379 |
+
return array();
|
380 |
+
}
|
381 |
+
array_walk( $selected_ids, 'intval' );
|
382 |
+
ewwwio_debug_message( 'selected items: ' . count( $selected_ids ) );
|
383 |
+
return $selected_ids;
|
384 |
+
}
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Retrieve an image ID from the ewwwio_queue table.
|
388 |
+
*
|
389 |
+
* @since 4.6.0
|
390 |
+
*
|
391 |
+
* @param string $gallery The type of attachment to find.
|
392 |
+
* @param int $limit The maximum number of unscanned attachments to retrieve.
|
393 |
+
* @return array The ID list for queued/scanned attachments.
|
394 |
+
* @global object $wpdb
|
395 |
+
*/
|
396 |
+
function ewww_image_optimizer_get_queued_attachments( $gallery, $limit = 100 ) {
|
397 |
+
global $wpdb;
|
398 |
+
// Retrieve the attachment IDs that were pre-loaded in the database.
|
399 |
+
$selected_ids = $wpdb->get_col( $wpdb->prepare( "SELECT attachment_id FROM $wpdb->ewwwio_queue WHERE gallery = %s AND scanned = 1 LIMIT %d", $gallery, $limit ) );
|
400 |
+
if ( empty( $selected_ids ) ) {
|
401 |
+
ewwwio_debug_message( 'no attachments found in queue' );
|
402 |
+
return array();
|
403 |
+
}
|
404 |
+
array_walk( $selected_ids, 'intval' );
|
405 |
+
ewwwio_debug_message( 'selected items: ' . count( $selected_ids ) );
|
406 |
+
return $selected_ids;
|
407 |
+
}
|
408 |
+
|
409 |
+
/**
|
410 |
+
* Insert a batch of attachment IDs into the ewwwio_queue table.
|
411 |
+
*
|
412 |
+
* @since 4.6.0
|
413 |
+
*
|
414 |
+
* @param array $ids The list of attachment IDs to insert.
|
415 |
+
* @param string $gallery The type of attachments to insert. Defaults to media library.
|
416 |
+
* @global object $wpdb
|
417 |
+
*/
|
418 |
+
function ewww_image_optimizer_insert_unscanned( $ids, $gallery = 'media' ) {
|
419 |
+
global $wpdb;
|
420 |
+
$images = array();
|
421 |
+
$id = array_shift( $ids );
|
422 |
+
while ( $ids ) {
|
423 |
+
$images[] = array(
|
424 |
+
'attachment_id' => (int) $id,
|
425 |
+
'gallery' => $gallery,
|
426 |
+
);
|
427 |
+
if ( count( $images ) > 999 ) {
|
428 |
+
ewww_image_optimizer_mass_insert( $wpdb->ewwwio_queue, $images, array( '%d', '%s' ) );
|
429 |
+
$images = array();
|
430 |
+
}
|
431 |
+
$id = array_shift( $ids );
|
432 |
+
}
|
433 |
+
if ( $images ) {
|
434 |
+
ewww_image_optimizer_mass_insert( $wpdb->ewwwio_queue, $images, array( '%d', '%s' ) );
|
435 |
+
}
|
436 |
+
}
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Update an image in the queue after it has been scanned.
|
440 |
+
*
|
441 |
+
* @since 4.6.0
|
442 |
+
*
|
443 |
+
* @param int $id The attachment ID to update.
|
444 |
+
* @param string $gallery The type of attachment to update. Defaults to media library.
|
445 |
+
* @global object $wpdb
|
446 |
+
*/
|
447 |
+
function ewww_image_optimizer_update_scanned_image( $id, $gallery = 'media' ) {
|
448 |
+
global $wpdb;
|
449 |
+
$wpdb->update(
|
450 |
+
$wpdb->ewwwio_queue,
|
451 |
+
array(
|
452 |
+
'scanned' => 1,
|
453 |
+
),
|
454 |
+
array(
|
455 |
+
'gallery' => $gallery,
|
456 |
+
'attachment_id' => (int) $id,
|
457 |
+
),
|
458 |
+
array( '%d' ),
|
459 |
+
array( '%s', '%d' )
|
460 |
+
);
|
461 |
+
}
|
462 |
+
|
463 |
+
/**
|
464 |
+
* Remove an image from the ewwwio_queue table (usually when we are done with it).
|
465 |
+
*
|
466 |
+
* @since 4.6.0
|
467 |
+
*
|
468 |
+
* @param int $id The attachment ID to remove.
|
469 |
+
* @param string $gallery The type of attachment to remove. Defaults to media library.
|
470 |
+
* @global object $wpdb
|
471 |
+
*/
|
472 |
+
function ewww_image_optimizer_delete_queued_image( $id, $gallery = 'media' ) {
|
473 |
+
global $wpdb;
|
474 |
+
$wpdb->delete(
|
475 |
+
$wpdb->ewwwio_queue,
|
476 |
+
array(
|
477 |
+
'gallery' => $gallery,
|
478 |
+
'attachment_id' => (int) $id,
|
479 |
+
),
|
480 |
+
array( '%s', '%d' )
|
481 |
+
);
|
482 |
+
}
|
483 |
+
|
484 |
+
/**
|
485 |
+
* Remove images from the ewwwio_queue table.
|
486 |
+
*
|
487 |
+
* @since 4.6.0
|
488 |
+
*
|
489 |
+
* @param string $gallery The type of attachments to clear from the queue. Default media library.
|
490 |
+
* @global object $wpdb
|
491 |
+
*/
|
492 |
+
function ewww_image_optimizer_delete_queue_images( $gallery = 'media' ) {
|
493 |
+
global $wpdb;
|
494 |
+
$wpdb->query( $wpdb->prepare( "DELETE from $wpdb->ewwwio_queue WHERE gallery = %s", $gallery ) );
|
495 |
+
}
|
496 |
+
|
497 |
/**
|
498 |
* Searches for images to optimize in a specific folder.
|
499 |
*
|
952 |
add_action( 'wp_ajax_bulk_aux_images_table', 'ewww_image_optimizer_aux_images_table' );
|
953 |
add_action( 'wp_ajax_bulk_aux_images_table_count', 'ewww_image_optimizer_aux_images_table_count' );
|
954 |
add_action( 'wp_ajax_bulk_aux_images_remove', 'ewww_image_optimizer_aux_images_remove' );
|
955 |
+
|
956 |
+
/**
|
957 |
+
* Set a batch of images to pending.
|
958 |
+
*
|
959 |
+
* @global object $wpdb
|
960 |
+
* @global object $ewwwdb A clone of $wpdb unless it is lacking utf8 connectivity.
|
961 |
+
*
|
962 |
+
* @param array $reset_images A list of images to reset in the ewwwio_images table.
|
963 |
+
*/
|
964 |
+
function ewww_image_optimizer_reset_images( $reset_images ) {
|
965 |
+
if ( ! ewww_image_optimizer_iterable( $reset_images ) ) {
|
966 |
+
return;
|
967 |
+
}
|
968 |
+
array_walk( $reset_images, 'intval' );
|
969 |
+
global $wpdb;
|
970 |
+
if ( strpos( $wpdb->charset, 'utf8' ) === false ) {
|
971 |
+
ewww_image_optimizer_db_init();
|
972 |
+
global $ewwwdb;
|
973 |
+
} else {
|
974 |
+
$ewwwdb = $wpdb;
|
975 |
+
}
|
976 |
+
$ewwwdb->query( "UPDATE $ewwwdb->ewwwio_images SET pending = 1, updated = updated WHERE id IN (" . implode( ',', $reset_images ) . ')' );
|
977 |
+
}
|
978 |
?>
|
bulk.php
CHANGED
@@ -218,10 +218,11 @@ function ewww_image_optimizer_count_optimized( $gallery ) {
|
|
218 |
$attachment_query_count = 0;
|
219 |
switch ( $gallery ) {
|
220 |
case 'media':
|
|
|
221 |
$ids = array();
|
222 |
$resume = get_option( 'ewww_image_optimizer_bulk_resume' );
|
223 |
// See if we were given attachment IDs to work with via GET/POST.
|
224 |
-
if ( ! empty( $_REQUEST['ids'] ) || $resume ) {
|
225 |
ewwwio_debug_message( 'we have received attachment ids via $_REQUEST' );
|
226 |
// Retrieve the attachment IDs that were pre-loaded in the database.
|
227 |
if ( 'scanning' == $resume ) {
|
@@ -243,9 +244,15 @@ function ewww_image_optimizer_count_optimized( $gallery ) {
|
|
243 |
$full_count = $wpdb->get_var( "SELECT COUNT(ID) FROM $wpdb->posts WHERE (post_type = 'attachment' OR post_type = 'ims_image') AND (post_mime_type LIKE '%%image%%' OR post_mime_type LIKE '%%pdf%%')" );
|
244 |
}
|
245 |
} else {
|
246 |
-
|
|
|
|
|
|
|
|
|
247 |
}
|
248 |
-
|
|
|
|
|
249 |
break;
|
250 |
case 'ngg':
|
251 |
// See if we were given attachment IDs to work with via GET/POST.
|
@@ -384,24 +391,24 @@ function ewww_image_optimizer_bulk_script( $hook ) {
|
|
384 |
if ( 'media_page_ewww-image-optimizer-bulk' != $hook ) {
|
385 |
return;
|
386 |
}
|
|
|
387 |
// Initialize the $attachments variable.
|
388 |
$attachments = array();
|
389 |
// Check to see if we are supposed to reset the bulk operation and verify we are authorized to do so.
|
390 |
if ( ! empty( $_REQUEST['ewww_reset'] ) && wp_verify_nonce( $_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk-reset' ) ) {
|
|
|
391 |
// Set the 'bulk resume' option to an empty string to reset the bulk operation.
|
392 |
update_option( 'ewww_image_optimizer_bulk_resume', '' );
|
393 |
update_option( 'ewww_image_optimizer_aux_resume', '' );
|
|
|
|
|
|
|
394 |
update_option( 'ewww_image_optimizer_scanning_attachments', '', false );
|
395 |
update_option( 'ewww_image_optimizer_bulk_attachments', '', false );
|
|
|
|
|
396 |
ewww_image_optimizer_delete_pending();
|
397 |
}
|
398 |
-
global $wpdb;
|
399 |
-
// Check to see if we are supposed to reset the bulk operation and verify we are authorized to do so.
|
400 |
-
if ( ! empty( $_REQUEST['ewww_reset_aux'] ) && wp_verify_nonce( $_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-aux-images-reset' ) ) {
|
401 |
-
// Set the 'aux resume' option to an empty string to reset the bulk operation.
|
402 |
-
update_option( 'ewww_image_optimizer_aux_resume', '' );
|
403 |
-
$wpdb->query( "DELETE from $wpdb->ewwwio_images WHERE image_size IS NULL" );
|
404 |
-
}
|
405 |
// Check to see if we are supposed to convert the auxiliary images table and verify we are authorized to do so.
|
406 |
if ( ! empty( $_REQUEST['ewww_convert'] ) && wp_verify_nonce( $_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-aux-images-convert' ) ) {
|
407 |
ewww_image_optimizer_aux_images_convert();
|
@@ -410,8 +417,13 @@ function ewww_image_optimizer_bulk_script( $hook ) {
|
|
410 |
$resume = get_option( 'ewww_image_optimizer_bulk_resume' );
|
411 |
$scanning = get_option( 'ewww_image_optimizer_aux_resume' );
|
412 |
if ( ! $resume && ! $scanning ) {
|
|
|
|
|
413 |
update_option( 'ewww_image_optimizer_scanning_attachments', '', false );
|
414 |
update_option( 'ewww_image_optimizer_bulk_attachments', '', false );
|
|
|
|
|
|
|
415 |
ewww_image_optimizer_delete_pending();
|
416 |
}
|
417 |
// See if we were given attachment IDs to work with via GET/POST.
|
@@ -444,23 +456,36 @@ function ewww_image_optimizer_bulk_script( $hook ) {
|
|
444 |
update_option( 'ewww_image_optimizer_bulk_resume', '' );
|
445 |
// Check if there is a previous bulk operation to resume.
|
446 |
} elseif ( 'scanning' == $resume ) {
|
|
|
|
|
447 |
// Retrieve the attachment IDs that have not been finished from the 'scanning attachments' option.
|
448 |
-
$attachments = get_option( 'ewww_image_optimizer_scanning_attachments' );
|
|
|
|
|
449 |
} elseif ( $scanning || $resume ) {
|
450 |
-
|
451 |
-
|
|
|
|
|
452 |
} elseif ( empty( $attachments ) ) {
|
|
|
|
|
453 |
delete_transient( 'ewww_image_optimizer_scan_aux' );
|
454 |
// Load up all the image attachments we can find.
|
455 |
$attachments = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE (post_type = 'attachment' OR post_type = 'ims_image') AND (post_mime_type LIKE '%%image%%' OR post_mime_type LIKE '%%pdf%%') ORDER BY ID DESC" );
|
456 |
} // End if().
|
457 |
-
|
458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
wp_enqueue_script( 'ewwwbulkscript', plugins_url( '/includes/eio.js', __FILE__ ), array( 'jquery', 'jquery-ui-slider', 'jquery-ui-progressbar', 'postbox', 'dashboard' ), EWWW_IMAGE_OPTIMIZER_VERSION );
|
460 |
// Number of images in the ewwwio_table (previously optimized images).
|
461 |
$image_count = ewww_image_optimizer_aux_images_table_count();
|
462 |
-
// Number of image attachments to be optimized.
|
463 |
-
$attachment_count = count( $attachments );
|
464 |
// Submit a couple variables for our javascript to work with.
|
465 |
$loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
|
466 |
wp_localize_script(
|
@@ -655,13 +680,13 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
655 |
$ewwwdb = $wpdb;
|
656 |
}
|
657 |
global $optimized_list;
|
|
|
658 |
$image_count = 0;
|
659 |
$attachments_processed = 0;
|
660 |
$attachment_query = '';
|
661 |
$images = array();
|
662 |
$attachment_images = array();
|
663 |
$reset_images = array();
|
664 |
-
$queued_ids = array();
|
665 |
$field_formats = array(
|
666 |
'%s', // path.
|
667 |
'%s', // gallery.
|
@@ -675,8 +700,12 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
675 |
set_transient( 'ewww_image_optimizer_no_scheduled_optimization', true, 60 * MINUTE_IN_SECONDS );
|
676 |
|
677 |
// Retrieve the time when the scan starts.
|
678 |
-
$started
|
679 |
-
|
|
|
|
|
|
|
|
|
680 |
// Make the Force Re-optimize option persistent.
|
681 |
if ( ! empty( $_REQUEST['ewww_force'] ) ) {
|
682 |
set_transient( 'ewww_image_optimizer_force_reopt', true, HOUR_IN_SECONDS );
|
@@ -694,10 +723,6 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
694 |
|
695 |
list( $bad_attachments, $bad_attachment ) = ewww_image_optimizer_get_bad_attachments();
|
696 |
|
697 |
-
$max_query = apply_filters( 'ewww_image_optimizer_count_optimized_queries', 4000 );
|
698 |
-
$max_query = (int) $max_query;
|
699 |
-
|
700 |
-
$attachment_ids = get_option( 'ewww_image_optimizer_scanning_attachments' );
|
701 |
if ( empty( $attachment_ids ) ) {
|
702 |
// When the media library is finished, run the aux script function to scan for additional images.
|
703 |
ewww_image_optimizer_aux_images_script();
|
@@ -734,20 +759,23 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
734 |
}
|
735 |
}
|
736 |
if ( ! empty( $attachment_ids ) && is_array( $attachment_ids ) ) {
|
|
|
737 |
$selected_ids = null;
|
738 |
ewwwio_debug_message( 'remaining items: ' . count( $attachment_ids ) );
|
739 |
// Retrieve the attachment IDs that were pre-loaded in the database.
|
740 |
$selected_ids = array_splice( $attachment_ids, 0, $max_query );
|
741 |
array_walk( $selected_ids, 'intval' );
|
742 |
-
|
743 |
-
|
|
|
744 |
} else {
|
745 |
ewwwio_debug_message( 'no array found' );
|
746 |
ewwwio_ob_clean();
|
747 |
die( ewwwio_json_encode( array( 'error' => esc_html__( 'List of attachment IDs not found.', 'ewww-image-optimizer' ) ) ) );
|
748 |
}
|
749 |
|
750 |
-
$
|
|
|
751 |
|
752 |
$attachment_meta = ewww_image_optimizer_fetch_metadata_batch( $attachments_in );
|
753 |
$attachments_in = null;
|
@@ -763,12 +791,12 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
763 |
|
764 |
ewwwio_debug_message( 'validated ' . count( $attachment_meta ) . ' attachment meta items' );
|
765 |
ewwwio_debug_message( 'remaining items after selection: ' . count( $attachment_ids ) );
|
766 |
-
foreach ( $
|
767 |
$attachments_processed++;
|
768 |
if ( 0 == $attachments_processed % 5 && ( microtime( true ) - $started > apply_filters( 'ewww_image_optimizer_timeout', 22 ) || ! ewwwio_check_memory_available( 2194304 ) ) ) {
|
769 |
ewwwio_debug_message( 'time exceeded, or memory exceeded' );
|
770 |
ewww_image_optimizer_debug_log();
|
771 |
-
$attachment_ids = array_merge( $failsafe_selected_ids, $attachment_ids );
|
772 |
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
773 |
if ( is_array( $optimized_list ) ) {
|
774 |
set_transient( 'ewww_image_optimizer_low_memory_mode', 'low_memory', 600 ); // Keep us in low memory mode for up to 10 minutes.
|
@@ -780,12 +808,18 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
780 |
}
|
781 |
}
|
782 |
ewww_image_optimizer_debug_log();
|
783 |
-
array_shift( $failsafe_selected_ids );
|
784 |
clearstatcache();
|
785 |
$pending = false;
|
786 |
$remote_file = false;
|
|
|
|
|
|
|
|
|
|
|
787 |
if ( ! empty( $attachment_meta[ $selected_id ]['tinypng'] ) ) {
|
788 |
ewwwio_debug_message( "TinyPNG already compressed $selected_id" );
|
|
|
789 |
continue;
|
790 |
}
|
791 |
if ( empty( $attachment_meta[ $selected_id ]['meta'] ) ) {
|
@@ -809,7 +843,6 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
809 |
}
|
810 |
|
811 |
if ( 'application/pdf' != $mime // NOT a pdf...
|
812 |
-
&& ! in_array( $selected_id, $bad_attachments ) // AND NOT a known broken attachment, which would mean we already tried this once before...
|
813 |
&& ( // AND...
|
814 |
empty( $meta ) // metadata is empty...
|
815 |
|| ( is_string( $meta ) && 'processing' == $meta ) // OR the string 'processing'...
|
@@ -830,6 +863,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
830 |
}
|
831 |
|
832 |
if ( ! in_array( $mime, $enabled_types ) ) {
|
|
|
833 |
continue;
|
834 |
}
|
835 |
ewwwio_debug_message( "id: $selected_id and type: $mime" );
|
@@ -853,11 +887,13 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
853 |
ewwwio_debug_message( "remote file possible: $file_path" );
|
854 |
if ( ! $file_path ) {
|
855 |
ewwwio_debug_message( 'no file found on remote storage, bailing' );
|
|
|
856 |
continue;
|
857 |
}
|
858 |
$remote_file = true;
|
859 |
} elseif ( ! $file_path ) {
|
860 |
ewwwio_debug_message( "no file path for $selected_id" );
|
|
|
861 |
continue;
|
862 |
}
|
863 |
ewww_image_optimizer_debug_log();
|
@@ -1127,7 +1163,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
1127 |
if ( ! empty( $reset_images ) ) {
|
1128 |
ewwwio_debug_message( 'marking reset_images as pending' );
|
1129 |
ewww_image_optimizer_debug_log();
|
1130 |
-
|
1131 |
}
|
1132 |
$reset_images = array();
|
1133 |
}
|
@@ -1136,7 +1172,10 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
1136 |
if ( $pending ) {
|
1137 |
ewwwio_debug_message( "$selected_id added to queue" );
|
1138 |
ewww_image_optimizer_debug_log();
|
1139 |
-
$queued_ids[] = $selected_id;
|
|
|
|
|
|
|
1140 |
}
|
1141 |
$attachment_images = array();
|
1142 |
ewwwio_debug_message( 'checking for bad attachment' );
|
@@ -1145,14 +1184,17 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
1145 |
ewwwio_debug_message( 'found bad attachment, bailing to reset the counter' );
|
1146 |
ewww_image_optimizer_debug_log();
|
1147 |
if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
|
1148 |
-
$attachment_ids = array_merge( $failsafe_selected_ids, $attachment_ids );
|
1149 |
break 2;
|
1150 |
}
|
1151 |
}
|
1152 |
} // End foreach().
|
1153 |
// End of loop for the selected_id.
|
1154 |
-
ewwwio_debug_message( 'finished foreach
|
1155 |
ewww_image_optimizer_debug_log();
|
|
|
|
|
|
|
1156 |
update_option( 'ewww_image_optimizer_scanning_attachments', $attachment_ids, false );
|
1157 |
$attachments_queued = get_option( 'ewww_image_optimizer_bulk_attachments' );
|
1158 |
if ( empty( $attachments_queued ) || ! is_array( $attachments_queued ) ) {
|
@@ -1165,23 +1207,28 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
1165 |
update_option( 'ewww_image_optimizer_bulk_attachments', array_merge( $attachments_queued, $queued_ids ), false );
|
1166 |
}
|
1167 |
$queued_ids = array();
|
|
|
1168 |
ewwwio_debug_message( 'finished a loop in the while, going back for more possibly' );
|
|
|
1169 |
ewww_image_optimizer_debug_log();
|
1170 |
} // End while().
|
1171 |
-
ewwwio_debug_message( 'done for
|
1172 |
ewww_image_optimizer_debug_log();
|
1173 |
if ( ! empty( $images ) ) {
|
1174 |
ewww_image_optimizer_mass_insert( $wpdb->ewwwio_images, $images, $field_formats );
|
1175 |
}
|
1176 |
if ( ! empty( $reset_images ) ) {
|
1177 |
-
$ewwwdb->query( "UPDATE $ewwwdb->ewwwio_images SET pending = 1, updated = updated WHERE id IN (" . implode( ',', $reset_images ) . ')' );
|
1178 |
}
|
|
|
1179 |
if ( 250 > $attachments_processed ) { // in-memory table is too slow.
|
1180 |
ewwwio_debug_message( 'using in-memory table is too slow, switching to plan b' );
|
1181 |
set_transient( 'ewww_image_optimizer_low_memory_mode', 'slow_list', 600 ); // Put it in low memory mode for at least 10 minutes.
|
1182 |
}
|
1183 |
-
ewwwio_debug_message( 'storing remaining attachments in scanning_attachments' );
|
1184 |
ewww_image_optimizer_debug_log();
|
|
|
|
|
|
|
1185 |
update_option( 'ewww_image_optimizer_scanning_attachments', $attachment_ids, false );
|
1186 |
if ( ! empty( $queued_ids ) ) {
|
1187 |
$attachments_queued = get_option( 'ewww_image_optimizer_bulk_attachments' );
|
@@ -1195,6 +1242,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
1195 |
update_option( 'ewww_image_optimizer_bulk_attachments', array_merge( $attachments_queued, $queued_ids ), false );
|
1196 |
}
|
1197 |
}
|
|
|
1198 |
$elapsed = microtime( true ) - $started;
|
1199 |
ewwwio_debug_message( "counting images took $elapsed seconds" );
|
1200 |
ewwwio_memory( __FUNCTION__ );
|
@@ -1204,13 +1252,14 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
|
|
1204 |
}
|
1205 |
$loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
|
1206 |
$notice = ( 'low_memory' == get_transient( 'ewww_image_optimizer_low_memory_mode' ) ? esc_html__( "Increasing PHP's memory_limit setting will allow for faster scanning with fewer database queries. Please allow up to 10 minutes for changes to memory limit to be detected.", 'ewww-image-optimizer' ) : '' );
|
1207 |
-
|
|
|
1208 |
ewwwio_ob_clean();
|
1209 |
die(
|
1210 |
ewwwio_json_encode(
|
1211 |
array(
|
1212 |
/* translators: %d: number of images */
|
1213 |
-
'remaining' => sprintf( esc_html__( 'Stage 1, %d images left to scan.', 'ewww-image-optimizer' ),
|
1214 |
'notice' => $notice,
|
1215 |
'bad_attachment' => $bad_attachment,
|
1216 |
)
|
@@ -1259,7 +1308,9 @@ function ewww_image_optimizer_bulk_initialize() {
|
|
1259 |
die( ewwwio_json_encode( array( 'error' => esc_html__( 'Access token has expired, please reload the page.', 'ewww-image-optimizer' ) ) ) );
|
1260 |
}
|
1261 |
session_write_close();
|
1262 |
-
$output
|
|
|
|
|
1263 |
$attachments = get_option( 'ewww_image_optimizer_bulk_attachments' );
|
1264 |
if ( ! is_array( $attachments ) && ! empty( $attachments ) ) {
|
1265 |
$attachments = unserialize( $attachments );
|
@@ -1298,9 +1349,11 @@ function ewww_image_optimizer_bulk_initialize() {
|
|
1298 |
}
|
1299 |
}
|
1300 |
}
|
|
|
1301 |
// Update the 'bulk resume' option to show that an operation is in progress.
|
1302 |
update_option( 'ewww_image_optimizer_bulk_resume', 'true' );
|
1303 |
-
$attachment = (int) array_shift( $attachments );
|
|
|
1304 |
ewwwio_debug_message( "first image: $attachment" );
|
1305 |
$first_image = new EWWW_Image( $attachment, 'media' );
|
1306 |
$file = $first_image->file;
|
@@ -1521,7 +1574,8 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) {
|
|
1521 |
}
|
1522 |
$batch_image_limit = ( empty( $_REQUEST['ewww_batch_limit'] ) ? 999 : 1 );
|
1523 |
// Get the 'bulk attachments' with a list of IDs remaining.
|
1524 |
-
$attachments = get_option( 'ewww_image_optimizer_bulk_attachments' )
|
|
|
1525 |
if ( ! empty( $attachments ) && is_array( $attachments ) ) {
|
1526 |
$attachment = (int) $attachments[0];
|
1527 |
} else {
|
@@ -1640,7 +1694,8 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) {
|
|
1640 |
}
|
1641 |
// When an image (attachment) is done, pull the next attachment ID off the stack.
|
1642 |
if ( ( 'full' == $next_image->resize || empty( $next_image->resize ) ) && ! empty( $attachment ) && $attachment != $next_image->attachment_id ) {
|
1643 |
-
|
|
|
1644 |
if ( ! empty( $attachments ) && is_array( $attachments ) ) {
|
1645 |
$attachment = (int) $attachments[0]; // Then grab the next one (if any are left).
|
1646 |
} else {
|
@@ -1652,7 +1707,7 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) {
|
|
1652 |
$time_adjustment = $image->time_estimate();
|
1653 |
} // End while().
|
1654 |
|
1655 |
-
ewwwio_debug_message( 'ending loop for now' );
|
1656 |
// Calculate how much time has elapsed since we started.
|
1657 |
$elapsed = microtime( true ) - $started;
|
1658 |
// Output how much time has elapsed since we started.
|
@@ -1666,7 +1721,7 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) {
|
|
1666 |
/* translators: %s: number of seconds */
|
1667 |
$output['results'] .= sprintf( '<p>' . esc_html( _n( 'Elapsed: %s second', 'Elapsed: %s seconds', $elapsed, 'ewww-image-optimizer' ) ) . '</p>', number_format_i18n( $elapsed ) );
|
1668 |
// Store the updated list of attachment IDs back in the 'bulk_attachments' option.
|
1669 |
-
update_option( 'ewww_image_optimizer_bulk_attachments', $attachments, false )
|
1670 |
if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) {
|
1671 |
global $ewww_debug;
|
1672 |
$debug_button = esc_html__( 'Show Debug Output', 'ewww-image-optimizer' );
|
@@ -1715,7 +1770,7 @@ function ewww_image_optimizer_bulk_cleanup() {
|
|
1715 |
// All done, so we can update the bulk options with empty values.
|
1716 |
update_option( 'ewww_image_optimizer_aux_resume', '' );
|
1717 |
update_option( 'ewww_image_optimizer_bulk_resume', '' );
|
1718 |
-
update_option( 'ewww_image_optimizer_bulk_attachments', '', false )
|
1719 |
delete_transient( 'ewww_image_optimizer_skip_aux' );
|
1720 |
delete_transient( 'ewww_image_optimizer_force_reopt' );
|
1721 |
// Let the user know we are done.
|
218 |
$attachment_query_count = 0;
|
219 |
switch ( $gallery ) {
|
220 |
case 'media':
|
221 |
+
/*
|
222 |
$ids = array();
|
223 |
$resume = get_option( 'ewww_image_optimizer_bulk_resume' );
|
224 |
// See if we were given attachment IDs to work with via GET/POST.
|
225 |
+
if ( false && ! empty( $_REQUEST['ids'] ) || $resume ) {
|
226 |
ewwwio_debug_message( 'we have received attachment ids via $_REQUEST' );
|
227 |
// Retrieve the attachment IDs that were pre-loaded in the database.
|
228 |
if ( 'scanning' == $resume ) {
|
244 |
$full_count = $wpdb->get_var( "SELECT COUNT(ID) FROM $wpdb->posts WHERE (post_type = 'attachment' OR post_type = 'ims_image') AND (post_mime_type LIKE '%%image%%' OR post_mime_type LIKE '%%pdf%%')" );
|
245 |
}
|
246 |
} else {
|
247 |
+
*/
|
248 |
+
/* $full_count = $wpdb->get_var( "SELECT COUNT(ID) FROM $wpdb->posts WHERE (post_type = 'attachment' OR post_type = 'ims_image') AND (post_mime_type LIKE '%%image%%' OR post_mime_type LIKE '%%pdf%%')" ); */
|
249 |
+
|
250 |
+
/*
|
251 |
+
$full_count = $wpdb->get_var( "SELECT COUNT(attachment_id) FROM $wpdb->ewwwio_queue WHERE gallery = 'media'" );
|
252 |
}
|
253 |
+
*/
|
254 |
+
return ewww_image_optimizer_count_attachments();
|
255 |
+
/* return $full_count; */
|
256 |
break;
|
257 |
case 'ngg':
|
258 |
// See if we were given attachment IDs to work with via GET/POST.
|
391 |
if ( 'media_page_ewww-image-optimizer-bulk' != $hook ) {
|
392 |
return;
|
393 |
}
|
394 |
+
global $wpdb;
|
395 |
// Initialize the $attachments variable.
|
396 |
$attachments = array();
|
397 |
// Check to see if we are supposed to reset the bulk operation and verify we are authorized to do so.
|
398 |
if ( ! empty( $_REQUEST['ewww_reset'] ) && wp_verify_nonce( $_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-bulk-reset' ) ) {
|
399 |
+
ewwwio_debug_message( 'resetting resume flags' );
|
400 |
// Set the 'bulk resume' option to an empty string to reset the bulk operation.
|
401 |
update_option( 'ewww_image_optimizer_bulk_resume', '' );
|
402 |
update_option( 'ewww_image_optimizer_aux_resume', '' );
|
403 |
+
|
404 |
+
/*
|
405 |
+
REMOVE
|
406 |
update_option( 'ewww_image_optimizer_scanning_attachments', '', false );
|
407 |
update_option( 'ewww_image_optimizer_bulk_attachments', '', false );
|
408 |
+
*/
|
409 |
+
ewww_image_optimizer_delete_queue_images();
|
410 |
ewww_image_optimizer_delete_pending();
|
411 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
412 |
// Check to see if we are supposed to convert the auxiliary images table and verify we are authorized to do so.
|
413 |
if ( ! empty( $_REQUEST['ewww_convert'] ) && wp_verify_nonce( $_REQUEST['ewww_wpnonce'], 'ewww-image-optimizer-aux-images-convert' ) ) {
|
414 |
ewww_image_optimizer_aux_images_convert();
|
417 |
$resume = get_option( 'ewww_image_optimizer_bulk_resume' );
|
418 |
$scanning = get_option( 'ewww_image_optimizer_aux_resume' );
|
419 |
if ( ! $resume && ! $scanning ) {
|
420 |
+
/*
|
421 |
+
REMOVE
|
422 |
update_option( 'ewww_image_optimizer_scanning_attachments', '', false );
|
423 |
update_option( 'ewww_image_optimizer_bulk_attachments', '', false );
|
424 |
+
*/
|
425 |
+
ewwwio_debug_message( 'not resuming/scanning, so clearing any pending images in both tables' );
|
426 |
+
ewww_image_optimizer_delete_queue_images();
|
427 |
ewww_image_optimizer_delete_pending();
|
428 |
}
|
429 |
// See if we were given attachment IDs to work with via GET/POST.
|
456 |
update_option( 'ewww_image_optimizer_bulk_resume', '' );
|
457 |
// Check if there is a previous bulk operation to resume.
|
458 |
} elseif ( 'scanning' == $resume ) {
|
459 |
+
ewwwio_debug_message( 'scanning, nothing doing' );
|
460 |
+
// TODO: do nothing...
|
461 |
// Retrieve the attachment IDs that have not been finished from the 'scanning attachments' option.
|
462 |
+
/* $attachments = get_option( 'ewww_image_optimizer_scanning_attachments' ); */
|
463 |
+
|
464 |
+
/* $attachment_count = ewww_image_optimizer_count_unscanned_attachments( 'media' ); */
|
465 |
} elseif ( $scanning || $resume ) {
|
466 |
+
ewwwio_debug_message( 'resuming, nothing doing' );
|
467 |
+
/* $attachments = array(); */
|
468 |
+
|
469 |
+
// TODO: do nothing...
|
470 |
} elseif ( empty( $attachments ) ) {
|
471 |
+
ewwwio_debug_message( 'load em all up' );
|
472 |
+
// Since we aren't resuming, and weren't given a list of IDs, we will optimize everything.
|
473 |
delete_transient( 'ewww_image_optimizer_scan_aux' );
|
474 |
// Load up all the image attachments we can find.
|
475 |
$attachments = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE (post_type = 'attachment' OR post_type = 'ims_image') AND (post_mime_type LIKE '%%image%%' OR post_mime_type LIKE '%%pdf%%') ORDER BY ID DESC" );
|
476 |
} // End if().
|
477 |
+
if ( ! empty( $attachments ) ) {
|
478 |
+
// Store the attachment IDs we retrieved in the 'scanning_attachments' option so we can keep track of our progress in the database.
|
479 |
+
ewwwio_debug_message( 'loading attachments into queue table' );
|
480 |
+
ewww_image_optimizer_insert_unscanned( $attachments );
|
481 |
+
$attachment_count = count( $attachments );
|
482 |
+
/* update_option( 'ewww_image_optimizer_scanning_attachments', $attachments, false ); */
|
483 |
+
} else {
|
484 |
+
$attachment_count = ewww_image_optimizer_count_unscanned_attachments();
|
485 |
+
}
|
486 |
wp_enqueue_script( 'ewwwbulkscript', plugins_url( '/includes/eio.js', __FILE__ ), array( 'jquery', 'jquery-ui-slider', 'jquery-ui-progressbar', 'postbox', 'dashboard' ), EWWW_IMAGE_OPTIMIZER_VERSION );
|
487 |
// Number of images in the ewwwio_table (previously optimized images).
|
488 |
$image_count = ewww_image_optimizer_aux_images_table_count();
|
|
|
|
|
489 |
// Submit a couple variables for our javascript to work with.
|
490 |
$loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
|
491 |
wp_localize_script(
|
680 |
$ewwwdb = $wpdb;
|
681 |
}
|
682 |
global $optimized_list;
|
683 |
+
/* $queued_ids = array(); */
|
684 |
$image_count = 0;
|
685 |
$attachments_processed = 0;
|
686 |
$attachment_query = '';
|
687 |
$images = array();
|
688 |
$attachment_images = array();
|
689 |
$reset_images = array();
|
|
|
690 |
$field_formats = array(
|
691 |
'%s', // path.
|
692 |
'%s', // gallery.
|
700 |
set_transient( 'ewww_image_optimizer_no_scheduled_optimization', true, 60 * MINUTE_IN_SECONDS );
|
701 |
|
702 |
// Retrieve the time when the scan starts.
|
703 |
+
$started = microtime( true );
|
704 |
+
|
705 |
+
$max_query = intval( apply_filters( 'ewww_image_optimizer_count_optimized_queries', 4000 ) );
|
706 |
+
|
707 |
+
$attachment_ids = ewww_image_optimizer_get_unscanned_attachments( 'media', $max_query );
|
708 |
+
|
709 |
// Make the Force Re-optimize option persistent.
|
710 |
if ( ! empty( $_REQUEST['ewww_force'] ) ) {
|
711 |
set_transient( 'ewww_image_optimizer_force_reopt', true, HOUR_IN_SECONDS );
|
723 |
|
724 |
list( $bad_attachments, $bad_attachment ) = ewww_image_optimizer_get_bad_attachments();
|
725 |
|
|
|
|
|
|
|
|
|
726 |
if ( empty( $attachment_ids ) ) {
|
727 |
// When the media library is finished, run the aux script function to scan for additional images.
|
728 |
ewww_image_optimizer_aux_images_script();
|
759 |
}
|
760 |
}
|
761 |
if ( ! empty( $attachment_ids ) && is_array( $attachment_ids ) ) {
|
762 |
+
/*
|
763 |
$selected_ids = null;
|
764 |
ewwwio_debug_message( 'remaining items: ' . count( $attachment_ids ) );
|
765 |
// Retrieve the attachment IDs that were pre-loaded in the database.
|
766 |
$selected_ids = array_splice( $attachment_ids, 0, $max_query );
|
767 |
array_walk( $selected_ids, 'intval' );
|
768 |
+
*/
|
769 |
+
ewwwio_debug_message( 'selected items: ' . count( $attachment_ids ) );
|
770 |
+
$attachments_in = implode( ',', $attachment_ids );
|
771 |
} else {
|
772 |
ewwwio_debug_message( 'no array found' );
|
773 |
ewwwio_ob_clean();
|
774 |
die( ewwwio_json_encode( array( 'error' => esc_html__( 'List of attachment IDs not found.', 'ewww-image-optimizer' ) ) ) );
|
775 |
}
|
776 |
|
777 |
+
// $selected_ids = $attachment_ids; // Might just be able to change everything over to $attachment_ids.
|
778 |
+
/* $failsafe_selected_ids = $selected_ids; */
|
779 |
|
780 |
$attachment_meta = ewww_image_optimizer_fetch_metadata_batch( $attachments_in );
|
781 |
$attachments_in = null;
|
791 |
|
792 |
ewwwio_debug_message( 'validated ' . count( $attachment_meta ) . ' attachment meta items' );
|
793 |
ewwwio_debug_message( 'remaining items after selection: ' . count( $attachment_ids ) );
|
794 |
+
foreach ( $attachment_ids as $selected_id ) {
|
795 |
$attachments_processed++;
|
796 |
if ( 0 == $attachments_processed % 5 && ( microtime( true ) - $started > apply_filters( 'ewww_image_optimizer_timeout', 22 ) || ! ewwwio_check_memory_available( 2194304 ) ) ) {
|
797 |
ewwwio_debug_message( 'time exceeded, or memory exceeded' );
|
798 |
ewww_image_optimizer_debug_log();
|
799 |
+
/* $attachment_ids = array_merge( $failsafe_selected_ids, $attachment_ids ); */
|
800 |
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
801 |
if ( is_array( $optimized_list ) ) {
|
802 |
set_transient( 'ewww_image_optimizer_low_memory_mode', 'low_memory', 600 ); // Keep us in low memory mode for up to 10 minutes.
|
808 |
}
|
809 |
}
|
810 |
ewww_image_optimizer_debug_log();
|
811 |
+
/* array_shift( $failsafe_selected_ids ); */
|
812 |
clearstatcache();
|
813 |
$pending = false;
|
814 |
$remote_file = false;
|
815 |
+
if ( in_array( $selected_id, $bad_attachments ) ) { // a known broken attachment, which would mean we already tried this once before...
|
816 |
+
ewwwio_debug_message( "skipping bad attachment $selected_id" );
|
817 |
+
ewww_image_optimizer_delete_queued_image( $selected_id );
|
818 |
+
continue;
|
819 |
+
}
|
820 |
if ( ! empty( $attachment_meta[ $selected_id ]['tinypng'] ) ) {
|
821 |
ewwwio_debug_message( "TinyPNG already compressed $selected_id" );
|
822 |
+
ewww_image_optimizer_delete_queued_image( $selected_id );
|
823 |
continue;
|
824 |
}
|
825 |
if ( empty( $attachment_meta[ $selected_id ]['meta'] ) ) {
|
843 |
}
|
844 |
|
845 |
if ( 'application/pdf' != $mime // NOT a pdf...
|
|
|
846 |
&& ( // AND...
|
847 |
empty( $meta ) // metadata is empty...
|
848 |
|| ( is_string( $meta ) && 'processing' == $meta ) // OR the string 'processing'...
|
863 |
}
|
864 |
|
865 |
if ( ! in_array( $mime, $enabled_types ) ) {
|
866 |
+
ewww_image_optimizer_delete_queued_image( $selected_id );
|
867 |
continue;
|
868 |
}
|
869 |
ewwwio_debug_message( "id: $selected_id and type: $mime" );
|
887 |
ewwwio_debug_message( "remote file possible: $file_path" );
|
888 |
if ( ! $file_path ) {
|
889 |
ewwwio_debug_message( 'no file found on remote storage, bailing' );
|
890 |
+
ewww_image_optimizer_delete_queued_image( $selected_id );
|
891 |
continue;
|
892 |
}
|
893 |
$remote_file = true;
|
894 |
} elseif ( ! $file_path ) {
|
895 |
ewwwio_debug_message( "no file path for $selected_id" );
|
896 |
+
ewww_image_optimizer_delete_queued_image( $selected_id );
|
897 |
continue;
|
898 |
}
|
899 |
ewww_image_optimizer_debug_log();
|
1163 |
if ( ! empty( $reset_images ) ) {
|
1164 |
ewwwio_debug_message( 'marking reset_images as pending' );
|
1165 |
ewww_image_optimizer_debug_log();
|
1166 |
+
ewww_image_optimizer_reset_images( $reset_images );
|
1167 |
}
|
1168 |
$reset_images = array();
|
1169 |
}
|
1172 |
if ( $pending ) {
|
1173 |
ewwwio_debug_message( "$selected_id added to queue" );
|
1174 |
ewww_image_optimizer_debug_log();
|
1175 |
+
/* $queued_ids[] = $selected_id; */
|
1176 |
+
ewww_image_optimizer_update_scanned_image( $selected_id );
|
1177 |
+
} else {
|
1178 |
+
ewww_image_optimizer_delete_queued_image( $selected_id );
|
1179 |
}
|
1180 |
$attachment_images = array();
|
1181 |
ewwwio_debug_message( 'checking for bad attachment' );
|
1184 |
ewwwio_debug_message( 'found bad attachment, bailing to reset the counter' );
|
1185 |
ewww_image_optimizer_debug_log();
|
1186 |
if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
|
1187 |
+
/* $attachment_ids = array_merge( $failsafe_selected_ids, $attachment_ids ); */
|
1188 |
break 2;
|
1189 |
}
|
1190 |
}
|
1191 |
} // End foreach().
|
1192 |
// End of loop for the selected_id.
|
1193 |
+
ewwwio_debug_message( 'finished foreach of attachment_ids' );
|
1194 |
ewww_image_optimizer_debug_log();
|
1195 |
+
|
1196 |
+
/*
|
1197 |
+
REMOVE
|
1198 |
update_option( 'ewww_image_optimizer_scanning_attachments', $attachment_ids, false );
|
1199 |
$attachments_queued = get_option( 'ewww_image_optimizer_bulk_attachments' );
|
1200 |
if ( empty( $attachments_queued ) || ! is_array( $attachments_queued ) ) {
|
1207 |
update_option( 'ewww_image_optimizer_bulk_attachments', array_merge( $attachments_queued, $queued_ids ), false );
|
1208 |
}
|
1209 |
$queued_ids = array();
|
1210 |
+
*/
|
1211 |
ewwwio_debug_message( 'finished a loop in the while, going back for more possibly' );
|
1212 |
+
$attachment_ids = ewww_image_optimizer_get_unscanned_attachments( 'media', $max_query );
|
1213 |
ewww_image_optimizer_debug_log();
|
1214 |
} // End while().
|
1215 |
+
ewwwio_debug_message( 'done for this request, wrapping up' );
|
1216 |
ewww_image_optimizer_debug_log();
|
1217 |
if ( ! empty( $images ) ) {
|
1218 |
ewww_image_optimizer_mass_insert( $wpdb->ewwwio_images, $images, $field_formats );
|
1219 |
}
|
1220 |
if ( ! empty( $reset_images ) ) {
|
1221 |
+
/* $ewwwdb->query( "UPDATE $ewwwdb->ewwwio_images SET pending = 1, updated = updated WHERE id IN (" . implode( ',', $reset_images ) . ')' ); */
|
1222 |
}
|
1223 |
+
ewww_image_optimizer_reset_images( $reset_images );
|
1224 |
if ( 250 > $attachments_processed ) { // in-memory table is too slow.
|
1225 |
ewwwio_debug_message( 'using in-memory table is too slow, switching to plan b' );
|
1226 |
set_transient( 'ewww_image_optimizer_low_memory_mode', 'slow_list', 600 ); // Put it in low memory mode for at least 10 minutes.
|
1227 |
}
|
|
|
1228 |
ewww_image_optimizer_debug_log();
|
1229 |
+
|
1230 |
+
/*
|
1231 |
+
REMOVE
|
1232 |
update_option( 'ewww_image_optimizer_scanning_attachments', $attachment_ids, false );
|
1233 |
if ( ! empty( $queued_ids ) ) {
|
1234 |
$attachments_queued = get_option( 'ewww_image_optimizer_bulk_attachments' );
|
1242 |
update_option( 'ewww_image_optimizer_bulk_attachments', array_merge( $attachments_queued, $queued_ids ), false );
|
1243 |
}
|
1244 |
}
|
1245 |
+
*/
|
1246 |
$elapsed = microtime( true ) - $started;
|
1247 |
ewwwio_debug_message( "counting images took $elapsed seconds" );
|
1248 |
ewwwio_memory( __FUNCTION__ );
|
1252 |
}
|
1253 |
$loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
|
1254 |
$notice = ( 'low_memory' == get_transient( 'ewww_image_optimizer_low_memory_mode' ) ? esc_html__( "Increasing PHP's memory_limit setting will allow for faster scanning with fewer database queries. Please allow up to 10 minutes for changes to memory limit to be detected.", 'ewww-image-optimizer' ) : '' );
|
1255 |
+
$remaining = ewww_image_optimizer_count_unscanned_attachments();
|
1256 |
+
if ( $remaining ) {
|
1257 |
ewwwio_ob_clean();
|
1258 |
die(
|
1259 |
ewwwio_json_encode(
|
1260 |
array(
|
1261 |
/* translators: %d: number of images */
|
1262 |
+
'remaining' => sprintf( esc_html__( 'Stage 1, %d images left to scan.', 'ewww-image-optimizer' ), $remaining ) . " <img src='$loading_image' />",
|
1263 |
'notice' => $notice,
|
1264 |
'bad_attachment' => $bad_attachment,
|
1265 |
)
|
1308 |
die( ewwwio_json_encode( array( 'error' => esc_html__( 'Access token has expired, please reload the page.', 'ewww-image-optimizer' ) ) ) );
|
1309 |
}
|
1310 |
session_write_close();
|
1311 |
+
$output = array();
|
1312 |
+
|
1313 |
+
/*
|
1314 |
$attachments = get_option( 'ewww_image_optimizer_bulk_attachments' );
|
1315 |
if ( ! is_array( $attachments ) && ! empty( $attachments ) ) {
|
1316 |
$attachments = unserialize( $attachments );
|
1349 |
}
|
1350 |
}
|
1351 |
}
|
1352 |
+
*/
|
1353 |
// Update the 'bulk resume' option to show that an operation is in progress.
|
1354 |
update_option( 'ewww_image_optimizer_bulk_resume', 'true' );
|
1355 |
+
// $attachment = (int) array_shift( $attachments );
|
1356 |
+
list( $attachment ) = ewww_image_optimizer_get_queued_attachments( 'media', 1 );
|
1357 |
ewwwio_debug_message( "first image: $attachment" );
|
1358 |
$first_image = new EWWW_Image( $attachment, 'media' );
|
1359 |
$file = $first_image->file;
|
1574 |
}
|
1575 |
$batch_image_limit = ( empty( $_REQUEST['ewww_batch_limit'] ) ? 999 : 1 );
|
1576 |
// Get the 'bulk attachments' with a list of IDs remaining.
|
1577 |
+
// $attachments = get_option( 'ewww_image_optimizer_bulk_attachments' );.
|
1578 |
+
$attachments = ewww_image_optimizer_get_queued_attachments( 'media', $batch_image_limit );
|
1579 |
if ( ! empty( $attachments ) && is_array( $attachments ) ) {
|
1580 |
$attachment = (int) $attachments[0];
|
1581 |
} else {
|
1694 |
}
|
1695 |
// When an image (attachment) is done, pull the next attachment ID off the stack.
|
1696 |
if ( ( 'full' == $next_image->resize || empty( $next_image->resize ) ) && ! empty( $attachment ) && $attachment != $next_image->attachment_id ) {
|
1697 |
+
ewww_image_optimizer_delete_queued_image( $attachment );
|
1698 |
+
$attachment = (int) array_shift( $attachments ); // Pull the first image off the stack.
|
1699 |
if ( ! empty( $attachments ) && is_array( $attachments ) ) {
|
1700 |
$attachment = (int) $attachments[0]; // Then grab the next one (if any are left).
|
1701 |
} else {
|
1707 |
$time_adjustment = $image->time_estimate();
|
1708 |
} // End while().
|
1709 |
|
1710 |
+
ewwwio_debug_message( 'ending bulk loop for now' );
|
1711 |
// Calculate how much time has elapsed since we started.
|
1712 |
$elapsed = microtime( true ) - $started;
|
1713 |
// Output how much time has elapsed since we started.
|
1721 |
/* translators: %s: number of seconds */
|
1722 |
$output['results'] .= sprintf( '<p>' . esc_html( _n( 'Elapsed: %s second', 'Elapsed: %s seconds', $elapsed, 'ewww-image-optimizer' ) ) . '</p>', number_format_i18n( $elapsed ) );
|
1723 |
// Store the updated list of attachment IDs back in the 'bulk_attachments' option.
|
1724 |
+
// update_option( 'ewww_image_optimizer_bulk_attachments', $attachments, false );.
|
1725 |
if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) {
|
1726 |
global $ewww_debug;
|
1727 |
$debug_button = esc_html__( 'Show Debug Output', 'ewww-image-optimizer' );
|
1770 |
// All done, so we can update the bulk options with empty values.
|
1771 |
update_option( 'ewww_image_optimizer_aux_resume', '' );
|
1772 |
update_option( 'ewww_image_optimizer_bulk_resume', '' );
|
1773 |
+
// update_option( 'ewww_image_optimizer_bulk_attachments', '', false );.
|
1774 |
delete_transient( 'ewww_image_optimizer_skip_aux' );
|
1775 |
delete_transient( 'ewww_image_optimizer_force_reopt' );
|
1776 |
// Let the user know we are done.
|
changelog.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
= 4.5.3 =
|
2 |
* fixed: ExactDN duplicates srcset instead of replacing it
|
3 |
* security: remote code execution, low exposure
|
1 |
+
= 4.6.0 =
|
2 |
+
* added: preserve animations in GIF images during resize operations for sites using Imagick extension
|
3 |
+
* changed: EXACTDN_EXCLUDE applies to all resources, including images, CSS, JS, fonts, etc.
|
4 |
+
* changed: API/ExactDN preserves color profiles, even when removing image metadata
|
5 |
+
* changed: new queue table for bulk optimizer to avoid exceeding max packet size for MySQL
|
6 |
+
* changed: unit tests run on PHP 7.3 also
|
7 |
+
* fixed: too many settings updates when trying to prevent slow queries
|
8 |
+
* fixed: ExactDN rewrites urls to static HTML files
|
9 |
+
* fixed: ExactDN skips 1x url in some cases, causing browser upscaling
|
10 |
+
* fixed: PHP notice when EXACTDN_EXCLUDE is defined
|
11 |
+
* fixed: race condition in Alt WebP prevents Webp derivatives from replacing the originals
|
12 |
+
|
13 |
= 4.5.3 =
|
14 |
* fixed: ExactDN duplicates srcset instead of replacing it
|
15 |
* security: remote code execution, low exposure
|
classes/class-ewwwio-alt-webp.php
CHANGED
@@ -16,12 +16,12 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
16 |
class EWWWIO_Alt_Webp extends EWWWIO_Page_Parser {
|
17 |
|
18 |
/**
|
19 |
-
* The Alt WebP inline script contents. Current length
|
20 |
*
|
21 |
* @access private
|
22 |
* @var string $inline_script
|
23 |
*/
|
24 |
-
private $inline_script = 'var Arrive=function(w,e,c){"use strict";if(w.MutationObserver&&"undefined"!=typeof HTMLElement){var a,t,r=0,d=(a=HTMLElement.prototype.matches||HTMLElement.prototype.webkitMatchesSelector||HTMLElement.prototype.mozMatchesSelector||HTMLElement.prototype.msMatchesSelector,{matchesSelector:function(e,t){return e instanceof HTMLElement&&a.call(e,t)},addMethod:function(e,t,a){var r=e[t];e[t]=function(){return a.length==arguments.length?a.apply(this,arguments):"function"==typeof r?r.apply(this,arguments):void 0}},callCallbacks:function(e,t){t&&t.options.onceOnly&&1==t.firedElems.length&&(e=[e[0]]);for(var a,r=0;a=e[r];r++)a&&a.callback&&a.callback.call(a.elem,a.elem);t&&t.options.onceOnly&&1==t.firedElems.length&&t.me.unbindEventWithSelectorAndCallback.call(t.target,t.selector,t.callback)},checkChildNodesRecursively:function(e,t,a,r){for(var i,n=0;i=e[n];n++)a(i,t,r)&&r.push({callback:t.callback,elem:i}),0<i.childNodes.length&&d.checkChildNodesRecursively(i.childNodes,t,a,r)},mergeArrays:function(e,t){var a,r={};for(a in e)e.hasOwnProperty(a)&&(r[a]=e[a]);for(a in t)t.hasOwnProperty(a)&&(r[a]=t[a]);return r},toElementsArray:function(e){return void 0===e||"number"==typeof e.length&&e!==w||(e=[e]),e}}),u=((t=function(){this._eventsBucket=[],this._beforeAdding=null,this._beforeRemoving=null}).prototype.addEvent=function(e,t,a,r){var i={target:e,selector:t,options:a,callback:r,firedElems:[]};return this._beforeAdding&&this._beforeAdding(i),this._eventsBucket.push(i),i},t.prototype.removeEvent=function(e){for(var t,a=this._eventsBucket.length-1;t=this._eventsBucket[a];a--)if(e(t)){this._beforeRemoving&&this._beforeRemoving(t);var r=this._eventsBucket.splice(a,1);r&&r.length&&(r[0].callback=null)}},t.prototype.beforeAdding=function(e){this._beforeAdding=e},t.prototype.beforeRemoving=function(e){this._beforeRemoving=e},t),l=function(i,n){var l=new u,s=this,o={fireOnAttributesModification:!1};return l.beforeAdding(function(t){var e,a=t.target;a!==w.document&&a!==w||(a=document.getElementsByTagName("html")[0]),e=new MutationObserver(function(e){n.call(this,e,t)});var r=i(t.options);e.observe(a,r),t.observer=e,t.me=s}),l.beforeRemoving(function(e){e.observer.disconnect()}),this.bindEvent=function(e,t,a){t=d.mergeArrays(o,t);for(var r=d.toElementsArray(this),i=0;i<r.length;i++)l.addEvent(r[i],e,t,a)},this.unbindEvent=function(){var a=d.toElementsArray(this);l.removeEvent(function(e){for(var t=0;t<a.length;t++)if(this===c||e.target===a[t])return!0;return!1})},this.unbindEventWithSelectorOrCallback=function(a){var e,r=d.toElementsArray(this),i=a;e="function"==typeof a?function(e){for(var t=0;t<r.length;t++)if((this===c||e.target===r[t])&&e.callback===i)return!0;return!1}:function(e){for(var t=0;t<r.length;t++)if((this===c||e.target===r[t])&&e.selector===a)return!0;return!1},l.removeEvent(e)},this.unbindEventWithSelectorAndCallback=function(a,r){var i=d.toElementsArray(this);l.removeEvent(function(e){for(var t=0;t<i.length;t++)if((this===c||e.target===i[t])&&e.selector===a&&e.callback===r)return!0;return!1})},this},i=new function(){var o={fireOnAttributesModification:!1,onceOnly:!1,existing:!1};function n(e,t,a){return!(!d.matchesSelector(e,t.selector)||(e._id===c&&(e._id=r++),-1!=t.firedElems.indexOf(e._id))||(t.firedElems.push(e._id),0))}var w=(i=new l(function(e){var t={attributes:!1,childList:!0,subtree:!0};return e.fireOnAttributesModification&&(t.attributes=!0),t},function(e,i){e.forEach(function(e){var t=e.addedNodes,a=e.target,r=[];null!==t&&0<t.length?d.checkChildNodesRecursively(t,i,n,r):"attributes"===e.type&&n(a,i)&&r.push({callback:i.callback,elem:a}),d.callCallbacks(r,i)})})).bindEvent;return i.bindEvent=function(e,t,a){void 0===a?(a=t,t=o):t=d.mergeArrays(o,t);var r=d.toElementsArray(this);if(t.existing){for(var i=[],n=0;n<r.length;n++)for(var l=r[n].querySelectorAll(e),s=0;s<l.length;s++)i.push({callback:a,elem:l[s]});if(t.onceOnly&&i.length)return a.call(i[0].elem,i[0].elem);setTimeout(d.callCallbacks,1,i)}w.call(this,e,t,a)},i},s=new function(){var r={};function i(e,t){return d.matchesSelector(e,t.selector)}var n=(s=new l(function(){return{childList:!0,subtree:!0}},function(e,r){e.forEach(function(e){var t=e.removedNodes,a=[];null!==t&&0<t.length&&d.checkChildNodesRecursively(t,r,i,a),d.callCallbacks(a,r)})})).bindEvent;return s.bindEvent=function(e,t,a){void 0===a?(a=t,t=r):t=d.mergeArrays(r,t),n.call(this,e,t,a)},s};e&&h(e.fn),h(HTMLElement.prototype),h(NodeList.prototype),h(HTMLCollection.prototype),h(HTMLDocument.prototype),h(Window.prototype);var n={};return o(i,n,"unbindAllArrive"),o(s,n,"unbindAllLeave"),n}function o(e,t,a){d.addMethod(t,a,e.unbindEvent),d.addMethod(t,a,e.unbindEventWithSelectorOrCallback),d.addMethod(t,a,e.unbindEventWithSelectorAndCallback)}function h(e){e.arrive=i.bindEvent,o(i,e,"unbindArrive"),e.leave=s.bindEvent,o(s,e,"unbindLeave")}}(window,"undefined"==typeof jQuery?null:jQuery,void 0);function check_webp_feature(e,t){var a=new Image;a.onload=function(){ewww_webp_supported=0<a.width&&0<a.height,t(ewww_webp_supported)},a.onerror=function(){t(ewww_webp_supported=!1)},a.src="data:image/webp;base64,"+{alpha:"UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",animation:"UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"}[e]}function ewww_load_images(t){!function(n){n.fn.extend({ewwwattr:function(e,t){return void 0!==t&&!1!==t&&this.attr(e,t),this}});t&&(n(".batch-image img, .image-wrapper a, .ngg-pro-masonry-item a, .ngg-galleria-offscreen-seo-wrapper a").each(function(){n(this).ewwwattr("data-src",n(this).attr("data-webp")),n(this).ewwwattr("data-thumbnail",n(this).attr("data-webp-thumbnail"))}),n(".image-wrapper a, .ngg-pro-masonry-item a").each(function(){n(this).ewwwattr("href",n(this).attr("data-webp"))}),n(".rev_slider ul li").each(function(){n(this).ewwwattr("data-thumb",n(this).attr("data-webp-thumb"));for(var e=1;e<11;)n(this).ewwwattr("data-param"+e,n(this).attr("data-webp-param"+e)),e++}),n(".rev_slider img").each(function(){n(this).ewwwattr("data-lazyload",n(this).attr("data-webp-lazyload"))}),n("div.woocommerce-product-gallery__image").each(function(){n(this).ewwwattr("data-thumb",n(this).attr("data-webp-thumb"))})),n("video").each(function(){t?n(this).ewwwattr("poster",n(this).attr("data-poster-webp")):n(this).ewwwattr("poster",n(this).attr("data-poster-image"))}),n("img.ewww_webp_lazy_load").each(function(){if(t){n(this).ewwwattr("data-lazy-srcset",n(this).attr("data-lazy-srcset-webp")),n(this).ewwwattr("data-srcset",n(this).attr("data-srcset-webp")),n(this).ewwwattr("data-lazy-src",n(this).attr("data-lazy-src-webp")),n(this).ewwwattr("data-src",n(this).attr("data-src-webp")),n(this).ewwwattr("data-orig-file",n(this).attr("data-webp-orig-file")),n(this).ewwwattr("data-medium-file",n(this).attr("data-webp-medium-file")),n(this).ewwwattr("data-large-file",n(this).attr("data-webp-large-file"));var e=n(this).attr("srcset");void 0!==e&&!1!==e&&e.includes("R0lGOD")&&n(this).ewwwattr("src",n(this).attr("data-lazy-src-webp"))}n(this).removeClass("ewww_webp_lazy_load")}),n(".ewww_webp").each(function(){var e=document.createElement("img");t?(n(e).ewwwattr("src",n(this).attr("data-webp")),n(e).ewwwattr("srcset",n(this).attr("data-srcset-webp")),n(e).ewwwattr("data-orig-file",n(this).attr("data-orig-file")),n(e).ewwwattr("data-orig-file",n(this).attr("data-webp-orig-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-medium-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-webp-medium-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-large-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-webp-large-file")),n(e).ewwwattr("data-large_image",n(this).attr("data-large_image")),n(e).ewwwattr("data-large_image",n(this).attr("data-webp-large_image")),n(e).ewwwattr("data-src",n(this).attr("data-src")),n(e).ewwwattr("data-src",n(this).attr("data-webp-src"))):(n(e).ewwwattr("src",n(this).attr("data-img")),n(e).ewwwattr("srcset",n(this).attr("data-srcset-img")),n(e).ewwwattr("data-orig-file",n(this).attr("data-orig-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-medium-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-large-file")),n(e).ewwwattr("data-large_image",n(this).attr("data-large_image")),n(e).ewwwattr("data-src",n(this).attr("data-src"))),e=function(e,t){for(var a=["align","alt","border","crossorigin","height","hspace","ismap","longdesc","usemap","vspace","width","accesskey","class","contenteditable","contextmenu","dir","draggable","dropzone","hidden","id","lang","spellcheck","style","tabindex","title","translate","sizes","data-caption","data-attachment-id","data-permalink","data-orig-size","data-comments-opened","data-image-meta","data-image-title","data-image-description","data-event-trigger","data-highlight-color","data-highlight-opacity","data-highlight-border-color","data-highlight-border-width","data-highlight-border-opacity","data-no-lazy","data-lazy","data-large_image_width","data-large_image_height"],r=0,i=a.length;r<i;r++)n(t).ewwwattr(a[r],n(e).attr("data-"+a[r]));return t}(this,e),n(this).after(e),n(this).removeClass("ewww_webp")})}(jQuery),jQuery.fn.isotope&&jQuery.fn.imagesLoaded&&(jQuery(".fusion-posts-container-infinite").imagesLoaded(function(){jQuery(".fusion-posts-container-infinite").hasClass("isotope")&&jQuery(".fusion-posts-container-infinite").isotope()}),jQuery(".fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper").imagesLoaded(function(){jQuery(".fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper").isotope()}))}var ewww_webp_supported=!1,ewww_jquery_waiting_timer=0;function ewww_ngg_plus_parse_galleries(e){e&&jQuery.each(galleries,function(e,t){galleries[e].images_list=ewww_ngg_plus_parse_image_list(t.images_list)})}function ewww_ngg_plus_load_galleries(e){var i;e&&((i=jQuery)(window).on("ngg.galleria.themeadded",function(e,t){window.ngg_galleria._create_backup=window.ngg_galleria.create,window.ngg_galleria.create=function(e,t){var a=i(e).data("id");return galleries["gallery_"+a].images_list=ewww_ngg_plus_parse_image_list(galleries["gallery_"+a].images_list),window.ngg_galleria._create_backup(e,t)}}),i(window).on("override_nplModal_methods",function(e,r){r._set_events_backup=r.set_events,r.set_events=function(){return i("#npl_content").bind("npl_images_ready",function(e,t){var a=r.fetch_images.gallery_image_cache[t];a=ewww_ngg_plus_parse_image_list(a)}),r._set_events_backup()}}))}function ewww_ngg_plus_parse_image_list(i){var e;return(e=jQuery).each(i,function(a,r){void 0!==r["image-webp"]&&(i[a].image=r["image-webp"],delete i[a]["image-webp"]),void 0!==r["thumb-webp"]&&(i[a].thumb=r["thumb-webp"],delete i[a]["thumb-webp"]),void 0!==r.full_image_webp&&(i[a].full_image=r.full_image_webp,delete i[a].full_image_webp),void 0!==r.srcsets&&e.each(r.srcsets,function(e,t){void 0!==r.srcsets[e+"-webp"]&&(i[a].srcsets[e]=r.srcsets[e+"-webp"],delete i[a].srcsets[e+"-webp"])}),void 0!==r.full_srcsets&&e.each(r.full_srcsets,function(e,t){void 0!==r.full_srcsets[e+"-webp"]&&(i[a].full_srcsets[e]=r.full_srcsets[e+"-webp"],delete i[a].full_srcsets[e+"-webp"])})}),i}ewww_jquery_waiting=setInterval(function(){if(window.jQuery){check_webp_feature("alpha",ewww_load_images),check_webp_feature("alpha",ewww_ngg_plus_load_galleries),document.arrive(".ewww_webp",function(){ewww_load_images(ewww_webp_supported)});var e=0,t=setInterval(function(){"undefined"!=typeof galleries&&(check_webp_feature("alpha",ewww_ngg_plus_parse_galleries),clearInterval(t)),1e3<(e+=25)&&clearInterval(t)},25);clearInterval(ewww_jquery_waiting)}1e4<(ewww_jquery_waiting_timer+=100)&&clearInterval(ewww_jquery_waiting)},100);';
|
25 |
|
26 |
/**
|
27 |
* Indicates if we are filtering ExactDN urls.
|
16 |
class EWWWIO_Alt_Webp extends EWWWIO_Page_Parser {
|
17 |
|
18 |
/**
|
19 |
+
* The Alt WebP inline script contents. Current length 11704.
|
20 |
*
|
21 |
* @access private
|
22 |
* @var string $inline_script
|
23 |
*/
|
24 |
+
private $inline_script = 'var Arrive=function(c,e,w){"use strict";if(c.MutationObserver&&"undefined"!=typeof HTMLElement){var a,t,r=0,d=(a=HTMLElement.prototype.matches||HTMLElement.prototype.webkitMatchesSelector||HTMLElement.prototype.mozMatchesSelector||HTMLElement.prototype.msMatchesSelector,{matchesSelector:function(e,t){return e instanceof HTMLElement&&a.call(e,t)},addMethod:function(e,t,a){var r=e[t];e[t]=function(){return a.length==arguments.length?a.apply(this,arguments):"function"==typeof r?r.apply(this,arguments):void 0}},callCallbacks:function(e,t){t&&t.options.onceOnly&&1==t.firedElems.length&&(e=[e[0]]);for(var a,r=0;a=e[r];r++)a&&a.callback&&a.callback.call(a.elem,a.elem);t&&t.options.onceOnly&&1==t.firedElems.length&&t.me.unbindEventWithSelectorAndCallback.call(t.target,t.selector,t.callback)},checkChildNodesRecursively:function(e,t,a,r){for(var i,n=0;i=e[n];n++)a(i,t,r)&&r.push({callback:t.callback,elem:i}),0<i.childNodes.length&&d.checkChildNodesRecursively(i.childNodes,t,a,r)},mergeArrays:function(e,t){var a,r={};for(a in e)e.hasOwnProperty(a)&&(r[a]=e[a]);for(a in t)t.hasOwnProperty(a)&&(r[a]=t[a]);return r},toElementsArray:function(e){return void 0===e||"number"==typeof e.length&&e!==c||(e=[e]),e}}),u=((t=function(){this._eventsBucket=[],this._beforeAdding=null,this._beforeRemoving=null}).prototype.addEvent=function(e,t,a,r){var i={target:e,selector:t,options:a,callback:r,firedElems:[]};return this._beforeAdding&&this._beforeAdding(i),this._eventsBucket.push(i),i},t.prototype.removeEvent=function(e){for(var t,a=this._eventsBucket.length-1;t=this._eventsBucket[a];a--)if(e(t)){this._beforeRemoving&&this._beforeRemoving(t);var r=this._eventsBucket.splice(a,1);r&&r.length&&(r[0].callback=null)}},t.prototype.beforeAdding=function(e){this._beforeAdding=e},t.prototype.beforeRemoving=function(e){this._beforeRemoving=e},t),l=function(i,n){var l=new u,s=this,o={fireOnAttributesModification:!1};return l.beforeAdding(function(t){var e,a=t.target;a!==c.document&&a!==c||(a=document.getElementsByTagName("html")[0]),e=new MutationObserver(function(e){n.call(this,e,t)});var r=i(t.options);e.observe(a,r),t.observer=e,t.me=s}),l.beforeRemoving(function(e){e.observer.disconnect()}),this.bindEvent=function(e,t,a){t=d.mergeArrays(o,t);for(var r=d.toElementsArray(this),i=0;i<r.length;i++)l.addEvent(r[i],e,t,a)},this.unbindEvent=function(){var a=d.toElementsArray(this);l.removeEvent(function(e){for(var t=0;t<a.length;t++)if(this===w||e.target===a[t])return!0;return!1})},this.unbindEventWithSelectorOrCallback=function(a){var e,r=d.toElementsArray(this),i=a;e="function"==typeof a?function(e){for(var t=0;t<r.length;t++)if((this===w||e.target===r[t])&&e.callback===i)return!0;return!1}:function(e){for(var t=0;t<r.length;t++)if((this===w||e.target===r[t])&&e.selector===a)return!0;return!1},l.removeEvent(e)},this.unbindEventWithSelectorAndCallback=function(a,r){var i=d.toElementsArray(this);l.removeEvent(function(e){for(var t=0;t<i.length;t++)if((this===w||e.target===i[t])&&e.selector===a&&e.callback===r)return!0;return!1})},this},i=new function(){var o={fireOnAttributesModification:!1,onceOnly:!1,existing:!1};function n(e,t,a){return!(!d.matchesSelector(e,t.selector)||(e._id===w&&(e._id=r++),-1!=t.firedElems.indexOf(e._id))||(t.firedElems.push(e._id),0))}var c=(i=new l(function(e){var t={attributes:!1,childList:!0,subtree:!0};return e.fireOnAttributesModification&&(t.attributes=!0),t},function(e,i){e.forEach(function(e){var t=e.addedNodes,a=e.target,r=[];null!==t&&0<t.length?d.checkChildNodesRecursively(t,i,n,r):"attributes"===e.type&&n(a,i)&&r.push({callback:i.callback,elem:a}),d.callCallbacks(r,i)})})).bindEvent;return i.bindEvent=function(e,t,a){void 0===a?(a=t,t=o):t=d.mergeArrays(o,t);var r=d.toElementsArray(this);if(t.existing){for(var i=[],n=0;n<r.length;n++)for(var l=r[n].querySelectorAll(e),s=0;s<l.length;s++)i.push({callback:a,elem:l[s]});if(t.onceOnly&&i.length)return a.call(i[0].elem,i[0].elem);setTimeout(d.callCallbacks,1,i)}c.call(this,e,t,a)},i},s=new function(){var r={};function i(e,t){return d.matchesSelector(e,t.selector)}var n=(s=new l(function(){return{childList:!0,subtree:!0}},function(e,r){e.forEach(function(e){var t=e.removedNodes,a=[];null!==t&&0<t.length&&d.checkChildNodesRecursively(t,r,i,a),d.callCallbacks(a,r)})})).bindEvent;return s.bindEvent=function(e,t,a){void 0===a?(a=t,t=r):t=d.mergeArrays(r,t),n.call(this,e,t,a)},s};e&&h(e.fn),h(HTMLElement.prototype),h(NodeList.prototype),h(HTMLCollection.prototype),h(HTMLDocument.prototype),h(Window.prototype);var n={};return o(i,n,"unbindAllArrive"),o(s,n,"unbindAllLeave"),n}function o(e,t,a){d.addMethod(t,a,e.unbindEvent),d.addMethod(t,a,e.unbindEventWithSelectorOrCallback),d.addMethod(t,a,e.unbindEventWithSelectorAndCallback)}function h(e){e.arrive=i.bindEvent,o(i,e,"unbindArrive"),e.leave=s.bindEvent,o(s,e,"unbindLeave")}}(window,"undefined"==typeof jQuery?null:jQuery,void 0);function check_webp_feature(e,t){var a=new Image;a.onload=function(){var e=0<a.width&&0<a.height;t(e)},a.onerror=function(){t(!1)},a.src="data:image/webp;base64,"+{alpha:"UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",animation:"UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"}[e]}function ewww_load_images(t){!function(n){n.fn.extend({ewwwattr:function(e,t){return void 0!==t&&!1!==t&&this.attr(e,t),this}});t&&(n(".batch-image img, .image-wrapper a, .ngg-pro-masonry-item a, .ngg-galleria-offscreen-seo-wrapper a").each(function(){n(this).ewwwattr("data-src",n(this).attr("data-webp")),n(this).ewwwattr("data-thumbnail",n(this).attr("data-webp-thumbnail"))}),n(".image-wrapper a, .ngg-pro-masonry-item a").each(function(){n(this).ewwwattr("href",n(this).attr("data-webp"))}),n(".rev_slider ul li").each(function(){n(this).ewwwattr("data-thumb",n(this).attr("data-webp-thumb"));for(var e=1;e<11;)n(this).ewwwattr("data-param"+e,n(this).attr("data-webp-param"+e)),e++}),n(".rev_slider img").each(function(){n(this).ewwwattr("data-lazyload",n(this).attr("data-webp-lazyload"))}),n("div.woocommerce-product-gallery__image").each(function(){n(this).ewwwattr("data-thumb",n(this).attr("data-webp-thumb"))})),n("video").each(function(){t?n(this).ewwwattr("poster",n(this).attr("data-poster-webp")):n(this).ewwwattr("poster",n(this).attr("data-poster-image"))}),n("img.ewww_webp_lazy_load").each(function(){if(t){n(this).ewwwattr("data-lazy-srcset",n(this).attr("data-lazy-srcset-webp")),n(this).ewwwattr("data-srcset",n(this).attr("data-srcset-webp")),n(this).ewwwattr("data-lazy-src",n(this).attr("data-lazy-src-webp")),n(this).ewwwattr("data-src",n(this).attr("data-src-webp")),n(this).ewwwattr("data-orig-file",n(this).attr("data-webp-orig-file")),n(this).ewwwattr("data-medium-file",n(this).attr("data-webp-medium-file")),n(this).ewwwattr("data-large-file",n(this).attr("data-webp-large-file"));var e=n(this).attr("srcset");void 0!==e&&!1!==e&&e.includes("R0lGOD")&&n(this).ewwwattr("src",n(this).attr("data-lazy-src-webp"))}n(this).removeClass("ewww_webp_lazy_load")}),n(".ewww_webp").each(function(){var e=document.createElement("img");t?(n(e).ewwwattr("src",n(this).attr("data-webp")),n(e).ewwwattr("srcset",n(this).attr("data-srcset-webp")),n(e).ewwwattr("data-orig-file",n(this).attr("data-orig-file")),n(e).ewwwattr("data-orig-file",n(this).attr("data-webp-orig-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-medium-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-webp-medium-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-large-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-webp-large-file")),n(e).ewwwattr("data-large_image",n(this).attr("data-large_image")),n(e).ewwwattr("data-large_image",n(this).attr("data-webp-large_image")),n(e).ewwwattr("data-src",n(this).attr("data-src")),n(e).ewwwattr("data-src",n(this).attr("data-webp-src"))):(n(e).ewwwattr("src",n(this).attr("data-img")),n(e).ewwwattr("srcset",n(this).attr("data-srcset-img")),n(e).ewwwattr("data-orig-file",n(this).attr("data-orig-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-medium-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-large-file")),n(e).ewwwattr("data-large_image",n(this).attr("data-large_image")),n(e).ewwwattr("data-src",n(this).attr("data-src"))),e=function(e,t){for(var a=["align","alt","border","crossorigin","height","hspace","ismap","longdesc","usemap","vspace","width","accesskey","class","contenteditable","contextmenu","dir","draggable","dropzone","hidden","id","lang","spellcheck","style","tabindex","title","translate","sizes","data-caption","data-attachment-id","data-permalink","data-orig-size","data-comments-opened","data-image-meta","data-image-title","data-image-description","data-event-trigger","data-highlight-color","data-highlight-opacity","data-highlight-border-color","data-highlight-border-width","data-highlight-border-opacity","data-no-lazy","data-lazy","data-large_image_width","data-large_image_height"],r=0,i=a.length;r<i;r++)n(t).ewwwattr(a[r],n(e).attr("data-"+a[r]));return t}(this,e),n(this).after(e),n(this).removeClass("ewww_webp")})}(jQuery),jQuery.fn.isotope&&jQuery.fn.imagesLoaded&&(jQuery(".fusion-posts-container-infinite").imagesLoaded(function(){jQuery(".fusion-posts-container-infinite").hasClass("isotope")&&jQuery(".fusion-posts-container-infinite").isotope()}),jQuery(".fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper").imagesLoaded(function(){jQuery(".fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper").isotope()}))}var ewww_jquery_waiting_timer=0;function ewww_ngg_plus_parse_galleries(e){e&&jQuery.each(galleries,function(e,t){galleries[e].images_list=ewww_ngg_plus_parse_image_list(t.images_list)})}function ewww_ngg_plus_load_galleries(e){var i;e&&((i=jQuery)(window).on("ngg.galleria.themeadded",function(e,t){window.ngg_galleria._create_backup=window.ngg_galleria.create,window.ngg_galleria.create=function(e,t){var a=i(e).data("id");return galleries["gallery_"+a].images_list=ewww_ngg_plus_parse_image_list(galleries["gallery_"+a].images_list),window.ngg_galleria._create_backup(e,t)}}),i(window).on("override_nplModal_methods",function(e,r){r._set_events_backup=r.set_events,r.set_events=function(){return i("#npl_content").bind("npl_images_ready",function(e,t){var a=r.fetch_images.gallery_image_cache[t];a=ewww_ngg_plus_parse_image_list(a)}),r._set_events_backup()}}))}function ewww_ngg_plus_parse_image_list(i){var e;return(e=jQuery).each(i,function(a,r){void 0!==r["image-webp"]&&(i[a].image=r["image-webp"],delete i[a]["image-webp"]),void 0!==r["thumb-webp"]&&(i[a].thumb=r["thumb-webp"],delete i[a]["thumb-webp"]),void 0!==r.full_image_webp&&(i[a].full_image=r.full_image_webp,delete i[a].full_image_webp),void 0!==r.srcsets&&e.each(r.srcsets,function(e,t){void 0!==r.srcsets[e+"-webp"]&&(i[a].srcsets[e]=r.srcsets[e+"-webp"],delete i[a].srcsets[e+"-webp"])}),void 0!==r.full_srcsets&&e.each(r.full_srcsets,function(e,t){void 0!==r.full_srcsets[e+"-webp"]&&(i[a].full_srcsets[e]=r.full_srcsets[e+"-webp"],delete i[a].full_srcsets[e+"-webp"])})}),i}ewww_jquery_waiting=setInterval(function(){if(window.jQuery){check_webp_feature("alpha",ewww_load_images),check_webp_feature("alpha",ewww_ngg_plus_load_galleries),document.arrive(".ewww_webp",function(){check_webp_feature("alpha",ewww_load_images)});var e=0,t=setInterval(function(){"undefined"!=typeof galleries&&(check_webp_feature("alpha",ewww_ngg_plus_parse_galleries),clearInterval(t)),1e3<(e+=25)&&clearInterval(t)},25);clearInterval(ewww_jquery_waiting)}1e4<(ewww_jquery_waiting_timer+=100)&&clearInterval(ewww_jquery_waiting)},100);';
|
25 |
|
26 |
/**
|
27 |
* Indicates if we are filtering ExactDN urls.
|
classes/class-ewwwio-gd-editor.php
CHANGED
@@ -309,11 +309,11 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
|
|
309 |
* @param bool $crop Optional. Scale by default, crop if true.
|
310 |
* @return bool|WP_Error
|
311 |
*/
|
312 |
-
|
|
|
313 |
if ( ( ! $max_w || $max_w >= $this->size['width'] ) && ( ! $max_h || $max_h >= $this->size['height'] ) ) {
|
314 |
return new WP_Error( 'image_resize_error', __( 'Image resize failed.' ) );
|
315 |
}
|
316 |
-
ewwwio_debug_message( '<b>wp_image_editor_gd::' . __FUNCTION__ . '()</b>' );
|
317 |
if ( defined( 'EWWWIO_EDITOR_AGR' ) && ! EWWWIO_EDITOR_AGR ) {
|
318 |
ewwwio_debug_message( 'AGR disabled' );
|
319 |
return parent::_resize( $max_w, $max_h, $crop );
|
@@ -386,6 +386,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
|
|
386 |
* @return true|WP_Error
|
387 |
*/
|
388 |
public function resize( $max_w, $max_h, $crop = false ) {
|
|
|
389 |
if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
|
390 |
return true;
|
391 |
}
|
@@ -431,6 +432,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
|
|
431 |
* @return array An array of resized images' metadata by size.
|
432 |
*/
|
433 |
public function multi_resize( $sizes ) {
|
|
|
434 |
$metadata = array();
|
435 |
$orig_size = $this->size;
|
436 |
foreach ( $sizes as $size => $size_data ) {
|
@@ -595,6 +597,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
|
|
595 |
* @return WP_Error|array The full path, base filename, and mimetype.
|
596 |
*/
|
597 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
|
|
598 |
global $ewww_defer;
|
599 |
global $ewww_preempt_editor;
|
600 |
if ( ! empty( $this->ewww_image ) && empty( $this->modified ) ) {
|
309 |
* @param bool $crop Optional. Scale by default, crop if true.
|
310 |
* @return bool|WP_Error
|
311 |
*/
|
312 |
+
protected function _resize( $max_w, $max_h, $crop = false ) {
|
313 |
+
ewwwio_debug_message( '<b>wp_image_editor_gd::' . __FUNCTION__ . '()</b>' );
|
314 |
if ( ( ! $max_w || $max_w >= $this->size['width'] ) && ( ! $max_h || $max_h >= $this->size['height'] ) ) {
|
315 |
return new WP_Error( 'image_resize_error', __( 'Image resize failed.' ) );
|
316 |
}
|
|
|
317 |
if ( defined( 'EWWWIO_EDITOR_AGR' ) && ! EWWWIO_EDITOR_AGR ) {
|
318 |
ewwwio_debug_message( 'AGR disabled' );
|
319 |
return parent::_resize( $max_w, $max_h, $crop );
|
386 |
* @return true|WP_Error
|
387 |
*/
|
388 |
public function resize( $max_w, $max_h, $crop = false ) {
|
389 |
+
ewwwio_debug_message( '<b>wp_image_editor_gd::' . __FUNCTION__ . '()</b>' );
|
390 |
if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
|
391 |
return true;
|
392 |
}
|
432 |
* @return array An array of resized images' metadata by size.
|
433 |
*/
|
434 |
public function multi_resize( $sizes ) {
|
435 |
+
ewwwio_debug_message( '<b>wp_image_editor_gd::' . __FUNCTION__ . '()</b>' );
|
436 |
$metadata = array();
|
437 |
$orig_size = $this->size;
|
438 |
foreach ( $sizes as $size => $size_data ) {
|
597 |
* @return WP_Error|array The full path, base filename, and mimetype.
|
598 |
*/
|
599 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
600 |
+
ewwwio_debug_message( '<b>wp_image_editor_gd::' . __FUNCTION__ . '()</b>' );
|
601 |
global $ewww_defer;
|
602 |
global $ewww_preempt_editor;
|
603 |
if ( ! empty( $this->ewww_image ) && empty( $this->modified ) ) {
|
classes/class-ewwwio-imagick-editor.php
CHANGED
@@ -25,6 +25,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
|
|
25 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
26 |
*/
|
27 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
|
|
28 |
global $ewww_defer;
|
29 |
global $ewww_preempt_editor;
|
30 |
if ( ! empty( $ewww_preempt_editor ) ) {
|
@@ -101,6 +102,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
|
|
101 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
102 |
*/
|
103 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
|
|
104 |
global $ewww_defer;
|
105 |
global $ewww_preempt_editor;
|
106 |
if ( ! empty( $ewww_preempt_editor ) ) {
|
@@ -177,6 +179,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
|
|
177 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
178 |
*/
|
179 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
|
|
180 |
global $ewww_defer;
|
181 |
global $ewww_preempt_editor;
|
182 |
if ( ! empty( $ewww_preempt_editor ) ) {
|
@@ -249,6 +252,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
|
|
249 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
250 |
*/
|
251 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
|
|
252 |
global $ewww_preempt_editor;
|
253 |
list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type );
|
254 |
if ( ! $filename ) {
|
@@ -346,17 +350,365 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
|
|
346 |
* @see WP_Image_Editor_Imagick
|
347 |
*/
|
348 |
class EWWWIO_Imagick_Editor extends WP_Image_Editor_Imagick {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
/**
|
350 |
* Saves a file from the image editor.
|
351 |
*
|
|
|
|
|
352 |
* @param resource $image An Imagick image object.
|
353 |
* @param string $filename Optional. The name of the file to be saved to.
|
354 |
* @param string $mime_type Optional. The mimetype of the file.
|
355 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
356 |
*/
|
357 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
|
|
358 |
global $ewww_defer;
|
359 |
global $ewww_preempt_editor;
|
|
|
|
|
|
|
360 |
if ( ! empty( $ewww_preempt_editor ) ) {
|
361 |
return parent::_save( $image, $filename, $mime_type );
|
362 |
}
|
25 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
26 |
*/
|
27 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
28 |
+
ewwwio_debug_message( '<b>wp_image_editor_imagick(wpthumb)::' . __FUNCTION__ . '()</b>' );
|
29 |
global $ewww_defer;
|
30 |
global $ewww_preempt_editor;
|
31 |
if ( ! empty( $ewww_preempt_editor ) ) {
|
102 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
103 |
*/
|
104 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
105 |
+
ewwwio_debug_message( '<b>wp_image_editor_imagick(bfi)::' . __FUNCTION__ . '()</b>' );
|
106 |
global $ewww_defer;
|
107 |
global $ewww_preempt_editor;
|
108 |
if ( ! empty( $ewww_preempt_editor ) ) {
|
179 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
180 |
*/
|
181 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
182 |
+
ewwwio_debug_message( '<b>wp_image_editor_imagick(respimg)::' . __FUNCTION__ . '()</b>' );
|
183 |
global $ewww_defer;
|
184 |
global $ewww_preempt_editor;
|
185 |
if ( ! empty( $ewww_preempt_editor ) ) {
|
252 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
253 |
*/
|
254 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
255 |
+
ewwwio_debug_message( '<b>wp_image_editor_imagick(s3uploads)::' . __FUNCTION__ . '()</b>' );
|
256 |
global $ewww_preempt_editor;
|
257 |
list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type );
|
258 |
if ( ! $filename ) {
|
350 |
* @see WP_Image_Editor_Imagick
|
351 |
*/
|
352 |
class EWWWIO_Imagick_Editor extends WP_Image_Editor_Imagick {
|
353 |
+
|
354 |
+
/**
|
355 |
+
* Resizes current image.
|
356 |
+
* Wraps _resize, since _resize returns a GD Resource.
|
357 |
+
*
|
358 |
+
* At minimum, either a height or width must be provided.
|
359 |
+
* If one of the two is set to null, the resize will
|
360 |
+
* maintain aspect ratio according to the provided dimension.
|
361 |
+
*
|
362 |
+
* @since 4.6.0
|
363 |
+
*
|
364 |
+
* @param int|null $max_w Image width.
|
365 |
+
* @param int|null $max_h Image height.
|
366 |
+
* @param bool $crop Optional. Scale by default, crop if true.
|
367 |
+
* @return true|WP_Error
|
368 |
+
*/
|
369 |
+
public function resize( $max_w, $max_h, $crop = false ) {
|
370 |
+
ewwwio_debug_message( '<b>wp_image_editor_gd::' . __FUNCTION__ . '()</b>' );
|
371 |
+
if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
|
372 |
+
return true;
|
373 |
+
}
|
374 |
+
|
375 |
+
$dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop );
|
376 |
+
if ( ! $dims ) {
|
377 |
+
return new WP_Error( 'error_getting_dimensions', __( 'Could not calculate resized image dimensions' ) );
|
378 |
+
}
|
379 |
+
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
|
380 |
+
|
381 |
+
$crop = $crop ? $dims : false;
|
382 |
+
|
383 |
+
$resized = $this->_resize( $dst_w, $dst_h, $crop );
|
384 |
+
|
385 |
+
if ( is_string( $resized ) ) {
|
386 |
+
$this->ewww_image = $resized;
|
387 |
+
return $resized;
|
388 |
+
} elseif ( is_wp_error( $resized ) ) {
|
389 |
+
return $resized;
|
390 |
+
}
|
391 |
+
return $this->update_size( $dst_w, $dst_h );
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Resizes current image.
|
396 |
+
*
|
397 |
+
* Uses gifsicle to preserve GIF animations.
|
398 |
+
*
|
399 |
+
* @since 4.6.0
|
400 |
+
*
|
401 |
+
* @param int|null $max_w Image width.
|
402 |
+
* @param int|null $max_h Image height.
|
403 |
+
* @param array $crop Optional. Scale by default, crop if true. Will contain all
|
404 |
+
* parameters necessary for crop method.
|
405 |
+
* @return bool|WP_Error
|
406 |
+
*/
|
407 |
+
protected function _resize( $max_w, $max_h, $crop = false ) {
|
408 |
+
ewwwio_debug_message( '<b>wp_image_editor_gd::' . __FUNCTION__ . '()</b>' );
|
409 |
+
if ( ( ! $max_w || $max_w >= $this->size['width'] ) && ( ! $max_h || $max_h >= $this->size['height'] ) ) {
|
410 |
+
return new WP_Error( 'image_resize_error', __( 'Image resize failed.' ) );
|
411 |
+
}
|
412 |
+
if ( defined( 'EWWWIO_EDITOR_AGR' ) && ! EWWWIO_EDITOR_AGR ) {
|
413 |
+
ewwwio_debug_message( 'AGR disabled' );
|
414 |
+
if ( $crop ) {
|
415 |
+
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $crop;
|
416 |
+
return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h );
|
417 |
+
}
|
418 |
+
return $this->thumbnail_image( $max_w, $max_h );
|
419 |
+
}
|
420 |
+
if ( defined( 'EWWWIO_EDITOR_BETTER_RESIZE' ) && ! EWWW_IO_EDITOR_BETTER_RESIZE ) {
|
421 |
+
ewwwio_debug_message( 'API resize disabled' );
|
422 |
+
if ( $crop ) {
|
423 |
+
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $crop;
|
424 |
+
return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h );
|
425 |
+
}
|
426 |
+
return $this->thumbnail_image( $max_w, $max_h );
|
427 |
+
}
|
428 |
+
$return_parent = false; // An indicator for whether we should short-circuit and use the parent thumbnail_image method.
|
429 |
+
if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_CLOUD' ) ) {
|
430 |
+
ewww_image_optimizer_cloud_init();
|
431 |
+
}
|
432 |
+
$ewww_status = get_transient( 'ewww_image_optimizer_cloud_status' );
|
433 |
+
if ( 'image/gif' === $this->mime_type && function_exists( 'ewww_image_optimizer_path_check' ) ) {
|
434 |
+
ewww_image_optimizer_path_check( false, false, true, false, false, false );
|
435 |
+
}
|
436 |
+
if ( 'image/gif' === $this->mime_type && ( ! defined( 'EWWW_IMAGE_OPTIMIZER_GIFSICLE' ) || ! EWWW_IMAGE_OPTIMIZER_GIFSICLE ) ) {
|
437 |
+
if ( false === strpos( $ewww_status, 'great' ) ) {
|
438 |
+
if ( ! ewww_image_optimizer_cloud_verify() ) {
|
439 |
+
ewwwio_debug_message( 'no gifsicle or API to resize an animated GIF' );
|
440 |
+
$return_parent = true;
|
441 |
+
}
|
442 |
+
}
|
443 |
+
}
|
444 |
+
if ( 'image/gif' !== $this->mime_type && false === strpos( $ewww_status, 'great' ) ) {
|
445 |
+
if ( ! ewww_image_optimizer_cloud_verify() ) {
|
446 |
+
ewwwio_debug_message( 'no API to resize the image' );
|
447 |
+
$return_parent = true;
|
448 |
+
}
|
449 |
+
}
|
450 |
+
if ( 'image/gif' !== $this->mime_type || ! ewww_image_optimizer_is_animated( $this->file ) ) {
|
451 |
+
ewwwio_debug_message( 'not an animated GIF' );
|
452 |
+
$return_parent = true;
|
453 |
+
}
|
454 |
+
// TODO: Possibly handle crop, rotate, and flip down the road.
|
455 |
+
if ( ! empty( $this->modified ) ) {
|
456 |
+
ewwwio_debug_message( 'GIF already altered, leave it alone' );
|
457 |
+
$return_parent = true;
|
458 |
+
}
|
459 |
+
if ( ! $this->file || 0 === strpos( $this->file, 's3' ) || 0 === strpos( $this->file, 'http' ) || 0 === strpos( $this->file, 'ftp' ) || ! is_file( $this->file ) ) {
|
460 |
+
ewwwio_debug_message( 'could not load original file, or remote path detected' );
|
461 |
+
$return_parent = true;
|
462 |
+
}
|
463 |
+
if ( $return_parent ) {
|
464 |
+
if ( $crop ) {
|
465 |
+
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $crop;
|
466 |
+
return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h );
|
467 |
+
}
|
468 |
+
return $this->thumbnail_image( $max_w, $max_h );
|
469 |
+
}
|
470 |
+
$resize_result = ewww_image_optimizer_better_resize( $this->file, $max_w, $max_h, $crop );
|
471 |
+
if ( is_wp_error( $resize_result ) ) {
|
472 |
+
return $resize_result;
|
473 |
+
}
|
474 |
+
|
475 |
+
$imagick = new Imagick();
|
476 |
+
$new_size = array();
|
477 |
+
try {
|
478 |
+
$imagick->clear();
|
479 |
+
$imagick->readImageBlob( $resize_result );
|
480 |
+
if ( function_exists( 'getimagesizefromstring' ) ) {
|
481 |
+
$gd_size_info = getimagesizefromstring( $resize_result );
|
482 |
+
}
|
483 |
+
if ( ! empty( $gd_size_info ) ) {
|
484 |
+
$new_size['width'] = $gd_size_info[0];
|
485 |
+
$new_size['height'] = $gd_size_info[1];
|
486 |
+
} else {
|
487 |
+
$new_size = $imagick->getImageGeometry();
|
488 |
+
}
|
489 |
+
ewwwio_debug_message( 'new size: ' . implode( 'x', $new_size ) );
|
490 |
+
} catch ( Exception $e ) {
|
491 |
+
return new WP_Error( 'image_resize_error', $e->getMessage(), $this->file );
|
492 |
+
}
|
493 |
+
$this->image = $imagick;
|
494 |
+
if ( empty( $new_size ) ) {
|
495 |
+
return new WP_Error( 'image_resize_error', __( 'Image resize failed.' ) );
|
496 |
+
}
|
497 |
+
$this->update_size( $new_size['width'], $new_size['height'] );
|
498 |
+
ewwwio_memory( __FUNCTION__ );
|
499 |
+
return $resize_result;
|
500 |
+
}
|
501 |
+
|
502 |
+
/**
|
503 |
+
* Resize multiple images from a single source.
|
504 |
+
*
|
505 |
+
* @since 4.6.0
|
506 |
+
*
|
507 |
+
* @param array $sizes {
|
508 |
+
* An array of image size arrays. Default sizes are 'small', 'medium', 'medium_large', 'large'.
|
509 |
+
*
|
510 |
+
* Either a height or width must be provided.
|
511 |
+
* If one of the two is set to null, the resize will
|
512 |
+
* maintain aspect ratio according to the provided dimension.
|
513 |
+
* Likewise, if crop is false, aspect ratio will also be preserved.
|
514 |
+
*
|
515 |
+
* @type array $size {
|
516 |
+
* Array of height, width values, and whether to crop.
|
517 |
+
*
|
518 |
+
* @type int $width Image width. Optional if `$height` is specified.
|
519 |
+
* @type int $height Image height. Optional if `$width` is specified.
|
520 |
+
* @type bool $crop Optional. Whether to crop the image. Default false.
|
521 |
+
* }
|
522 |
+
* }
|
523 |
+
* @return array An array of resized images' metadata by size.
|
524 |
+
*/
|
525 |
+
public function multi_resize( $sizes ) {
|
526 |
+
ewwwio_debug_message( '<b>wp_image_editor_imagick::' . __FUNCTION__ . '()</b>' );
|
527 |
+
$metadata = array();
|
528 |
+
$orig_size = $this->size;
|
529 |
+
$orig_image = $this->image->getImage();
|
530 |
+
foreach ( $sizes as $size => $size_data ) {
|
531 |
+
if ( ! $this->image ) {
|
532 |
+
$this->image = $orig_image->getImage();
|
533 |
+
}
|
534 |
+
if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) {
|
535 |
+
continue;
|
536 |
+
}
|
537 |
+
if ( ! isset( $size_data['width'] ) ) {
|
538 |
+
$size_data['width'] = null;
|
539 |
+
}
|
540 |
+
if ( ! isset( $size_data['height'] ) ) {
|
541 |
+
$size_data['height'] = null;
|
542 |
+
}
|
543 |
+
if ( ! isset( $size_data['crop'] ) ) {
|
544 |
+
$size_data['crop'] = false;
|
545 |
+
}
|
546 |
+
|
547 |
+
$resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
|
548 |
+
$duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) );
|
549 |
+
|
550 |
+
if ( ! is_wp_error( $resize_result ) && ! $duplicate ) {
|
551 |
+
if ( is_string( $resize_result ) ) {
|
552 |
+
$resized = $this->_save_ewwwio_file( $resize_result );
|
553 |
+
unset( $resize_result );
|
554 |
+
// Note sure this bit is necessary, but just to be safe.
|
555 |
+
$this->image->clear();
|
556 |
+
$this->image->destroy();
|
557 |
+
$this->image = null;
|
558 |
+
} else {
|
559 |
+
$resized = $this->_save( $this->image );
|
560 |
+
$this->image->clear();
|
561 |
+
$this->image->destroy();
|
562 |
+
$this->image = null;
|
563 |
+
}
|
564 |
+
if ( ! is_wp_error( $resized ) && $resized ) {
|
565 |
+
unset( $resized['path'] );
|
566 |
+
$metadata[ $size ] = $resized;
|
567 |
+
}
|
568 |
+
}
|
569 |
+
$this->size = $orig_size;
|
570 |
+
}
|
571 |
+
$this->image = $orig_image;
|
572 |
+
return $metadata;
|
573 |
+
}
|
574 |
+
|
575 |
+
/**
|
576 |
+
* Crops Image.
|
577 |
+
*
|
578 |
+
* Currently does nothing more than call the parent and let us know the image is modified.
|
579 |
+
*
|
580 |
+
* @since 4.6.0
|
581 |
+
*
|
582 |
+
* @param int $src_x The start x position to crop from.
|
583 |
+
* @param int $src_y The start y position to crop from.
|
584 |
+
* @param int $src_w The width to crop.
|
585 |
+
* @param int $src_h The height to crop.
|
586 |
+
* @param int $dst_w Optional. The destination width.
|
587 |
+
* @param int $dst_h Optional. The destination height.
|
588 |
+
* @param bool $src_abs Optional. If the source crop points are absolute.
|
589 |
+
* @return bool|WP_Error
|
590 |
+
*/
|
591 |
+
public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) {
|
592 |
+
$this->modified = 'crop';
|
593 |
+
return parent::crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs );
|
594 |
+
}
|
595 |
+
|
596 |
+
/**
|
597 |
+
* Rotates current image counter-clockwise by $angle.
|
598 |
+
*
|
599 |
+
* Currently does nothing more than call the parent and let us know the image is modified.
|
600 |
+
*
|
601 |
+
* @since 4.6.0
|
602 |
+
*
|
603 |
+
* @param float $angle The number of degrees for rotation.
|
604 |
+
* @return true|WP_Error
|
605 |
+
*/
|
606 |
+
public function rotate( $angle ) {
|
607 |
+
$this->modified = 'rotate';
|
608 |
+
return parent::rotate( $angle );
|
609 |
+
}
|
610 |
+
|
611 |
+
/**
|
612 |
+
* Flips current image.
|
613 |
+
*
|
614 |
+
* Currently does nothing more than call the parent and let us know the image is modified.
|
615 |
+
*
|
616 |
+
* @since 4.6.0
|
617 |
+
*
|
618 |
+
* @param bool $horz Flip along Horizontal Axis.
|
619 |
+
* @param bool $vert Flip along Vertical Axis.
|
620 |
+
* @return true|WP_Error
|
621 |
+
*/
|
622 |
+
public function flip( $horz, $vert ) {
|
623 |
+
$this->modified = 'flip';
|
624 |
+
return parent::flip( $horz, $vert );
|
625 |
+
}
|
626 |
+
|
627 |
+
/**
|
628 |
+
* Saves a file from the EWWW IO API-enabled image editor.
|
629 |
+
*
|
630 |
+
* @since 4.6.0
|
631 |
+
*
|
632 |
+
* @param string $image A string containing the image contents.
|
633 |
+
* @param string $filename Optional. The name of the file to be saved to.
|
634 |
+
* @param string $mime_type Optional. The mimetype of the file.
|
635 |
+
* @return WP_Error|array The full path, base filename, and mimetype.
|
636 |
+
*/
|
637 |
+
protected function _save_ewwwio_file( $image, $filename = null, $mime_type = null ) {
|
638 |
+
ewwwio_debug_message( '<b>wp_image_editor_imagick::' . __FUNCTION__ . '()</b>' );
|
639 |
+
list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type );
|
640 |
+
if ( ! $filename ) {
|
641 |
+
$filename = $this->generate_filename( null, null, $extension );
|
642 |
+
}
|
643 |
+
if ( wp_is_stream( $filename ) ) {
|
644 |
+
$imagick = new Imagick();
|
645 |
+
try {
|
646 |
+
$imagick->readImageBlob( $image );
|
647 |
+
} catch ( Exception $e ) {
|
648 |
+
return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
|
649 |
+
}
|
650 |
+
unset( $this->ewww_image );
|
651 |
+
return parent::_save( $imagick, $filename, $mime_type );
|
652 |
+
}
|
653 |
+
if ( ! is_string( $image ) ) {
|
654 |
+
unset( $this->ewww_image );
|
655 |
+
return parent::_save( $image, $filename, $mime_type );
|
656 |
+
}
|
657 |
+
global $ewww_preempt_editor;
|
658 |
+
if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) && empty( $ewww_preempt_editor ) ) {
|
659 |
+
ewwwio_debug_message( "detected existing file: $filename" );
|
660 |
+
$current_size = getimagesize( $filename );
|
661 |
+
if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
|
662 |
+
ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
|
663 |
+
return array(
|
664 |
+
'path' => $filename,
|
665 |
+
'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
|
666 |
+
'width' => $this->size['width'],
|
667 |
+
'height' => $this->size['height'],
|
668 |
+
'mime-type' => $mime_type,
|
669 |
+
);
|
670 |
+
}
|
671 |
+
}
|
672 |
+
// Write out the image (substitute for $this->make_image()).
|
673 |
+
wp_mkdir_p( dirname( $filename ) );
|
674 |
+
$result = file_put_contents( $filename, $image );
|
675 |
+
if ( $result ) {
|
676 |
+
ewwwio_debug_message( "image editor (imagick-api-enhanced) saved: $filename" );
|
677 |
+
if ( is_writable( $filename ) ) {
|
678 |
+
$stat = stat( dirname( $filename ) );
|
679 |
+
$perms = $stat['mode'] & 0000666; // Same permissions as parent folder with executable bits stripped.
|
680 |
+
chmod( $filename, $perms );
|
681 |
+
}
|
682 |
+
ewwwio_memory( __FUNCTION__ );
|
683 |
+
return array(
|
684 |
+
'path' => $filename,
|
685 |
+
'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
|
686 |
+
'width' => $this->size['width'],
|
687 |
+
'height' => $this->size['height'],
|
688 |
+
'mime-type' => $mime_type,
|
689 |
+
);
|
690 |
+
}
|
691 |
+
ewwwio_memory( __FUNCTION__ );
|
692 |
+
return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
|
693 |
+
}
|
694 |
+
|
695 |
/**
|
696 |
* Saves a file from the image editor.
|
697 |
*
|
698 |
+
* @since 1.7.0
|
699 |
+
*
|
700 |
* @param resource $image An Imagick image object.
|
701 |
* @param string $filename Optional. The name of the file to be saved to.
|
702 |
* @param string $mime_type Optional. The mimetype of the file.
|
703 |
* @return WP_Error| array The full path, base filename, width, height, and mimetype.
|
704 |
*/
|
705 |
protected function _save( $image, $filename = null, $mime_type = null ) {
|
706 |
+
ewwwio_debug_message( '<b>wp_image_editor_imagick::' . __FUNCTION__ . '()</b>' );
|
707 |
global $ewww_defer;
|
708 |
global $ewww_preempt_editor;
|
709 |
+
if ( ! empty( $this->ewww_image ) && empty( $this->modified ) ) {
|
710 |
+
return $this->_save_ewwwio_file( $this->ewww_image, $filename, $mime_type );
|
711 |
+
}
|
712 |
if ( ! empty( $ewww_preempt_editor ) ) {
|
713 |
return parent::_save( $image, $filename, $mime_type );
|
714 |
}
|
classes/class-exactdn.php
CHANGED
@@ -150,6 +150,9 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
150 |
add_filter( 'exactdn_admin_allow_image_downsize', array( $this, 'allow_admin_image_downsize' ), 10, 2 );
|
151 |
// Overrides for "pass through" images.
|
152 |
add_filter( 'exactdn_pre_args', array( $this, 'exactdn_remove_args' ), 10, 3 );
|
|
|
|
|
|
|
153 |
|
154 |
// Responsive image srcset substitution.
|
155 |
add_filter( 'wp_calculate_image_srcset', array( $this, 'filter_srcset_array' ), 1001, 5 );
|
@@ -312,6 +315,7 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
312 |
if ( ! empty( $last_checkin ) && $last_checkin > time() ) {
|
313 |
ewwwio_debug_message( 'not time yet: ' . $this->human_time_diff( $this->get_exactdn_option( 'checkin' ) ) );
|
314 |
if ( $this->get_exactdn_option( 'suspended' ) ) {
|
|
|
315 |
return false;
|
316 |
}
|
317 |
return true;
|
@@ -380,7 +384,7 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
380 |
} elseif ( ! empty( $result['body'] ) ) {
|
381 |
$response = json_decode( $result['body'], true );
|
382 |
$error_message = $response['error'];
|
383 |
-
ewwwio_debug_message( "exactdn
|
384 |
$this->set_exactdn_option( 'suspended', 1 );
|
385 |
return false;
|
386 |
}
|
@@ -613,6 +617,13 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
613 |
|
614 |
$content = $this->filter_the_content( $content );
|
615 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
616 |
$this->filtering_the_page = false;
|
617 |
ewwwio_debug_message( "parsing page took $this->elapsed_time seconds" );
|
618 |
return $content;
|
@@ -1029,8 +1040,9 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
1029 |
$content = preg_replace( '#(<use.+?href=["\'])(https?:)?//(?:www\.)?' . $escaped_upload_domain . '([^"\'?>]+?)/wp-content/#is', '$1$2//' . $this->upload_domain . '$3/?wpcontent-bypass?/', $content );
|
1030 |
}
|
1031 |
// Pre-empt rewriting of wp-includes and wp-content if the extension is not allowed by using a temporary placeholder.
|
1032 |
-
$content = preg_replace( '#(https?:)?//(?:www\.)?' . $escaped_upload_domain . '([^"\'?>]+?)?/wp-content/([^"\'?>]+?)\.(php|ashx|m4v|mov|wvm|qt|webm|ogv|mp4|m4p|mpg|mpeg|mpv)#i', '$1//' . $this->upload_domain . '$2/?wpcontent-bypass?/$3.$4', $content );
|
1033 |
$content = str_replace( 'wp-content/themes/jupiter"', '?wpcontent-bypass?/themes/jupiter"', $content );
|
|
|
1034 |
$content = preg_replace( '#(https?:)?//(?:www\.)?' . $escaped_upload_domain . '/([^"\'?>]+?)?(nextgen-image|wp-includes|wp-content)/#i', '$1//' . $this->exactdn_domain . '/$2$3/', $content );
|
1035 |
$content = str_replace( '?wpcontent-bypass?', 'wp-content', $content );
|
1036 |
}
|
@@ -1042,7 +1054,7 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
1042 |
ewwwio_debug_message( "parsing the_content took $elapsed_time seconds" );
|
1043 |
$this->elapsed_time += microtime( true ) - $started;
|
1044 |
ewwwio_debug_message( "parsing the page took $this->elapsed_time seconds so far" );
|
1045 |
-
if ( $this->elapsed_time > .5 ) {
|
1046 |
ewww_image_optimizer_set_option( 'exactdn_prevent_db_queries', true );
|
1047 |
}
|
1048 |
return $content;
|
@@ -1170,6 +1182,10 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
1170 |
|
1171 |
// Get the image URL and proceed with ExactDN replacement if successful.
|
1172 |
$image_url = wp_get_attachment_url( $attachment_id );
|
|
|
|
|
|
|
|
|
1173 |
ewwwio_debug_message( $image_url );
|
1174 |
ewwwio_debug_message( $attachment_id );
|
1175 |
if ( is_string( $size ) || is_int( $size ) ) {
|
@@ -1647,7 +1663,7 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
1647 |
}
|
1648 |
foreach ( $currentwidths as $currentwidth ) {
|
1649 |
// If a new width would be within 50 pixels of an existing one or larger than the full size image, skip.
|
1650 |
-
if ( abs( $currentwidth - $newwidth ) < 50 ) {
|
1651 |
continue 2; // Back to the foreach ( $multipliers as $multiplier ).
|
1652 |
}
|
1653 |
} // foreach ( $currentwidths as $currentwidth ){
|
@@ -2079,6 +2095,27 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
2079 |
return $args;
|
2080 |
}
|
2081 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2082 |
/**
|
2083 |
* Converts a local script/css url to use ExactDN.
|
2084 |
*
|
@@ -2092,20 +2129,27 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
2092 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
2093 |
$parsed_url = $this->parse_url( $url );
|
2094 |
|
2095 |
-
if ( $this->user_exclusions ) {
|
2096 |
-
foreach ( $this->user_exclusions as $exclusion ) {
|
2097 |
-
if ( false !== strpos( $url, $exclusion ) ) {
|
2098 |
-
ewwwio_debug_message( "user excluded $url via $exclusion" );
|
2099 |
-
return $url;
|
2100 |
-
}
|
2101 |
-
}
|
2102 |
-
}
|
2103 |
if ( false !== strpos( $url, 'wp-admin/' ) ) {
|
2104 |
return $url;
|
2105 |
}
|
2106 |
if ( false !== strpos( $url, 'xmlrpc.php' ) ) {
|
2107 |
return $url;
|
2108 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2109 |
// Unable to parse.
|
2110 |
if ( ! $parsed_url || ! is_array( $parsed_url ) || empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) ) {
|
2111 |
ewwwio_debug_message( 'src url no good' );
|
@@ -2179,12 +2223,12 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
2179 |
}
|
2180 |
|
2181 |
/**
|
2182 |
-
* Allow specific
|
2183 |
*
|
2184 |
-
* @param bool false Should the
|
2185 |
-
* @param string $image_url
|
2186 |
* @param array|string $args Array of ExactDN arguments.
|
2187 |
-
* @param string|null $scheme
|
2188 |
*/
|
2189 |
if ( true === apply_filters( 'exactdn_skip_for_url', false, $image_url, $args, $scheme ) ) {
|
2190 |
return $image_url;
|
@@ -2400,3 +2444,41 @@ class ExactDN extends EWWWIO_Page_Parser {
|
|
2400 |
|
2401 |
global $exactdn;
|
2402 |
$exactdn = new ExactDN();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
add_filter( 'exactdn_admin_allow_image_downsize', array( $this, 'allow_admin_image_downsize' ), 10, 2 );
|
151 |
// Overrides for "pass through" images.
|
152 |
add_filter( 'exactdn_pre_args', array( $this, 'exactdn_remove_args' ), 10, 3 );
|
153 |
+
// Overrides for user exclusions.
|
154 |
+
add_filter( 'exactdn_skip_image', array( $this, 'exactdn_skip_user_exclusions' ), 9, 2 );
|
155 |
+
add_filter( 'exactdn_skip_for_url', array( $this, 'exactdn_skip_user_exclusions' ), 9, 2 );
|
156 |
|
157 |
// Responsive image srcset substitution.
|
158 |
add_filter( 'wp_calculate_image_srcset', array( $this, 'filter_srcset_array' ), 1001, 5 );
|
315 |
if ( ! empty( $last_checkin ) && $last_checkin > time() ) {
|
316 |
ewwwio_debug_message( 'not time yet: ' . $this->human_time_diff( $this->get_exactdn_option( 'checkin' ) ) );
|
317 |
if ( $this->get_exactdn_option( 'suspended' ) ) {
|
318 |
+
ewwwio_debug_message( 'suspended marker, returning false until next checkin' );
|
319 |
return false;
|
320 |
}
|
321 |
return true;
|
384 |
} elseif ( ! empty( $result['body'] ) ) {
|
385 |
$response = json_decode( $result['body'], true );
|
386 |
$error_message = $response['error'];
|
387 |
+
ewwwio_debug_message( "exactdn verification request failed: $error_message" );
|
388 |
$this->set_exactdn_option( 'suspended', 1 );
|
389 |
return false;
|
390 |
}
|
617 |
|
618 |
$content = $this->filter_the_content( $content );
|
619 |
|
620 |
+
/**
|
621 |
+
* Allow parsing the full page content after ExactDN is finished with it.
|
622 |
+
*
|
623 |
+
* @param string $content The fully-parsed HTML code of the page.
|
624 |
+
*/
|
625 |
+
$content = apply_filters( 'exactdn_the_page', $content );
|
626 |
+
|
627 |
$this->filtering_the_page = false;
|
628 |
ewwwio_debug_message( "parsing page took $this->elapsed_time seconds" );
|
629 |
return $content;
|
1040 |
$content = preg_replace( '#(<use.+?href=["\'])(https?:)?//(?:www\.)?' . $escaped_upload_domain . '([^"\'?>]+?)/wp-content/#is', '$1$2//' . $this->upload_domain . '$3/?wpcontent-bypass?/', $content );
|
1041 |
}
|
1042 |
// Pre-empt rewriting of wp-includes and wp-content if the extension is not allowed by using a temporary placeholder.
|
1043 |
+
$content = preg_replace( '#(https?:)?//(?:www\.)?' . $escaped_upload_domain . '([^"\'?>]+?)?/wp-content/([^"\'?>]+?)\.(htm|html|php|ashx|m4v|mov|wvm|qt|webm|ogv|mp4|m4p|mpg|mpeg|mpv)#i', '$1//' . $this->upload_domain . '$2/?wpcontent-bypass?/$3.$4', $content );
|
1044 |
$content = str_replace( 'wp-content/themes/jupiter"', '?wpcontent-bypass?/themes/jupiter"', $content );
|
1045 |
+
$content = str_replace( 'wp-content/plugins/anti-captcha/', '?wpcontent-bypass?/plugins/anti-captcha', $content );
|
1046 |
$content = preg_replace( '#(https?:)?//(?:www\.)?' . $escaped_upload_domain . '/([^"\'?>]+?)?(nextgen-image|wp-includes|wp-content)/#i', '$1//' . $this->exactdn_domain . '/$2$3/', $content );
|
1047 |
$content = str_replace( '?wpcontent-bypass?', 'wp-content', $content );
|
1048 |
}
|
1054 |
ewwwio_debug_message( "parsing the_content took $elapsed_time seconds" );
|
1055 |
$this->elapsed_time += microtime( true ) - $started;
|
1056 |
ewwwio_debug_message( "parsing the page took $this->elapsed_time seconds so far" );
|
1057 |
+
if ( ! ewww_image_optimizer_get_option( 'exactdn_prevent_db_queries' ) && $this->elapsed_time > .5 ) {
|
1058 |
ewww_image_optimizer_set_option( 'exactdn_prevent_db_queries', true );
|
1059 |
}
|
1060 |
return $content;
|
1182 |
|
1183 |
// Get the image URL and proceed with ExactDN replacement if successful.
|
1184 |
$image_url = wp_get_attachment_url( $attachment_id );
|
1185 |
+
/** This filter is already documented in class-exactdn.php */
|
1186 |
+
if ( apply_filters( 'exactdn_skip_image', false, $image_url, null ) ) {
|
1187 |
+
return $image;
|
1188 |
+
}
|
1189 |
ewwwio_debug_message( $image_url );
|
1190 |
ewwwio_debug_message( $attachment_id );
|
1191 |
if ( is_string( $size ) || is_int( $size ) ) {
|
1663 |
}
|
1664 |
foreach ( $currentwidths as $currentwidth ) {
|
1665 |
// If a new width would be within 50 pixels of an existing one or larger than the full size image, skip.
|
1666 |
+
if ( 1 !== $multiplier && abs( $currentwidth - $newwidth ) < 50 ) {
|
1667 |
continue 2; // Back to the foreach ( $multipliers as $multiplier ).
|
1668 |
}
|
1669 |
} // foreach ( $currentwidths as $currentwidth ){
|
2095 |
return $args;
|
2096 |
}
|
2097 |
|
2098 |
+
/**
|
2099 |
+
* Exclude images and other resources from being processed based on user specified list.
|
2100 |
+
*
|
2101 |
+
* @since 4.6.0
|
2102 |
+
*
|
2103 |
+
* @param boolean $skip Whether ExactDN should skip processing.
|
2104 |
+
* @param string $url Resource URL.
|
2105 |
+
* @return boolean True to skip the resource, unchanged otherwise.
|
2106 |
+
*/
|
2107 |
+
function exactdn_skip_user_exclusions( $skip, $url ) {
|
2108 |
+
if ( $this->user_exclusions ) {
|
2109 |
+
foreach ( $this->user_exclusions as $exclusion ) {
|
2110 |
+
if ( false !== strpos( $url, $exclusion ) ) {
|
2111 |
+
ewwwio_debug_message( "user excluded $url via $exclusion" );
|
2112 |
+
return true;
|
2113 |
+
}
|
2114 |
+
}
|
2115 |
+
}
|
2116 |
+
return $skip;
|
2117 |
+
}
|
2118 |
+
|
2119 |
/**
|
2120 |
* Converts a local script/css url to use ExactDN.
|
2121 |
*
|
2129 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
2130 |
$parsed_url = $this->parse_url( $url );
|
2131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2132 |
if ( false !== strpos( $url, 'wp-admin/' ) ) {
|
2133 |
return $url;
|
2134 |
}
|
2135 |
if ( false !== strpos( $url, 'xmlrpc.php' ) ) {
|
2136 |
return $url;
|
2137 |
}
|
2138 |
+
if ( strpos( $url, 'wp-content/plugins/anti-captcha/' ) ) {
|
2139 |
+
return $url;
|
2140 |
+
}
|
2141 |
+
/**
|
2142 |
+
* Allow specific URLs to avoid going through ExactDN.
|
2143 |
+
*
|
2144 |
+
* @param bool false Should the URL be returned as is, without going through ExactDN. Default to false.
|
2145 |
+
* @param string $url Resource URL.
|
2146 |
+
* @param array|string $args Array of ExactDN arguments.
|
2147 |
+
* @param string|null $scheme URL scheme. Default to null.
|
2148 |
+
*/
|
2149 |
+
if ( true === apply_filters( 'exactdn_skip_for_url', false, $url, array(), null ) ) {
|
2150 |
+
return $url;
|
2151 |
+
}
|
2152 |
+
|
2153 |
// Unable to parse.
|
2154 |
if ( ! $parsed_url || ! is_array( $parsed_url ) || empty( $parsed_url['host'] ) || empty( $parsed_url['path'] ) ) {
|
2155 |
ewwwio_debug_message( 'src url no good' );
|
2223 |
}
|
2224 |
|
2225 |
/**
|
2226 |
+
* Allow specific URLs to avoid going through ExactDN.
|
2227 |
*
|
2228 |
+
* @param bool false Should the URL be returned as is, without going through ExactDN. Default to false.
|
2229 |
+
* @param string $image_url Resource URL.
|
2230 |
* @param array|string $args Array of ExactDN arguments.
|
2231 |
+
* @param string|null $scheme URL scheme. Default to null.
|
2232 |
*/
|
2233 |
if ( true === apply_filters( 'exactdn_skip_for_url', false, $image_url, $args, $scheme ) ) {
|
2234 |
return $image_url;
|
2444 |
|
2445 |
global $exactdn;
|
2446 |
$exactdn = new ExactDN();
|
2447 |
+
|
2448 |
+
if ( ! function_exists( 'ampforwp_aq_resize' ) ) {
|
2449 |
+
|
2450 |
+
/**
|
2451 |
+
* This is just a tiny wrapper function for the class above so that there is no
|
2452 |
+
* need to change any code in your own WP themes. Usage is still the same :)
|
2453 |
+
*
|
2454 |
+
* @param string $url stuff.
|
2455 |
+
* @param int $width other stuff.
|
2456 |
+
* @param int $height tall stuff.
|
2457 |
+
* @param bool $crop flippy stuff.
|
2458 |
+
* @param bool $single lonely stuff.
|
2459 |
+
* @param bool $upscale fancy stuff.
|
2460 |
+
*/
|
2461 |
+
function ampforwp_aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
|
2462 |
+
/* WPML Fix */
|
2463 |
+
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
|
2464 |
+
global $sitepress;
|
2465 |
+
$url = $sitepress->convert_url( $url, $sitepress->get_default_language() );
|
2466 |
+
}
|
2467 |
+
/* EWWW Image Optimizer (ExactDN) Compatible*/
|
2468 |
+
global $exactdn;
|
2469 |
+
if ( class_exists( 'ExactDN' ) && $exactdn->get_exactdn_domain() ) {
|
2470 |
+
$args = array(
|
2471 |
+
'resize' => "$width,$height",
|
2472 |
+
);
|
2473 |
+
$image = array(
|
2474 |
+
0 => $exactdn->generate_url( $url, $args ),
|
2475 |
+
1 => $width,
|
2476 |
+
2 => $height,
|
2477 |
+
);
|
2478 |
+
return $image;
|
2479 |
+
} else {
|
2480 |
+
$aq_resize = Aq_Resize::getInstance();
|
2481 |
+
return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
|
2482 |
+
}
|
2483 |
+
}
|
2484 |
+
}
|
common.php
CHANGED
@@ -13,8 +13,7 @@
|
|
13 |
// TODO: might be able to use the Custom Bulk Actions in 4.7 to support the bulk optimize drop-down menu.
|
14 |
// TODO: need to make the scheduler so it can resume without having to re-run the queue population, and then we can probably also flush the queue when scheduled opt starts, but later it would be nice to implement the bulk_loop as the aux_loop so that it could handle media properly.
|
15 |
// TODO: Add a custom async function for parallel mode to store image as pending and use the row ID instead of relative path.
|
16 |
-
// TODO: write some tests for
|
17 |
-
// TODO: write some conversion tests.
|
18 |
// TODO: check this patch, to see if the use of 'full' causes any issues: https://core.trac.wordpress.org/ticket/37840 .
|
19 |
// TODO: use this: https://codex.wordpress.org/AJAX_in_Plugins#The_post-load_JavaScript_Event .
|
20 |
// TODO: can some of the bulk "fallbacks" be implemented for async processing?
|
@@ -24,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
24 |
exit;
|
25 |
}
|
26 |
|
27 |
-
define( 'EWWW_IMAGE_OPTIMIZER_VERSION', '
|
28 |
|
29 |
// Initialize a couple globals.
|
30 |
$ewww_debug = '';
|
@@ -39,6 +38,9 @@ global $wpdb;
|
|
39 |
if ( ! isset( $wpdb->ewwwio_images ) ) {
|
40 |
$wpdb->ewwwio_images = $wpdb->prefix . 'ewwwio_images';
|
41 |
}
|
|
|
|
|
|
|
42 |
|
43 |
if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_RELATIVE' ) ) {
|
44 |
define( 'EWWW_IMAGE_OPTIMIZER_RELATIVE', true );
|
@@ -514,7 +516,11 @@ function ewww_image_optimizer_upgrade() {
|
|
514 |
}
|
515 |
if ( get_option( 'ewww_image_optimizer_version' ) > 0 && get_option( 'ewww_image_optimizer_version' ) < 440 && ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) || ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) < 30 ) ) {
|
516 |
add_site_option( 'exactdn_lossy', true );
|
517 |
-
|
|
|
|
|
|
|
|
|
518 |
}
|
519 |
ewww_image_optimizer_remove_obsolete_settings();
|
520 |
update_option( 'ewww_image_optimizer_version', EWWW_IMAGE_OPTIMIZER_VERSION );
|
@@ -573,6 +579,18 @@ function ewww_image_optimizer_retest_background_optimization() {
|
|
573 |
function ewww_image_optimizer_admin_init() {
|
574 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
575 |
ewwwio_memory( __FUNCTION__ );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
576 |
ewww_image_optimizer_cloud_init();
|
577 |
ewww_image_optimizer_upgrade();
|
578 |
if ( ! function_exists( 'is_plugin_active_for_network' ) && is_multisite() ) {
|
@@ -721,18 +739,6 @@ function ewww_image_optimizer_admin_init() {
|
|
721 |
register_setting( 'ewww_image_optimizer_options', 'ewww_image_optimizer_webp_for_cdn', 'boolval' );
|
722 |
ewww_image_optimizer_exec_init();
|
723 |
ewww_image_optimizer_cron_setup( 'ewww_image_optimizer_auto' );
|
724 |
-
/**
|
725 |
-
* Require the file that does the bulk processing.
|
726 |
-
*/
|
727 |
-
require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'bulk.php' );
|
728 |
-
/**
|
729 |
-
* Require the files that contain functions for the images table and bulk processing images outside the library.
|
730 |
-
*/
|
731 |
-
require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'aux-optimize.php' );
|
732 |
-
/**
|
733 |
-
* Require the files that migrate WebP images from extension replacement to extension appending.
|
734 |
-
*/
|
735 |
-
require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'mwebp.php' );
|
736 |
// Queue the function that contains custom styling for our progressbars.
|
737 |
add_action( 'admin_enqueue_scripts', 'ewww_image_optimizer_progressbar_style' );
|
738 |
// Alert user if multiple re-optimizations detected.
|
@@ -1113,6 +1119,7 @@ function ewww_image_optimizer_install_table() {
|
|
1113 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
1114 |
global $wpdb;
|
1115 |
$wpdb->ewwwio_images = $wpdb->prefix . 'ewwwio_images';
|
|
|
1116 |
|
1117 |
// Get the current wpdb charset and collation.
|
1118 |
$db_collation = $wpdb->get_charset_collate();
|
@@ -1216,12 +1223,30 @@ function ewww_image_optimizer_install_table() {
|
|
1216 |
// Include the upgrade library to install/upgrade a table.
|
1217 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
1218 |
$updates = dbDelta( $sql );
|
1219 |
-
ewwwio_debug_message( 'db upgrade results: ' . implode( '<br>', $updates ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1220 |
|
1221 |
// Make sure some of our options are not autoloaded (since they can be huge).
|
1222 |
-
$bulk_attachments = get_option( 'ewww_image_optimizer_bulk_attachments', '' )
|
1223 |
delete_option( 'ewww_image_optimizer_bulk_attachments' );
|
1224 |
-
add_option( 'ewww_image_optimizer_bulk_attachments', $bulk_attachments, '', 'no' )
|
1225 |
$bulk_attachments = get_option( 'ewww_image_optimizer_flag_attachments', '' );
|
1226 |
delete_option( 'ewww_image_optimizer_flag_attachments' );
|
1227 |
add_option( 'ewww_image_optimizer_flag_attachments', $bulk_attachments, '', 'no' );
|
@@ -1893,12 +1918,18 @@ function ewww_image_optimizer_network_deactivate( $network_wide ) {
|
|
1893 |
}
|
1894 |
|
1895 |
/**
|
1896 |
-
*
|
|
|
|
|
1897 |
*/
|
1898 |
function ewww_image_optimizer_uninstall() {
|
1899 |
if ( ewwwio_extract_from_markers( ewww_image_optimizer_htaccess_path(), 'EWWWIO' ) ) {
|
1900 |
insert_with_markers( ewww_image_optimizer_htaccess_path(), 'EWWWIO', '' );
|
1901 |
}
|
|
|
|
|
|
|
|
|
1902 |
}
|
1903 |
|
1904 |
/**
|
@@ -2200,7 +2231,7 @@ function ewww_image_optimizer_gd_support() {
|
|
2200 |
*/
|
2201 |
function ewww_image_optimizer_imagick_support() {
|
2202 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
2203 |
-
if ( extension_loaded( 'imagick' ) ) {
|
2204 |
$imagick = new Imagick();
|
2205 |
$formats = $imagick->queryFormats();
|
2206 |
ewwwio_debug_message( implode( ',', $formats ) );
|
@@ -2219,7 +2250,7 @@ function ewww_image_optimizer_imagick_support() {
|
|
2219 |
*/
|
2220 |
function ewww_image_optimizer_gmagick_support() {
|
2221 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
2222 |
-
if ( extension_loaded( 'gmagick' ) ) {
|
2223 |
$gmagick = new Gmagick();
|
2224 |
$formats = $gmagick->queryFormats();
|
2225 |
ewwwio_debug_message( implode( ',', $formats ) );
|
@@ -3748,7 +3779,7 @@ function ewww_image_optimizer_mass_insert( $table, $images, $format ) {
|
|
3748 |
*
|
3749 |
* @param string $file The filename of the image.
|
3750 |
* @param int $orig_size The current filesize of the image.
|
3751 |
-
* @return
|
3752 |
*/
|
3753 |
function ewww_image_optimizer_check_table( $file, $orig_size ) {
|
3754 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
@@ -3771,7 +3802,7 @@ function ewww_image_optimizer_check_table( $file, $orig_size ) {
|
|
3771 |
if ( is_array( $image ) && $image['image_size'] == $orig_size ) {
|
3772 |
$prev_string = ' - ' . __( 'Previously Optimized', 'ewww-image-optimizer' );
|
3773 |
if ( preg_match( '/' . __( 'License exceeded', 'ewww-image-optimizer' ) . '/', $image['results'] ) ) {
|
3774 |
-
return;
|
3775 |
}
|
3776 |
$already_optimized = preg_replace( "/$prev_string/", '', $image['results'] );
|
3777 |
$already_optimized = $already_optimized . $prev_string;
|
@@ -3792,6 +3823,7 @@ function ewww_image_optimizer_check_table( $file, $orig_size ) {
|
|
3792 |
}
|
3793 |
return $already_optimized;
|
3794 |
}
|
|
|
3795 |
}
|
3796 |
|
3797 |
/**
|
@@ -4463,6 +4495,11 @@ function ewwwio_crop_dimensions( $current_width, $current_height, $max_width = 0
|
|
4463 |
*/
|
4464 |
function ewww_image_optimizer_better_resize( $file, $max_w, $max_h, $crop = false ) {
|
4465 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
|
|
|
|
|
|
|
|
|
|
4466 |
$type = ewww_image_optimizer_mimetype( $file, 'i' );
|
4467 |
if ( false === strpos( $type, 'image' ) ) {
|
4468 |
ewwwio_debug_message( 'not an image, no resizing possible' );
|
@@ -7736,13 +7773,12 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
|
|
7736 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_debug'>" . esc_html__( 'Debugging', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . '</th>' .
|
7737 |
"<td><input type='checkbox' id='ewww_image_optimizer_debug' name='ewww_image_optimizer_debug' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Use this to provide information for support purposes, or if you feel comfortable digging around in the code to fix a problem you are experiencing.', 'ewww-image-optimizer' ) . "</td></tr>\n";
|
7738 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_metadata_remove'>" . esc_html__( 'Remove Metadata', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
|
7739 |
-
"<td><input type='checkbox' id='ewww_image_optimizer_metadata_remove' name='ewww_image_optimizer_metadata_remove' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'This will remove ALL metadata: EXIF, comments, color profiles, and anything else that is not pixel data.', 'ewww-image-optimizer' ) .
|
|
|
7740 |
ewwwio_debug_message( 'remove metadata: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) == true ? 'on' : 'off' ) );
|
7741 |
-
|
7742 |
-
|
7743 |
-
|
7744 |
-
( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ? "<p class='$network_class nocloud'><strong>* <a href='https://ewww.io/plans/' target='_blank'>" . esc_html__( 'Get an API key to achieve up to 80% compression and see the quality for yourself.', 'ewww-image-optimizer' ) . "</a></strong></p>\n" : '' );
|
7745 |
-
$output[] = "</td></tr>\n";
|
7746 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_jpg_level'>" . esc_html__( 'JPG Optimization Level', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
|
7747 |
"<td><span><select id='ewww_image_optimizer_jpg_level' name='ewww_image_optimizer_jpg_level'>\n" .
|
7748 |
"<option value='0'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ), 0, false ) . '>' . esc_html__( 'No Compression', 'ewww-image-optimizer' ) . "</option>\n";
|
@@ -7762,14 +7798,14 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
|
|
7762 |
}
|
7763 |
$output[] = "<option class='$network_class' $disable_level value='20' " . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ), 20, false ) .
|
7764 |
selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ), 30, false ) . '>' . esc_html__( 'Pixel Perfect Plus', 'ewww-image-optimizer' ) . " *</option>\n" .
|
7765 |
-
"<option value='40'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ), 40, false ) . '>' . esc_html__( 'Premium', 'ewww-image-optimizer' ) . "</option>\n" .
|
7766 |
"<option $disable_level value='50'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ), 50, false ) . '>' . esc_html__( 'Premium Plus', 'ewww-image-optimizer' ) . " *</option>\n" .
|
7767 |
"</select></td></tr>\n";
|
7768 |
ewwwio_debug_message( 'png level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) );
|
7769 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_gif_level'>" . esc_html__( 'GIF Optimization Level', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
|
7770 |
"<td><span><select id='ewww_image_optimizer_gif_level' name='ewww_image_optimizer_gif_level'>\n" .
|
7771 |
"<option value='0'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ), 0, false ) . '>' . esc_html__( 'No Compression', 'ewww-image-optimizer' ) . "</option>\n" .
|
7772 |
-
"<option value='10'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ), 10, false ) . '>' . esc_html__( 'Pixel Perfect', 'ewww-image-optimizer' ) . "</option>\n" .
|
7773 |
"</select></td></tr>\n";
|
7774 |
ewwwio_debug_message( 'gif level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) );
|
7775 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_pdf_level'>" . esc_html__( 'PDF Optimization Level', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
|
@@ -7779,6 +7815,11 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
|
|
7779 |
"<option $disable_level value='20'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ), 20, false ) . '>' . esc_html__( 'High Compression', 'ewww-image-optimizer' ) . " *</option>\n" .
|
7780 |
"</select></td></tr>\n";
|
7781 |
ewwwio_debug_message( 'pdf level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) );
|
|
|
|
|
|
|
|
|
|
|
7782 |
ewwwio_debug_message( 'bulk delay: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_delay' ) );
|
7783 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_backup_files'>" . esc_html__( 'Backup Originals', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . '</th>' .
|
7784 |
"<td><input type='checkbox' id='ewww_image_optimizer_backup_files' name='ewww_image_optimizer_backup_files' value='true' " .
|
@@ -7816,10 +7857,11 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
|
|
7816 |
ewwwio_debug_message( 'ExactDN resize existing: ' . ( ewww_image_optimizer_get_option( 'exactdn_resize_existing' ) == true ? 'on' : 'off' ) );
|
7817 |
ewwwio_debug_message( 'ExactDN attachment queries: ' . ( ewww_image_optimizer_get_option( 'exactdn_prevent_db_queries' ) == true ? 'off' : 'on' ) );
|
7818 |
if ( defined( 'EXACTDN_EXCLUDE' ) && EXACTDN_EXCLUDE ) {
|
7819 |
-
|
7820 |
-
|
7821 |
-
|
7822 |
-
|
|
|
7823 |
} else {
|
7824 |
ewwwio_debug_message( 'ExactDN user exclusions invalid data type' );
|
7825 |
}
|
13 |
// TODO: might be able to use the Custom Bulk Actions in 4.7 to support the bulk optimize drop-down menu.
|
14 |
// TODO: need to make the scheduler so it can resume without having to re-run the queue population, and then we can probably also flush the queue when scheduled opt starts, but later it would be nice to implement the bulk_loop as the aux_loop so that it could handle media properly.
|
15 |
// TODO: Add a custom async function for parallel mode to store image as pending and use the row ID instead of relative path.
|
16 |
+
// TODO: write some tests for AGR.
|
|
|
17 |
// TODO: check this patch, to see if the use of 'full' causes any issues: https://core.trac.wordpress.org/ticket/37840 .
|
18 |
// TODO: use this: https://codex.wordpress.org/AJAX_in_Plugins#The_post-load_JavaScript_Event .
|
19 |
// TODO: can some of the bulk "fallbacks" be implemented for async processing?
|
23 |
exit;
|
24 |
}
|
25 |
|
26 |
+
define( 'EWWW_IMAGE_OPTIMIZER_VERSION', '460.0' );
|
27 |
|
28 |
// Initialize a couple globals.
|
29 |
$ewww_debug = '';
|
38 |
if ( ! isset( $wpdb->ewwwio_images ) ) {
|
39 |
$wpdb->ewwwio_images = $wpdb->prefix . 'ewwwio_images';
|
40 |
}
|
41 |
+
if ( ! isset( $wpdb->ewwwio_queue ) ) {
|
42 |
+
$wpdb->ewwwio_queue = $wpdb->prefix . 'ewwwio_queue';
|
43 |
+
}
|
44 |
|
45 |
if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_RELATIVE' ) ) {
|
46 |
define( 'EWWW_IMAGE_OPTIMIZER_RELATIVE', true );
|
516 |
}
|
517 |
if ( get_option( 'ewww_image_optimizer_version' ) > 0 && get_option( 'ewww_image_optimizer_version' ) < 440 && ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) || ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) < 30 ) ) {
|
518 |
add_site_option( 'exactdn_lossy', true );
|
519 |
+
}
|
520 |
+
if ( get_option( 'ewww_image_optimizer_version' ) < 454 ) {
|
521 |
+
update_option( 'ewww_image_optimizer_bulk_resume', '' );
|
522 |
+
update_option( 'ewww_image_optimizer_aux_resume', '' );
|
523 |
+
ewww_image_optimizer_delete_pending();
|
524 |
}
|
525 |
ewww_image_optimizer_remove_obsolete_settings();
|
526 |
update_option( 'ewww_image_optimizer_version', EWWW_IMAGE_OPTIMIZER_VERSION );
|
579 |
function ewww_image_optimizer_admin_init() {
|
580 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
581 |
ewwwio_memory( __FUNCTION__ );
|
582 |
+
/**
|
583 |
+
* Require the file that does the bulk processing.
|
584 |
+
*/
|
585 |
+
require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'bulk.php' );
|
586 |
+
/**
|
587 |
+
* Require the files that contain functions for the images table and bulk processing images outside the library.
|
588 |
+
*/
|
589 |
+
require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'aux-optimize.php' );
|
590 |
+
/**
|
591 |
+
* Require the files that migrate WebP images from extension replacement to extension appending.
|
592 |
+
*/
|
593 |
+
require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'mwebp.php' );
|
594 |
ewww_image_optimizer_cloud_init();
|
595 |
ewww_image_optimizer_upgrade();
|
596 |
if ( ! function_exists( 'is_plugin_active_for_network' ) && is_multisite() ) {
|
739 |
register_setting( 'ewww_image_optimizer_options', 'ewww_image_optimizer_webp_for_cdn', 'boolval' );
|
740 |
ewww_image_optimizer_exec_init();
|
741 |
ewww_image_optimizer_cron_setup( 'ewww_image_optimizer_auto' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
742 |
// Queue the function that contains custom styling for our progressbars.
|
743 |
add_action( 'admin_enqueue_scripts', 'ewww_image_optimizer_progressbar_style' );
|
744 |
// Alert user if multiple re-optimizations detected.
|
1119 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
1120 |
global $wpdb;
|
1121 |
$wpdb->ewwwio_images = $wpdb->prefix . 'ewwwio_images';
|
1122 |
+
$wpdb->ewwwio_queue = $wpdb->prefix . 'ewwwio_queue';
|
1123 |
|
1124 |
// Get the current wpdb charset and collation.
|
1125 |
$db_collation = $wpdb->get_charset_collate();
|
1223 |
// Include the upgrade library to install/upgrade a table.
|
1224 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
1225 |
$updates = dbDelta( $sql );
|
1226 |
+
ewwwio_debug_message( 'images db upgrade results: ' . implode( '<br>', $updates ) );
|
1227 |
+
|
1228 |
+
/*
|
1229 |
+
* Create a table with XX columns:
|
1230 |
+
* attachment_id: the unique id within the media library, nextgen, or flag
|
1231 |
+
* gallery: 'media', 'nextgen', 'nextcell', or 'flag',
|
1232 |
+
* scanned: 1 if the image is queued for optimization, 0 if it still needs scanning.
|
1233 |
+
*/
|
1234 |
+
$sql = "CREATE TABLE $wpdb->ewwwio_queue (
|
1235 |
+
attachment_id bigint(20) unsigned,
|
1236 |
+
gallery varchar(10),
|
1237 |
+
scanned tinyint(1) NOT NULL DEFAULT 0,
|
1238 |
+
KEY attachment_info (gallery(3),attachment_id)
|
1239 |
+
) COLLATE utf8_general_ci;";
|
1240 |
+
|
1241 |
+
// Include the upgrade library to install/upgrade a table.
|
1242 |
+
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
1243 |
+
$updates = dbDelta( $sql );
|
1244 |
+
ewwwio_debug_message( 'queue db upgrade results: ' . implode( '<br>', $updates ) );
|
1245 |
|
1246 |
// Make sure some of our options are not autoloaded (since they can be huge).
|
1247 |
+
// $bulk_attachments = get_option( 'ewww_image_optimizer_bulk_attachments', '' );.
|
1248 |
delete_option( 'ewww_image_optimizer_bulk_attachments' );
|
1249 |
+
// add_option( 'ewww_image_optimizer_bulk_attachments', $bulk_attachments, '', 'no' );.
|
1250 |
$bulk_attachments = get_option( 'ewww_image_optimizer_flag_attachments', '' );
|
1251 |
delete_option( 'ewww_image_optimizer_flag_attachments' );
|
1252 |
add_option( 'ewww_image_optimizer_flag_attachments', $bulk_attachments, '', 'no' );
|
1918 |
}
|
1919 |
|
1920 |
/**
|
1921 |
+
* Cleans up when the plugin is removed.
|
1922 |
+
*
|
1923 |
+
* Removes rules from .htaccess file added for WebP rewriting. Also clears the ewwwio_queue table.
|
1924 |
*/
|
1925 |
function ewww_image_optimizer_uninstall() {
|
1926 |
if ( ewwwio_extract_from_markers( ewww_image_optimizer_htaccess_path(), 'EWWWIO' ) ) {
|
1927 |
insert_with_markers( ewww_image_optimizer_htaccess_path(), 'EWWWIO', '' );
|
1928 |
}
|
1929 |
+
ewww_image_optimizer_delete_queue_images();
|
1930 |
+
ewww_image_optimizer_delete_queue_images( 'flag' );
|
1931 |
+
ewww_image_optimizer_delete_queue_images( 'nextgen' );
|
1932 |
+
ewww_image_optimizer_delete_queue_images( 'nextcell' );
|
1933 |
}
|
1934 |
|
1935 |
/**
|
2231 |
*/
|
2232 |
function ewww_image_optimizer_imagick_support() {
|
2233 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
2234 |
+
if ( extension_loaded( 'imagick' ) && class_exists( 'Imagick' ) ) {
|
2235 |
$imagick = new Imagick();
|
2236 |
$formats = $imagick->queryFormats();
|
2237 |
ewwwio_debug_message( implode( ',', $formats ) );
|
2250 |
*/
|
2251 |
function ewww_image_optimizer_gmagick_support() {
|
2252 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
2253 |
+
if ( extension_loaded( 'gmagick' ) && class_exists( 'Gmagick' ) ) {
|
2254 |
$gmagick = new Gmagick();
|
2255 |
$formats = $gmagick->queryFormats();
|
2256 |
ewwwio_debug_message( implode( ',', $formats ) );
|
3779 |
*
|
3780 |
* @param string $file The filename of the image.
|
3781 |
* @param int $orig_size The current filesize of the image.
|
3782 |
+
* @return string The image results from the table, if found.
|
3783 |
*/
|
3784 |
function ewww_image_optimizer_check_table( $file, $orig_size ) {
|
3785 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
3802 |
if ( is_array( $image ) && $image['image_size'] == $orig_size ) {
|
3803 |
$prev_string = ' - ' . __( 'Previously Optimized', 'ewww-image-optimizer' );
|
3804 |
if ( preg_match( '/' . __( 'License exceeded', 'ewww-image-optimizer' ) . '/', $image['results'] ) ) {
|
3805 |
+
return '';
|
3806 |
}
|
3807 |
$already_optimized = preg_replace( "/$prev_string/", '', $image['results'] );
|
3808 |
$already_optimized = $already_optimized . $prev_string;
|
3823 |
}
|
3824 |
return $already_optimized;
|
3825 |
}
|
3826 |
+
return '';
|
3827 |
}
|
3828 |
|
3829 |
/**
|
4495 |
*/
|
4496 |
function ewww_image_optimizer_better_resize( $file, $max_w, $max_h, $crop = false ) {
|
4497 |
ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
|
4498 |
+
ewwwio_debug_message( "resizing to $max_w and $max_h" );
|
4499 |
+
if ( $crop ) {
|
4500 |
+
ewwwio_debug_message( 'cropping too' );
|
4501 |
+
$crop = true;
|
4502 |
+
}
|
4503 |
$type = ewww_image_optimizer_mimetype( $file, 'i' );
|
4504 |
if ( false === strpos( $type, 'image' ) ) {
|
4505 |
ewwwio_debug_message( 'not an image, no resizing possible' );
|
7773 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_debug'>" . esc_html__( 'Debugging', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . '</th>' .
|
7774 |
"<td><input type='checkbox' id='ewww_image_optimizer_debug' name='ewww_image_optimizer_debug' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Use this to provide information for support purposes, or if you feel comfortable digging around in the code to fix a problem you are experiencing.', 'ewww-image-optimizer' ) . "</td></tr>\n";
|
7775 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_metadata_remove'>" . esc_html__( 'Remove Metadata', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
|
7776 |
+
"<td><input type='checkbox' id='ewww_image_optimizer_metadata_remove' name='ewww_image_optimizer_metadata_remove' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'This will remove ALL metadata: EXIF, comments, color profiles, and anything else that is not pixel data.', 'ewww-image-optimizer' ) .
|
7777 |
+
"<p class ='description'>" . esc_html__( 'Color profiles are preserved when using the API or ExactDN.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
|
7778 |
ewwwio_debug_message( 'remove metadata: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) == true ? 'on' : 'off' ) );
|
7779 |
+
|
7780 |
+
$maybe_api_level = ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ? '*' : '';
|
7781 |
+
|
|
|
|
|
7782 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_jpg_level'>" . esc_html__( 'JPG Optimization Level', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
|
7783 |
"<td><span><select id='ewww_image_optimizer_jpg_level' name='ewww_image_optimizer_jpg_level'>\n" .
|
7784 |
"<option value='0'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ), 0, false ) . '>' . esc_html__( 'No Compression', 'ewww-image-optimizer' ) . "</option>\n";
|
7798 |
}
|
7799 |
$output[] = "<option class='$network_class' $disable_level value='20' " . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ), 20, false ) .
|
7800 |
selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ), 30, false ) . '>' . esc_html__( 'Pixel Perfect Plus', 'ewww-image-optimizer' ) . " *</option>\n" .
|
7801 |
+
"<option value='40'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ), 40, false ) . '>' . esc_html__( 'Premium', 'ewww-image-optimizer' ) . " $maybe_api_level</option>\n" .
|
7802 |
"<option $disable_level value='50'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ), 50, false ) . '>' . esc_html__( 'Premium Plus', 'ewww-image-optimizer' ) . " *</option>\n" .
|
7803 |
"</select></td></tr>\n";
|
7804 |
ewwwio_debug_message( 'png level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) );
|
7805 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_gif_level'>" . esc_html__( 'GIF Optimization Level', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
|
7806 |
"<td><span><select id='ewww_image_optimizer_gif_level' name='ewww_image_optimizer_gif_level'>\n" .
|
7807 |
"<option value='0'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ), 0, false ) . '>' . esc_html__( 'No Compression', 'ewww-image-optimizer' ) . "</option>\n" .
|
7808 |
+
"<option value='10'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ), 10, false ) . '>' . esc_html__( 'Pixel Perfect', 'ewww-image-optimizer' ) . " $maybe_api_level</option>\n" .
|
7809 |
"</select></td></tr>\n";
|
7810 |
ewwwio_debug_message( 'gif level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) );
|
7811 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_pdf_level'>" . esc_html__( 'PDF Optimization Level', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
|
7815 |
"<option $disable_level value='20'" . selected( ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ), 20, false ) . '>' . esc_html__( 'High Compression', 'ewww-image-optimizer' ) . " *</option>\n" .
|
7816 |
"</select></td></tr>\n";
|
7817 |
ewwwio_debug_message( 'pdf level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) );
|
7818 |
+
$output[] = "<tr class='$network_class'><th> </th><td>" .
|
7819 |
+
( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ? "<p class='$network_class nocloud'>* <strong><a href='https://ewww.io/plans/' target='_blank'>" . esc_html__( 'Purchase an API key to unlock these optimization levels. Achieve up to 80% compression and see the quality for yourself.', 'ewww-image-optimizer' ) . "</a></strong></p>\n" :
|
7820 |
+
'<p>* ' . esc_html__( 'These levels use the compression API.', 'ewww-image-optimizer' ) ) .
|
7821 |
+
"<p class='$network_class description'>" . esc_html__( 'All methods used by the EWWW Image Optimizer are intended to produce visually identical images.', 'ewww-image-optimizer' ) . "</p>\n" .
|
7822 |
+
"</td></tr>\n";
|
7823 |
ewwwio_debug_message( 'bulk delay: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_delay' ) );
|
7824 |
$output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_backup_files'>" . esc_html__( 'Backup Originals', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . '</th>' .
|
7825 |
"<td><input type='checkbox' id='ewww_image_optimizer_backup_files' name='ewww_image_optimizer_backup_files' value='true' " .
|
7857 |
ewwwio_debug_message( 'ExactDN resize existing: ' . ( ewww_image_optimizer_get_option( 'exactdn_resize_existing' ) == true ? 'on' : 'off' ) );
|
7858 |
ewwwio_debug_message( 'ExactDN attachment queries: ' . ( ewww_image_optimizer_get_option( 'exactdn_prevent_db_queries' ) == true ? 'off' : 'on' ) );
|
7859 |
if ( defined( 'EXACTDN_EXCLUDE' ) && EXACTDN_EXCLUDE ) {
|
7860 |
+
$exactdn_user_exclusions = EXACTDN_EXCLUDE;
|
7861 |
+
if ( is_array( $exactdn_user_exclusions ) ) {
|
7862 |
+
ewwwio_debug_message( 'ExactDN user exclusions : ' . implode( ',', $exactdn_user_exclusions ) );
|
7863 |
+
} elseif ( is_string( $exactdn_user_exclusions ) ) {
|
7864 |
+
ewwwio_debug_message( 'ExactDN user exclusions : ' . $exactdn_user_exclusions );
|
7865 |
} else {
|
7866 |
ewwwio_debug_message( 'ExactDN user exclusions invalid data type' );
|
7867 |
}
|
ewww-image-optimizer.php
CHANGED
@@ -14,7 +14,7 @@ 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 |
Text Domain: ewww-image-optimizer
|
17 |
-
Version: 4.
|
18 |
Author URI: https://ewww.io/
|
19 |
License: GPLv3
|
20 |
*/
|
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 |
Text Domain: ewww-image-optimizer
|
17 |
+
Version: 4.6.0
|
18 |
Author URI: https://ewww.io/
|
19 |
License: GPLv3
|
20 |
*/
|
includes/load_webp.js
CHANGED
@@ -469,11 +469,10 @@ function check_webp_feature(feature, callback) {
|
|
469 |
};
|
470 |
var img = new Image();
|
471 |
img.onload = function () {
|
472 |
-
ewww_webp_supported = (img.width > 0) && (img.height > 0);
|
473 |
callback(ewww_webp_supported);
|
474 |
};
|
475 |
img.onerror = function () {
|
476 |
-
ewww_webp_supported = false;
|
477 |
callback(false);
|
478 |
};
|
479 |
img.src = "data:image/webp;base64," + kTestImages[feature];
|
@@ -583,14 +582,13 @@ function ewww_load_images(ewww_webp_supported) {
|
|
583 |
});
|
584 |
}
|
585 |
}
|
586 |
-
var ewww_webp_supported = false;
|
587 |
var ewww_jquery_waiting_timer = 0;
|
588 |
ewww_jquery_waiting = setInterval(function () {
|
589 |
if (window.jQuery) {
|
590 |
check_webp_feature('alpha', ewww_load_images);
|
591 |
check_webp_feature('alpha', ewww_ngg_plus_load_galleries);
|
592 |
document.arrive('.ewww_webp', function() {
|
593 |
-
ewww_load_images
|
594 |
});
|
595 |
var ewww_ngg_galleries_timer = 0;
|
596 |
var ewww_ngg_galleries = setInterval(function() {
|
469 |
};
|
470 |
var img = new Image();
|
471 |
img.onload = function () {
|
472 |
+
var ewww_webp_supported = (img.width > 0) && (img.height > 0);
|
473 |
callback(ewww_webp_supported);
|
474 |
};
|
475 |
img.onerror = function () {
|
|
|
476 |
callback(false);
|
477 |
};
|
478 |
img.src = "data:image/webp;base64," + kTestImages[feature];
|
582 |
});
|
583 |
}
|
584 |
}
|
|
|
585 |
var ewww_jquery_waiting_timer = 0;
|
586 |
ewww_jquery_waiting = setInterval(function () {
|
587 |
if (window.jQuery) {
|
588 |
check_webp_feature('alpha', ewww_load_images);
|
589 |
check_webp_feature('alpha', ewww_ngg_plus_load_galleries);
|
590 |
document.arrive('.ewww_webp', function() {
|
591 |
+
check_webp_feature('alpha', ewww_load_images);
|
592 |
});
|
593 |
var ewww_ngg_galleries_timer = 0;
|
594 |
var ewww_ngg_galleries = setInterval(function() {
|
includes/load_webp.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
var Arrive=function(w,e,c){"use strict";if(w.MutationObserver&&"undefined"!=typeof HTMLElement){var a,t,r=0,d=(a=HTMLElement.prototype.matches||HTMLElement.prototype.webkitMatchesSelector||HTMLElement.prototype.mozMatchesSelector||HTMLElement.prototype.msMatchesSelector,{matchesSelector:function(e,t){return e instanceof HTMLElement&&a.call(e,t)},addMethod:function(e,t,a){var r=e[t];e[t]=function(){return a.length==arguments.length?a.apply(this,arguments):"function"==typeof r?r.apply(this,arguments):void 0}},callCallbacks:function(e,t){t&&t.options.onceOnly&&1==t.firedElems.length&&(e=[e[0]]);for(var a,r=0;a=e[r];r++)a&&a.callback&&a.callback.call(a.elem,a.elem);t&&t.options.onceOnly&&1==t.firedElems.length&&t.me.unbindEventWithSelectorAndCallback.call(t.target,t.selector,t.callback)},checkChildNodesRecursively:function(e,t,a,r){for(var i,n=0;i=e[n];n++)a(i,t,r)&&r.push({callback:t.callback,elem:i}),0<i.childNodes.length&&d.checkChildNodesRecursively(i.childNodes,t,a,r)},mergeArrays:function(e,t){var a,r={};for(a in e)e.hasOwnProperty(a)&&(r[a]=e[a]);for(a in t)t.hasOwnProperty(a)&&(r[a]=t[a]);return r},toElementsArray:function(e){return void 0===e||"number"==typeof e.length&&e!==w||(e=[e]),e}}),u=((t=function(){this._eventsBucket=[],this._beforeAdding=null,this._beforeRemoving=null}).prototype.addEvent=function(e,t,a,r){var i={target:e,selector:t,options:a,callback:r,firedElems:[]};return this._beforeAdding&&this._beforeAdding(i),this._eventsBucket.push(i),i},t.prototype.removeEvent=function(e){for(var t,a=this._eventsBucket.length-1;t=this._eventsBucket[a];a--)if(e(t)){this._beforeRemoving&&this._beforeRemoving(t);var r=this._eventsBucket.splice(a,1);r&&r.length&&(r[0].callback=null)}},t.prototype.beforeAdding=function(e){this._beforeAdding=e},t.prototype.beforeRemoving=function(e){this._beforeRemoving=e},t),l=function(i,n){var l=new u,s=this,o={fireOnAttributesModification:!1};return l.beforeAdding(function(t){var e,a=t.target;a!==w.document&&a!==w||(a=document.getElementsByTagName("html")[0]),e=new MutationObserver(function(e){n.call(this,e,t)});var r=i(t.options);e.observe(a,r),t.observer=e,t.me=s}),l.beforeRemoving(function(e){e.observer.disconnect()}),this.bindEvent=function(e,t,a){t=d.mergeArrays(o,t);for(var r=d.toElementsArray(this),i=0;i<r.length;i++)l.addEvent(r[i],e,t,a)},this.unbindEvent=function(){var a=d.toElementsArray(this);l.removeEvent(function(e){for(var t=0;t<a.length;t++)if(this===c||e.target===a[t])return!0;return!1})},this.unbindEventWithSelectorOrCallback=function(a){var e,r=d.toElementsArray(this),i=a;e="function"==typeof a?function(e){for(var t=0;t<r.length;t++)if((this===c||e.target===r[t])&&e.callback===i)return!0;return!1}:function(e){for(var t=0;t<r.length;t++)if((this===c||e.target===r[t])&&e.selector===a)return!0;return!1},l.removeEvent(e)},this.unbindEventWithSelectorAndCallback=function(a,r){var i=d.toElementsArray(this);l.removeEvent(function(e){for(var t=0;t<i.length;t++)if((this===c||e.target===i[t])&&e.selector===a&&e.callback===r)return!0;return!1})},this},i=new function(){var o={fireOnAttributesModification:!1,onceOnly:!1,existing:!1};function n(e,t,a){return!(!d.matchesSelector(e,t.selector)||(e._id===c&&(e._id=r++),-1!=t.firedElems.indexOf(e._id))||(t.firedElems.push(e._id),0))}var w=(i=new l(function(e){var t={attributes:!1,childList:!0,subtree:!0};return e.fireOnAttributesModification&&(t.attributes=!0),t},function(e,i){e.forEach(function(e){var t=e.addedNodes,a=e.target,r=[];null!==t&&0<t.length?d.checkChildNodesRecursively(t,i,n,r):"attributes"===e.type&&n(a,i)&&r.push({callback:i.callback,elem:a}),d.callCallbacks(r,i)})})).bindEvent;return i.bindEvent=function(e,t,a){void 0===a?(a=t,t=o):t=d.mergeArrays(o,t);var r=d.toElementsArray(this);if(t.existing){for(var i=[],n=0;n<r.length;n++)for(var l=r[n].querySelectorAll(e),s=0;s<l.length;s++)i.push({callback:a,elem:l[s]});if(t.onceOnly&&i.length)return a.call(i[0].elem,i[0].elem);setTimeout(d.callCallbacks,1,i)}w.call(this,e,t,a)},i},s=new function(){var r={};function i(e,t){return d.matchesSelector(e,t.selector)}var n=(s=new l(function(){return{childList:!0,subtree:!0}},function(e,r){e.forEach(function(e){var t=e.removedNodes,a=[];null!==t&&0<t.length&&d.checkChildNodesRecursively(t,r,i,a),d.callCallbacks(a,r)})})).bindEvent;return s.bindEvent=function(e,t,a){void 0===a?(a=t,t=r):t=d.mergeArrays(r,t),n.call(this,e,t,a)},s};e&&h(e.fn),h(HTMLElement.prototype),h(NodeList.prototype),h(HTMLCollection.prototype),h(HTMLDocument.prototype),h(Window.prototype);var n={};return o(i,n,"unbindAllArrive"),o(s,n,"unbindAllLeave"),n}function o(e,t,a){d.addMethod(t,a,e.unbindEvent),d.addMethod(t,a,e.unbindEventWithSelectorOrCallback),d.addMethod(t,a,e.unbindEventWithSelectorAndCallback)}function h(e){e.arrive=i.bindEvent,o(i,e,"unbindArrive"),e.leave=s.bindEvent,o(s,e,"unbindLeave")}}(window,"undefined"==typeof jQuery?null:jQuery,void 0);function check_webp_feature(e,t){var a=new Image;a.onload=function(){ewww_webp_supported=0<a.width&&0<a.height,t(ewww_webp_supported)},a.onerror=function(){t(ewww_webp_supported=!1)},a.src="data:image/webp;base64,"+{alpha:"UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",animation:"UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"}[e]}function ewww_load_images(t){!function(n){n.fn.extend({ewwwattr:function(e,t){return void 0!==t&&!1!==t&&this.attr(e,t),this}});t&&(n(".batch-image img, .image-wrapper a, .ngg-pro-masonry-item a, .ngg-galleria-offscreen-seo-wrapper a").each(function(){n(this).ewwwattr("data-src",n(this).attr("data-webp")),n(this).ewwwattr("data-thumbnail",n(this).attr("data-webp-thumbnail"))}),n(".image-wrapper a, .ngg-pro-masonry-item a").each(function(){n(this).ewwwattr("href",n(this).attr("data-webp"))}),n(".rev_slider ul li").each(function(){n(this).ewwwattr("data-thumb",n(this).attr("data-webp-thumb"));for(var e=1;e<11;)n(this).ewwwattr("data-param"+e,n(this).attr("data-webp-param"+e)),e++}),n(".rev_slider img").each(function(){n(this).ewwwattr("data-lazyload",n(this).attr("data-webp-lazyload"))}),n("div.woocommerce-product-gallery__image").each(function(){n(this).ewwwattr("data-thumb",n(this).attr("data-webp-thumb"))})),n("video").each(function(){t?n(this).ewwwattr("poster",n(this).attr("data-poster-webp")):n(this).ewwwattr("poster",n(this).attr("data-poster-image"))}),n("img.ewww_webp_lazy_load").each(function(){if(t){n(this).ewwwattr("data-lazy-srcset",n(this).attr("data-lazy-srcset-webp")),n(this).ewwwattr("data-srcset",n(this).attr("data-srcset-webp")),n(this).ewwwattr("data-lazy-src",n(this).attr("data-lazy-src-webp")),n(this).ewwwattr("data-src",n(this).attr("data-src-webp")),n(this).ewwwattr("data-orig-file",n(this).attr("data-webp-orig-file")),n(this).ewwwattr("data-medium-file",n(this).attr("data-webp-medium-file")),n(this).ewwwattr("data-large-file",n(this).attr("data-webp-large-file"));var e=n(this).attr("srcset");void 0!==e&&!1!==e&&e.includes("R0lGOD")&&n(this).ewwwattr("src",n(this).attr("data-lazy-src-webp"))}n(this).removeClass("ewww_webp_lazy_load")}),n(".ewww_webp").each(function(){var e=document.createElement("img");t?(n(e).ewwwattr("src",n(this).attr("data-webp")),n(e).ewwwattr("srcset",n(this).attr("data-srcset-webp")),n(e).ewwwattr("data-orig-file",n(this).attr("data-orig-file")),n(e).ewwwattr("data-orig-file",n(this).attr("data-webp-orig-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-medium-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-webp-medium-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-large-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-webp-large-file")),n(e).ewwwattr("data-large_image",n(this).attr("data-large_image")),n(e).ewwwattr("data-large_image",n(this).attr("data-webp-large_image")),n(e).ewwwattr("data-src",n(this).attr("data-src")),n(e).ewwwattr("data-src",n(this).attr("data-webp-src"))):(n(e).ewwwattr("src",n(this).attr("data-img")),n(e).ewwwattr("srcset",n(this).attr("data-srcset-img")),n(e).ewwwattr("data-orig-file",n(this).attr("data-orig-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-medium-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-large-file")),n(e).ewwwattr("data-large_image",n(this).attr("data-large_image")),n(e).ewwwattr("data-src",n(this).attr("data-src"))),e=function(e,t){for(var a=["align","alt","border","crossorigin","height","hspace","ismap","longdesc","usemap","vspace","width","accesskey","class","contenteditable","contextmenu","dir","draggable","dropzone","hidden","id","lang","spellcheck","style","tabindex","title","translate","sizes","data-caption","data-attachment-id","data-permalink","data-orig-size","data-comments-opened","data-image-meta","data-image-title","data-image-description","data-event-trigger","data-highlight-color","data-highlight-opacity","data-highlight-border-color","data-highlight-border-width","data-highlight-border-opacity","data-no-lazy","data-lazy","data-large_image_width","data-large_image_height"],r=0,i=a.length;r<i;r++)n(t).ewwwattr(a[r],n(e).attr("data-"+a[r]));return t}(this,e),n(this).after(e),n(this).removeClass("ewww_webp")})}(jQuery),jQuery.fn.isotope&&jQuery.fn.imagesLoaded&&(jQuery(".fusion-posts-container-infinite").imagesLoaded(function(){jQuery(".fusion-posts-container-infinite").hasClass("isotope")&&jQuery(".fusion-posts-container-infinite").isotope()}),jQuery(".fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper").imagesLoaded(function(){jQuery(".fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper").isotope()}))}var ewww_webp_supported=!1,ewww_jquery_waiting_timer=0;function ewww_ngg_plus_parse_galleries(e){e&&jQuery.each(galleries,function(e,t){galleries[e].images_list=ewww_ngg_plus_parse_image_list(t.images_list)})}function ewww_ngg_plus_load_galleries(e){var i;e&&((i=jQuery)(window).on("ngg.galleria.themeadded",function(e,t){window.ngg_galleria._create_backup=window.ngg_galleria.create,window.ngg_galleria.create=function(e,t){var a=i(e).data("id");return galleries["gallery_"+a].images_list=ewww_ngg_plus_parse_image_list(galleries["gallery_"+a].images_list),window.ngg_galleria._create_backup(e,t)}}),i(window).on("override_nplModal_methods",function(e,r){r._set_events_backup=r.set_events,r.set_events=function(){return i("#npl_content").bind("npl_images_ready",function(e,t){var a=r.fetch_images.gallery_image_cache[t];a=ewww_ngg_plus_parse_image_list(a)}),r._set_events_backup()}}))}function ewww_ngg_plus_parse_image_list(i){var e;return(e=jQuery).each(i,function(a,r){void 0!==r["image-webp"]&&(i[a].image=r["image-webp"],delete i[a]["image-webp"]),void 0!==r["thumb-webp"]&&(i[a].thumb=r["thumb-webp"],delete i[a]["thumb-webp"]),void 0!==r.full_image_webp&&(i[a].full_image=r.full_image_webp,delete i[a].full_image_webp),void 0!==r.srcsets&&e.each(r.srcsets,function(e,t){void 0!==r.srcsets[e+"-webp"]&&(i[a].srcsets[e]=r.srcsets[e+"-webp"],delete i[a].srcsets[e+"-webp"])}),void 0!==r.full_srcsets&&e.each(r.full_srcsets,function(e,t){void 0!==r.full_srcsets[e+"-webp"]&&(i[a].full_srcsets[e]=r.full_srcsets[e+"-webp"],delete i[a].full_srcsets[e+"-webp"])})}),i}ewww_jquery_waiting=setInterval(function(){if(window.jQuery){check_webp_feature("alpha",ewww_load_images),check_webp_feature("alpha",ewww_ngg_plus_load_galleries),document.arrive(".ewww_webp",function(){ewww_load_images(ewww_webp_supported)});var e=0,t=setInterval(function(){"undefined"!=typeof galleries&&(check_webp_feature("alpha",ewww_ngg_plus_parse_galleries),clearInterval(t)),1e3<(e+=25)&&clearInterval(t)},25);clearInterval(ewww_jquery_waiting)}1e4<(ewww_jquery_waiting_timer+=100)&&clearInterval(ewww_jquery_waiting)},100);
|
1 |
+
var Arrive=function(c,e,w){"use strict";if(c.MutationObserver&&"undefined"!=typeof HTMLElement){var a,t,r=0,d=(a=HTMLElement.prototype.matches||HTMLElement.prototype.webkitMatchesSelector||HTMLElement.prototype.mozMatchesSelector||HTMLElement.prototype.msMatchesSelector,{matchesSelector:function(e,t){return e instanceof HTMLElement&&a.call(e,t)},addMethod:function(e,t,a){var r=e[t];e[t]=function(){return a.length==arguments.length?a.apply(this,arguments):"function"==typeof r?r.apply(this,arguments):void 0}},callCallbacks:function(e,t){t&&t.options.onceOnly&&1==t.firedElems.length&&(e=[e[0]]);for(var a,r=0;a=e[r];r++)a&&a.callback&&a.callback.call(a.elem,a.elem);t&&t.options.onceOnly&&1==t.firedElems.length&&t.me.unbindEventWithSelectorAndCallback.call(t.target,t.selector,t.callback)},checkChildNodesRecursively:function(e,t,a,r){for(var i,n=0;i=e[n];n++)a(i,t,r)&&r.push({callback:t.callback,elem:i}),0<i.childNodes.length&&d.checkChildNodesRecursively(i.childNodes,t,a,r)},mergeArrays:function(e,t){var a,r={};for(a in e)e.hasOwnProperty(a)&&(r[a]=e[a]);for(a in t)t.hasOwnProperty(a)&&(r[a]=t[a]);return r},toElementsArray:function(e){return void 0===e||"number"==typeof e.length&&e!==c||(e=[e]),e}}),u=((t=function(){this._eventsBucket=[],this._beforeAdding=null,this._beforeRemoving=null}).prototype.addEvent=function(e,t,a,r){var i={target:e,selector:t,options:a,callback:r,firedElems:[]};return this._beforeAdding&&this._beforeAdding(i),this._eventsBucket.push(i),i},t.prototype.removeEvent=function(e){for(var t,a=this._eventsBucket.length-1;t=this._eventsBucket[a];a--)if(e(t)){this._beforeRemoving&&this._beforeRemoving(t);var r=this._eventsBucket.splice(a,1);r&&r.length&&(r[0].callback=null)}},t.prototype.beforeAdding=function(e){this._beforeAdding=e},t.prototype.beforeRemoving=function(e){this._beforeRemoving=e},t),l=function(i,n){var l=new u,s=this,o={fireOnAttributesModification:!1};return l.beforeAdding(function(t){var e,a=t.target;a!==c.document&&a!==c||(a=document.getElementsByTagName("html")[0]),e=new MutationObserver(function(e){n.call(this,e,t)});var r=i(t.options);e.observe(a,r),t.observer=e,t.me=s}),l.beforeRemoving(function(e){e.observer.disconnect()}),this.bindEvent=function(e,t,a){t=d.mergeArrays(o,t);for(var r=d.toElementsArray(this),i=0;i<r.length;i++)l.addEvent(r[i],e,t,a)},this.unbindEvent=function(){var a=d.toElementsArray(this);l.removeEvent(function(e){for(var t=0;t<a.length;t++)if(this===w||e.target===a[t])return!0;return!1})},this.unbindEventWithSelectorOrCallback=function(a){var e,r=d.toElementsArray(this),i=a;e="function"==typeof a?function(e){for(var t=0;t<r.length;t++)if((this===w||e.target===r[t])&&e.callback===i)return!0;return!1}:function(e){for(var t=0;t<r.length;t++)if((this===w||e.target===r[t])&&e.selector===a)return!0;return!1},l.removeEvent(e)},this.unbindEventWithSelectorAndCallback=function(a,r){var i=d.toElementsArray(this);l.removeEvent(function(e){for(var t=0;t<i.length;t++)if((this===w||e.target===i[t])&&e.selector===a&&e.callback===r)return!0;return!1})},this},i=new function(){var o={fireOnAttributesModification:!1,onceOnly:!1,existing:!1};function n(e,t,a){return!(!d.matchesSelector(e,t.selector)||(e._id===w&&(e._id=r++),-1!=t.firedElems.indexOf(e._id))||(t.firedElems.push(e._id),0))}var c=(i=new l(function(e){var t={attributes:!1,childList:!0,subtree:!0};return e.fireOnAttributesModification&&(t.attributes=!0),t},function(e,i){e.forEach(function(e){var t=e.addedNodes,a=e.target,r=[];null!==t&&0<t.length?d.checkChildNodesRecursively(t,i,n,r):"attributes"===e.type&&n(a,i)&&r.push({callback:i.callback,elem:a}),d.callCallbacks(r,i)})})).bindEvent;return i.bindEvent=function(e,t,a){void 0===a?(a=t,t=o):t=d.mergeArrays(o,t);var r=d.toElementsArray(this);if(t.existing){for(var i=[],n=0;n<r.length;n++)for(var l=r[n].querySelectorAll(e),s=0;s<l.length;s++)i.push({callback:a,elem:l[s]});if(t.onceOnly&&i.length)return a.call(i[0].elem,i[0].elem);setTimeout(d.callCallbacks,1,i)}c.call(this,e,t,a)},i},s=new function(){var r={};function i(e,t){return d.matchesSelector(e,t.selector)}var n=(s=new l(function(){return{childList:!0,subtree:!0}},function(e,r){e.forEach(function(e){var t=e.removedNodes,a=[];null!==t&&0<t.length&&d.checkChildNodesRecursively(t,r,i,a),d.callCallbacks(a,r)})})).bindEvent;return s.bindEvent=function(e,t,a){void 0===a?(a=t,t=r):t=d.mergeArrays(r,t),n.call(this,e,t,a)},s};e&&h(e.fn),h(HTMLElement.prototype),h(NodeList.prototype),h(HTMLCollection.prototype),h(HTMLDocument.prototype),h(Window.prototype);var n={};return o(i,n,"unbindAllArrive"),o(s,n,"unbindAllLeave"),n}function o(e,t,a){d.addMethod(t,a,e.unbindEvent),d.addMethod(t,a,e.unbindEventWithSelectorOrCallback),d.addMethod(t,a,e.unbindEventWithSelectorAndCallback)}function h(e){e.arrive=i.bindEvent,o(i,e,"unbindArrive"),e.leave=s.bindEvent,o(s,e,"unbindLeave")}}(window,"undefined"==typeof jQuery?null:jQuery,void 0);function check_webp_feature(e,t){var a=new Image;a.onload=function(){var e=0<a.width&&0<a.height;t(e)},a.onerror=function(){t(!1)},a.src="data:image/webp;base64,"+{alpha:"UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",animation:"UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"}[e]}function ewww_load_images(t){!function(n){n.fn.extend({ewwwattr:function(e,t){return void 0!==t&&!1!==t&&this.attr(e,t),this}});t&&(n(".batch-image img, .image-wrapper a, .ngg-pro-masonry-item a, .ngg-galleria-offscreen-seo-wrapper a").each(function(){n(this).ewwwattr("data-src",n(this).attr("data-webp")),n(this).ewwwattr("data-thumbnail",n(this).attr("data-webp-thumbnail"))}),n(".image-wrapper a, .ngg-pro-masonry-item a").each(function(){n(this).ewwwattr("href",n(this).attr("data-webp"))}),n(".rev_slider ul li").each(function(){n(this).ewwwattr("data-thumb",n(this).attr("data-webp-thumb"));for(var e=1;e<11;)n(this).ewwwattr("data-param"+e,n(this).attr("data-webp-param"+e)),e++}),n(".rev_slider img").each(function(){n(this).ewwwattr("data-lazyload",n(this).attr("data-webp-lazyload"))}),n("div.woocommerce-product-gallery__image").each(function(){n(this).ewwwattr("data-thumb",n(this).attr("data-webp-thumb"))})),n("video").each(function(){t?n(this).ewwwattr("poster",n(this).attr("data-poster-webp")):n(this).ewwwattr("poster",n(this).attr("data-poster-image"))}),n("img.ewww_webp_lazy_load").each(function(){if(t){n(this).ewwwattr("data-lazy-srcset",n(this).attr("data-lazy-srcset-webp")),n(this).ewwwattr("data-srcset",n(this).attr("data-srcset-webp")),n(this).ewwwattr("data-lazy-src",n(this).attr("data-lazy-src-webp")),n(this).ewwwattr("data-src",n(this).attr("data-src-webp")),n(this).ewwwattr("data-orig-file",n(this).attr("data-webp-orig-file")),n(this).ewwwattr("data-medium-file",n(this).attr("data-webp-medium-file")),n(this).ewwwattr("data-large-file",n(this).attr("data-webp-large-file"));var e=n(this).attr("srcset");void 0!==e&&!1!==e&&e.includes("R0lGOD")&&n(this).ewwwattr("src",n(this).attr("data-lazy-src-webp"))}n(this).removeClass("ewww_webp_lazy_load")}),n(".ewww_webp").each(function(){var e=document.createElement("img");t?(n(e).ewwwattr("src",n(this).attr("data-webp")),n(e).ewwwattr("srcset",n(this).attr("data-srcset-webp")),n(e).ewwwattr("data-orig-file",n(this).attr("data-orig-file")),n(e).ewwwattr("data-orig-file",n(this).attr("data-webp-orig-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-medium-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-webp-medium-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-large-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-webp-large-file")),n(e).ewwwattr("data-large_image",n(this).attr("data-large_image")),n(e).ewwwattr("data-large_image",n(this).attr("data-webp-large_image")),n(e).ewwwattr("data-src",n(this).attr("data-src")),n(e).ewwwattr("data-src",n(this).attr("data-webp-src"))):(n(e).ewwwattr("src",n(this).attr("data-img")),n(e).ewwwattr("srcset",n(this).attr("data-srcset-img")),n(e).ewwwattr("data-orig-file",n(this).attr("data-orig-file")),n(e).ewwwattr("data-medium-file",n(this).attr("data-medium-file")),n(e).ewwwattr("data-large-file",n(this).attr("data-large-file")),n(e).ewwwattr("data-large_image",n(this).attr("data-large_image")),n(e).ewwwattr("data-src",n(this).attr("data-src"))),e=function(e,t){for(var a=["align","alt","border","crossorigin","height","hspace","ismap","longdesc","usemap","vspace","width","accesskey","class","contenteditable","contextmenu","dir","draggable","dropzone","hidden","id","lang","spellcheck","style","tabindex","title","translate","sizes","data-caption","data-attachment-id","data-permalink","data-orig-size","data-comments-opened","data-image-meta","data-image-title","data-image-description","data-event-trigger","data-highlight-color","data-highlight-opacity","data-highlight-border-color","data-highlight-border-width","data-highlight-border-opacity","data-no-lazy","data-lazy","data-large_image_width","data-large_image_height"],r=0,i=a.length;r<i;r++)n(t).ewwwattr(a[r],n(e).attr("data-"+a[r]));return t}(this,e),n(this).after(e),n(this).removeClass("ewww_webp")})}(jQuery),jQuery.fn.isotope&&jQuery.fn.imagesLoaded&&(jQuery(".fusion-posts-container-infinite").imagesLoaded(function(){jQuery(".fusion-posts-container-infinite").hasClass("isotope")&&jQuery(".fusion-posts-container-infinite").isotope()}),jQuery(".fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper").imagesLoaded(function(){jQuery(".fusion-portfolio:not(.fusion-recent-works) .fusion-portfolio-wrapper").isotope()}))}var ewww_jquery_waiting_timer=0;function ewww_ngg_plus_parse_galleries(e){e&&jQuery.each(galleries,function(e,t){galleries[e].images_list=ewww_ngg_plus_parse_image_list(t.images_list)})}function ewww_ngg_plus_load_galleries(e){var i;e&&((i=jQuery)(window).on("ngg.galleria.themeadded",function(e,t){window.ngg_galleria._create_backup=window.ngg_galleria.create,window.ngg_galleria.create=function(e,t){var a=i(e).data("id");return galleries["gallery_"+a].images_list=ewww_ngg_plus_parse_image_list(galleries["gallery_"+a].images_list),window.ngg_galleria._create_backup(e,t)}}),i(window).on("override_nplModal_methods",function(e,r){r._set_events_backup=r.set_events,r.set_events=function(){return i("#npl_content").bind("npl_images_ready",function(e,t){var a=r.fetch_images.gallery_image_cache[t];a=ewww_ngg_plus_parse_image_list(a)}),r._set_events_backup()}}))}function ewww_ngg_plus_parse_image_list(i){var e;return(e=jQuery).each(i,function(a,r){void 0!==r["image-webp"]&&(i[a].image=r["image-webp"],delete i[a]["image-webp"]),void 0!==r["thumb-webp"]&&(i[a].thumb=r["thumb-webp"],delete i[a]["thumb-webp"]),void 0!==r.full_image_webp&&(i[a].full_image=r.full_image_webp,delete i[a].full_image_webp),void 0!==r.srcsets&&e.each(r.srcsets,function(e,t){void 0!==r.srcsets[e+"-webp"]&&(i[a].srcsets[e]=r.srcsets[e+"-webp"],delete i[a].srcsets[e+"-webp"])}),void 0!==r.full_srcsets&&e.each(r.full_srcsets,function(e,t){void 0!==r.full_srcsets[e+"-webp"]&&(i[a].full_srcsets[e]=r.full_srcsets[e+"-webp"],delete i[a].full_srcsets[e+"-webp"])})}),i}ewww_jquery_waiting=setInterval(function(){if(window.jQuery){check_webp_feature("alpha",ewww_load_images),check_webp_feature("alpha",ewww_ngg_plus_load_galleries),document.arrive(".ewww_webp",function(){check_webp_feature("alpha",ewww_load_images)});var e=0,t=setInterval(function(){"undefined"!=typeof galleries&&(check_webp_feature("alpha",ewww_ngg_plus_parse_galleries),clearInterval(t)),1e3<(e+=25)&&clearInterval(t)},25);clearInterval(ewww_jquery_waiting)}1e4<(ewww_jquery_waiting_timer+=100)&&clearInterval(ewww_jquery_waiting)},100);
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: image, compress, resize, optimize, optimization, lossless, lossy, seo, web
|
|
5 |
Requires at least: 4.9
|
6 |
Tested up to: 5.0
|
7 |
Requires PHP: 5.6
|
8 |
-
Stable tag: 4.
|
9 |
License: GPLv3
|
10 |
|
11 |
Speed up your website and improve your visitors' experience by automatically compressing and resizing images and PDFs. Boost SEO and improve sales.
|
@@ -174,6 +174,18 @@ http://developer.yahoo.com/performance/rules.html#opt_images
|
|
174 |
* Feature requests can be viewed and submitted at https://github.com/nosilver4u/ewww-image-optimizer/labels/enhancement
|
175 |
* If you would like to help translate this plugin in your language, get started here: https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
= 4.5.3 =
|
178 |
* fixed: ExactDN duplicates srcset instead of replacing it
|
179 |
* security: remote code execution, low exposure
|
5 |
Requires at least: 4.9
|
6 |
Tested up to: 5.0
|
7 |
Requires PHP: 5.6
|
8 |
+
Stable tag: 4.6.0
|
9 |
License: GPLv3
|
10 |
|
11 |
Speed up your website and improve your visitors' experience by automatically compressing and resizing images and PDFs. Boost SEO and improve sales.
|
174 |
* Feature requests can be viewed and submitted at https://github.com/nosilver4u/ewww-image-optimizer/labels/enhancement
|
175 |
* If you would like to help translate this plugin in your language, get started here: https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/
|
176 |
|
177 |
+
= 4.6.0 =
|
178 |
+
* added: preserve animations in GIF images during resize operations for sites using Imagick extension
|
179 |
+
* changed: EXACTDN_EXCLUDE applies to all resources, including images, CSS, JS, fonts, etc.
|
180 |
+
* changed: API/ExactDN preserves color profiles, even when removing image metadata
|
181 |
+
* changed: new queue table for bulk optimizer to avoid exceeding max packet size for MySQL
|
182 |
+
* changed: unit tests run on PHP 7.3 also
|
183 |
+
* fixed: too many settings updates when trying to prevent slow queries
|
184 |
+
* fixed: ExactDN rewrites urls to static HTML files
|
185 |
+
* fixed: ExactDN skips 1x url in some cases, causing browser upscaling
|
186 |
+
* fixed: PHP notice when EXACTDN_EXCLUDE is defined
|
187 |
+
* fixed: race condition in Alt WebP prevents Webp derivatives from replacing the originals
|
188 |
+
|
189 |
= 4.5.3 =
|
190 |
* fixed: ExactDN duplicates srcset instead of replacing it
|
191 |
* security: remote code execution, low exposure
|
tests/test-convert.php
ADDED
@@ -0,0 +1,342 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class EWWWIO_Convert_Tests
|
4 |
+
*
|
5 |
+
* @link https://ewww.io
|
6 |
+
* @package Ewww_Image_Optimizer
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Conversion test cases.
|
11 |
+
*/
|
12 |
+
class EWWWIO_Convert_Tests extends WP_UnitTestCase {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* The location of the test JPG image.
|
16 |
+
*
|
17 |
+
* @var string $test_jpg
|
18 |
+
*/
|
19 |
+
public static $test_jpg = '';
|
20 |
+
|
21 |
+
/**
|
22 |
+
* The location of the test PNG image.
|
23 |
+
*
|
24 |
+
* @var string $test_png
|
25 |
+
*/
|
26 |
+
public static $test_png = '';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* The location of the test GIF image.
|
30 |
+
*
|
31 |
+
* @var string $test_gif
|
32 |
+
*/
|
33 |
+
public static $test_gif = '';
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Downloads test images.
|
37 |
+
*/
|
38 |
+
public static function setUpBeforeClass() {
|
39 |
+
self::$test_jpg = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/DCClogo.jpg' );
|
40 |
+
self::$test_png = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/common-loon.png' );
|
41 |
+
self::$test_gif = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/xhtml11.gif' );
|
42 |
+
ewww_image_optimizer_set_defaults();
|
43 |
+
update_option( 'ewww_image_optimizer_jpg_level', 10 );
|
44 |
+
update_option( 'ewww_image_optimizer_gif_level', 10 );
|
45 |
+
update_option( 'ewww_image_optimizer_webp', true );
|
46 |
+
update_option( 'ewww_image_optimizer_png_level', 40 );
|
47 |
+
update_site_option( 'ewww_image_optimizer_webp', true );
|
48 |
+
update_site_option( 'ewww_image_optimizer_png_level', 40 );
|
49 |
+
ewww_image_optimizer_install_tools();
|
50 |
+
ewww_image_optimizer_install_pngout();
|
51 |
+
update_option( 'ewww_image_optimizer_webp', '' );
|
52 |
+
update_option( 'ewww_image_optimizer_png_level', 10 );
|
53 |
+
update_site_option( 'ewww_image_optimizer_webp', '' );
|
54 |
+
update_site_option( 'ewww_image_optimizer_png_level', 10 );
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Initializes the plugin and installs the ewwwio_images table.
|
59 |
+
*/
|
60 |
+
function setUp() {
|
61 |
+
parent::setUp();
|
62 |
+
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
|
63 |
+
ewww_image_optimizer_install_table();
|
64 |
+
add_filter( 'query', array( $this, '_create_temporary_tables' ) );
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Copies the test JPG to a temp file, optimizes it, and returns the results.
|
69 |
+
*
|
70 |
+
* @return array The results of the ewww_image_optimizer() function.
|
71 |
+
*/
|
72 |
+
protected function optimize_jpg( $original = false ) {
|
73 |
+
if ( ! $original ) {
|
74 |
+
$original = self::$test_jpg;
|
75 |
+
}
|
76 |
+
$_REQUEST['ewww_force'] = 1;
|
77 |
+
$filename = $original . ".jpg";
|
78 |
+
copy( $original, $filename );
|
79 |
+
$results = ewww_image_optimizer( $filename, 1 );
|
80 |
+
return $results;
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Copies the test PNG to a temp file, optimizes it, and returns the results.
|
85 |
+
*
|
86 |
+
* @return array The results of the ewww_image_optimizer() function.
|
87 |
+
*/
|
88 |
+
protected function optimize_png( $original = false ) {
|
89 |
+
if ( ! $original ) {
|
90 |
+
$original = self::$test_png;
|
91 |
+
}
|
92 |
+
$_REQUEST['ewww_force'] = 1;
|
93 |
+
$filename = $original . ".png";
|
94 |
+
copy( $original, $filename );
|
95 |
+
$results = ewww_image_optimizer( $filename, 1 );
|
96 |
+
return $results;
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Copies the test GIF to a temp file, optimizes it, and returns the results.
|
101 |
+
*
|
102 |
+
* @return array The results of the ewww_image_optimizer() function.
|
103 |
+
*/
|
104 |
+
protected function optimize_gif( $original = false ) {
|
105 |
+
if ( ! $original ) {
|
106 |
+
$original = self::$test_gif;
|
107 |
+
}
|
108 |
+
$_REQUEST['ewww_force'] = 1;
|
109 |
+
$filename = $original . ".gif";
|
110 |
+
copy( $original, $filename );
|
111 |
+
$results = ewww_image_optimizer( $filename, 1 );
|
112 |
+
return $results;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Test JPG to PNG conversion.
|
117 |
+
*/
|
118 |
+
function test_convert_jpg_to_png() {
|
119 |
+
update_option( 'ewww_image_optimizer_metadata_remove', true );
|
120 |
+
update_option( 'ewww_image_optimizer_jpg_level', 10 );
|
121 |
+
update_option( 'ewww_image_optimizer_png_level', 10 );
|
122 |
+
update_option( 'ewww_image_optimizer_jpg_to_png', true );
|
123 |
+
update_site_option( 'ewww_image_optimizer_metadata_remove', true );
|
124 |
+
update_site_option( 'ewww_image_optimizer_jpg_level', 10 );
|
125 |
+
update_site_option( 'ewww_image_optimizer_png_level', 10 );
|
126 |
+
update_site_option( 'ewww_image_optimizer_jpg_to_png', true );
|
127 |
+
|
128 |
+
$results = $this->optimize_jpg();
|
129 |
+
$this->assertEquals( 'image/png', ewww_image_optimizer_mimetype( $results[0], 'i' ) );
|
130 |
+
unlink( $results[0] );
|
131 |
+
|
132 |
+
update_option( 'ewww_image_optimizer_cloud_key', 'abc123' );
|
133 |
+
update_option( 'ewww_image_optimizer_jpg_level', 20 );
|
134 |
+
update_site_option( 'ewww_image_optimizer_cloud_key', 'abc123' );
|
135 |
+
update_site_option( 'ewww_image_optimizer_jpg_level', 20 );
|
136 |
+
$results = $this->optimize_jpg();
|
137 |
+
$this->assertEquals( 'image/png', ewww_image_optimizer_mimetype( $results[0], 'i' ) );
|
138 |
+
unlink( $results[0] );
|
139 |
+
|
140 |
+
update_option( 'ewww_image_optimizer_jpg_to_png', '' );
|
141 |
+
update_option( 'ewww_image_optimizer_cloud_key', '' );
|
142 |
+
update_site_option( 'ewww_image_optimizer_jpg_to_png', '' );
|
143 |
+
update_site_option( 'ewww_image_optimizer_cloud_key', '' );
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Test PNG to JPG conversion.
|
148 |
+
*/
|
149 |
+
function test_convert_png_to_jpg() {
|
150 |
+
update_option( 'ewww_image_optimizer_png_level', 10 );
|
151 |
+
update_option( 'ewww_image_optimizer_jpg_level', 10 );
|
152 |
+
update_option( 'ewww_image_optimizer_disable_pngout', true );
|
153 |
+
update_option( 'ewww_image_optimizer_optipng_level', 2 );
|
154 |
+
update_option( 'ewww_image_optimizer_metadata_remove', true );
|
155 |
+
update_option( 'ewww_image_optimizer_png_to_jpg', true );
|
156 |
+
update_site_option( 'ewww_image_optimizer_png_level', 10 );
|
157 |
+
update_site_option( 'ewww_image_optimizer_jpg_level', 10 );
|
158 |
+
update_site_option( 'ewww_image_optimizer_disable_pngout', true );
|
159 |
+
update_site_option( 'ewww_image_optimizer_optipng_level', 2 );
|
160 |
+
update_site_option( 'ewww_image_optimizer_metadata_remove', true );
|
161 |
+
update_site_option( 'ewww_image_optimizer_png_to_jpg', true );
|
162 |
+
$results = $this->optimize_png();
|
163 |
+
update_option( 'ewww_image_optimizer_png_to_jpg', '' );
|
164 |
+
update_site_option( 'ewww_image_optimizer_png_to_jpg', '' );
|
165 |
+
$this->assertEquals( 'image/jpeg', ewww_image_optimizer_mimetype( $results[0], 'i' ) );
|
166 |
+
unlink( $results[0] );
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Test PNG to JPG conversion with alpha.
|
171 |
+
*/
|
172 |
+
function test_convert_png_to_jpg_alpha() {
|
173 |
+
update_option( 'ewww_image_optimizer_png_level', 10 );
|
174 |
+
update_option( 'ewww_image_optimizer_jpg_level', 10 );
|
175 |
+
update_option( 'ewww_image_optimizer_disable_pngout', true );
|
176 |
+
update_option( 'ewww_image_optimizer_optipng_level', 2 );
|
177 |
+
update_option( 'ewww_image_optimizer_metadata_remove', true );
|
178 |
+
update_option( 'ewww_image_optimizer_png_to_jpg', true );
|
179 |
+
update_option( 'ewww_image_optimizer_jpg_background', '' );
|
180 |
+
update_site_option( 'ewww_image_optimizer_png_level', 10 );
|
181 |
+
update_site_option( 'ewww_image_optimizer_jpg_level', 10 );
|
182 |
+
update_site_option( 'ewww_image_optimizer_disable_pngout', true );
|
183 |
+
update_site_option( 'ewww_image_optimizer_optipng_level', 2 );
|
184 |
+
update_site_option( 'ewww_image_optimizer_metadata_remove', true );
|
185 |
+
update_site_option( 'ewww_image_optimizer_png_to_jpg', true );
|
186 |
+
update_site_option( 'ewww_image_optimizer_jpg_background', '' );
|
187 |
+
|
188 |
+
// No background, conversion will fail.
|
189 |
+
$test_png = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/books.png' );
|
190 |
+
$results = $this->optimize_png( $test_png );
|
191 |
+
$this->assertEquals( 'image/png', ewww_image_optimizer_mimetype( $results[0], 'i' ) );
|
192 |
+
unlink( $results[0] );
|
193 |
+
|
194 |
+
// Set background, conversion will succeed.
|
195 |
+
update_option( 'ewww_image_optimizer_jpg_background', 'ffffff' );
|
196 |
+
update_site_option( 'ewww_image_optimizer_jpg_background', 'ffffff' );
|
197 |
+
$results = $this->optimize_png( $test_png );
|
198 |
+
$this->assertEquals( 'image/jpeg', ewww_image_optimizer_mimetype( $results[0], 'i' ) );
|
199 |
+
unlink( $results[0] );
|
200 |
+
|
201 |
+
// No background, conversion will fail, using API.
|
202 |
+
update_option( 'ewww_image_optimizer_png_level', 20 );
|
203 |
+
update_option( 'ewww_image_optimizer_jpg_background', '' );
|
204 |
+
update_option( 'ewww_image_optimizer_cloud_key', 'abc123' );
|
205 |
+
update_site_option( 'ewww_image_optimizer_png_level', 20 );
|
206 |
+
update_site_option( 'ewww_image_optimizer_jpg_background', '' );
|
207 |
+
update_site_option( 'ewww_image_optimizer_cloud_key', 'abc123' );
|
208 |
+
$results = $this->optimize_png( $test_png );
|
209 |
+
$this->assertEquals( 'image/png', ewww_image_optimizer_mimetype( $results[0], 'i' ) );
|
210 |
+
unlink( $results[0] );
|
211 |
+
|
212 |
+
// Set background, conversion will succeed, using API.
|
213 |
+
update_option( 'ewww_image_optimizer_jpg_background', 'ffffff' );
|
214 |
+
update_site_option( 'ewww_image_optimizer_jpg_background', 'ffffff' );
|
215 |
+
$results = $this->optimize_png( $test_png );
|
216 |
+
$this->assertEquals( 'image/jpeg', ewww_image_optimizer_mimetype( $results[0], 'i' ) );
|
217 |
+
unlink( $results[0] );
|
218 |
+
|
219 |
+
update_option( 'ewww_image_optimizer_png_to_jpg', '' );
|
220 |
+
update_option( 'ewww_image_optimizer_jpg_background', '' );
|
221 |
+
update_option( 'ewww_image_optimizer_cloud_key', '' );
|
222 |
+
update_site_option( 'ewww_image_optimizer_png_to_jpg', '' );
|
223 |
+
update_site_option( 'ewww_image_optimizer_jpg_background', '' );
|
224 |
+
update_site_option( 'ewww_image_optimizer_cloud_key', '' );
|
225 |
+
unlink( $test_png );
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Tests autoconvert by uploading a PNG attachment.
|
230 |
+
*/
|
231 |
+
function test_autoconvert_png_local() {
|
232 |
+
update_option( 'ewww_image_optimizer_png_level', 10 );
|
233 |
+
update_site_option( 'ewww_image_optimizer_png_level', 10 );
|
234 |
+
|
235 |
+
$upload_png = self::$test_png . '.png';
|
236 |
+
copy( self::$test_png, $upload_png );
|
237 |
+
$id = $this->factory->attachment->create_upload_object( $upload_png );
|
238 |
+
$meta = wp_get_attachment_metadata( $id );
|
239 |
+
list( $file_path, $upload_path ) = ewww_image_optimizer_attachment_path( $meta, $id );
|
240 |
+
$this->assertEquals( 'image/jpeg', ewww_image_optimizer_mimetype( $file_path, 'i' ) );
|
241 |
+
|
242 |
+
$test_png = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/books.png' );
|
243 |
+
$upload_png = $test_png . '.png';
|
244 |
+
copy( $test_png, $upload_png );
|
245 |
+
$id = $this->factory->attachment->create_upload_object( $upload_png );
|
246 |
+
$meta = wp_get_attachment_metadata( $id );
|
247 |
+
list( $file_path, $upload_path ) = ewww_image_optimizer_attachment_path( $meta, $id );
|
248 |
+
$this->assertEquals( 'image/png', ewww_image_optimizer_mimetype( $file_path, 'i' ) );
|
249 |
+
|
250 |
+
unlink( $test_png );
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Tests attachment conversion by uploading a PNG attachment and then converting it.
|
255 |
+
*/
|
256 |
+
function test_convert_png_attachment() {
|
257 |
+
ewww_image_optimizer_set_option( 'ewww_image_optimizer_png_level', 0 );
|
258 |
+
ewww_image_optimizer_set_option( 'ewww_image_optimizer_disable_autoconvert', true );
|
259 |
+
|
260 |
+
$upload_png = self::$test_png . '.png';
|
261 |
+
copy( self::$test_png, $upload_png );
|
262 |
+
$id = $this->factory->attachment->create_upload_object( $upload_png );
|
263 |
+
$meta = wp_get_attachment_metadata( $id );
|
264 |
+
list( $file_path, $upload_path ) = ewww_image_optimizer_attachment_path( $meta, $id );
|
265 |
+
$this->assertEquals( 'image/png', ewww_image_optimizer_mimetype( $file_path, 'i' ) );
|
266 |
+
|
267 |
+
global $ewww_new_image;
|
268 |
+
$ewww_new_image = true;
|
269 |
+
ewww_image_optimizer_set_option( 'ewww_image_optimizer_png_level', 10 );
|
270 |
+
ewww_image_optimizer_set_option( 'ewww_image_optimizer_png_to_jpg', true );
|
271 |
+
$meta = ewww_image_optimizer_resize_from_meta_data( $meta, $id, false, true );
|
272 |
+
list( $file_path, $upload_path ) = ewww_image_optimizer_attachment_path( $meta, $id );
|
273 |
+
$this->assertEquals( 'image/jpeg', ewww_image_optimizer_mimetype( $file_path, 'i' ) );
|
274 |
+
|
275 |
+
$base_dir = trailingslashit( dirname( $file_path ) );
|
276 |
+
foreach ( $meta['sizes'] as $size => $data ) {
|
277 |
+
$image_path = $base_dir . $data['file'];
|
278 |
+
$this->assertEquals( 'image/jpeg', ewww_image_optimizer_mimetype( $image_path, 'i' ) );
|
279 |
+
}
|
280 |
+
|
281 |
+
ewww_image_optimizer_set_option( 'ewww_image_optimizer_png_to_jpg', '' );
|
282 |
+
ewww_image_optimizer_set_option( 'ewww_image_optimizer_disable_autoconvert', '' );
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Test GIF to PNG conversion.
|
287 |
+
*/
|
288 |
+
function test_convert_gif_to_png() {
|
289 |
+
update_option( 'ewww_image_optimizer_gif_level', 10 );
|
290 |
+
update_option( 'ewww_image_optimizer_png_level', 10 );
|
291 |
+
update_option( 'ewww_image_optimizer_gif_to_png', true );
|
292 |
+
update_site_option( 'ewww_image_optimizer_gif_level', 10 );
|
293 |
+
update_site_option( 'ewww_image_optimizer_png_level', 10 );
|
294 |
+
update_site_option( 'ewww_image_optimizer_gif_to_png', true );
|
295 |
+
|
296 |
+
$results = $this->optimize_gif();
|
297 |
+
$this->assertEquals( 'image/png', ewww_image_optimizer_mimetype( $results[0], 'i' ) );
|
298 |
+
unlink( $results[0] );
|
299 |
+
|
300 |
+
update_option( 'ewww_image_optimizer_cloud_key', 'abc123' );
|
301 |
+
update_site_option( 'ewww_image_optimizer_cloud_key', 'abc123' );
|
302 |
+
$results = $this->optimize_gif();
|
303 |
+
$this->assertEquals( 'image/png', ewww_image_optimizer_mimetype( $results[0], 'i' ) );
|
304 |
+
unlink( $results[0] );
|
305 |
+
|
306 |
+
update_option( 'ewww_image_optimizer_gif_to_png', '' );
|
307 |
+
update_option( 'ewww_image_optimizer_cloud_key', '' );
|
308 |
+
update_site_option( 'ewww_image_optimizer_gif_to_png', '' );
|
309 |
+
update_site_option( 'ewww_image_optimizer_cloud_key', '' );
|
310 |
+
}
|
311 |
+
|
312 |
+
/**
|
313 |
+
* Cleans up ewwwio_images table.
|
314 |
+
*/
|
315 |
+
function tearDown() {
|
316 |
+
global $wpdb;
|
317 |
+
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
|
318 |
+
$wpdb->query( "DROP TABLE IF EXISTS $wpdb->ewwwio_images" );
|
319 |
+
add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
|
320 |
+
delete_option( 'ewww_image_optimizer_version' );
|
321 |
+
delete_option( 'ewww_image_optimizer_cloud_key' );
|
322 |
+
delete_site_option( 'ewww_image_optimizer_version' );
|
323 |
+
delete_site_option( 'ewww_image_optimizer_cloud_key' );
|
324 |
+
parent::tearDown();
|
325 |
+
}
|
326 |
+
|
327 |
+
/**
|
328 |
+
* Cleans up the temp images.
|
329 |
+
*/
|
330 |
+
public static function tearDownAfterClass() {
|
331 |
+
if ( is_file( self::$test_jpg ) ) {
|
332 |
+
unlink( self::$test_jpg );
|
333 |
+
}
|
334 |
+
if ( is_file( self::$test_png ) ) {
|
335 |
+
unlink( self::$test_png );
|
336 |
+
}
|
337 |
+
if ( is_file( self::$test_gif ) ) {
|
338 |
+
unlink( self::$test_gif );
|
339 |
+
}
|
340 |
+
ewww_image_optimizer_remove_binaries();
|
341 |
+
}
|
342 |
+
}
|
tests/test-optimize.php
CHANGED
@@ -48,8 +48,8 @@ class EWWWIO_Optimize_Tests extends WP_UnitTestCase {
|
|
48 |
self::$test_gif = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/gifsiclelogo.gif' );
|
49 |
self::$test_pdf = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/tomtempleartist-bio-2008.pdf' );
|
50 |
ewww_image_optimizer_set_defaults();
|
51 |
-
update_option( 'ewww_image_optimizer_jpg_level',
|
52 |
-
update_option( 'ewww_image_optimizer_gif_level',
|
53 |
update_option( 'ewww_image_optimizer_webp', true );
|
54 |
update_option( 'ewww_image_optimizer_png_level', 40 );
|
55 |
update_site_option( 'ewww_image_optimizer_webp', true );
|
48 |
self::$test_gif = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/gifsiclelogo.gif' );
|
49 |
self::$test_pdf = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/tomtempleartist-bio-2008.pdf' );
|
50 |
ewww_image_optimizer_set_defaults();
|
51 |
+
update_option( 'ewww_image_optimizer_jpg_level', 10 );
|
52 |
+
update_option( 'ewww_image_optimizer_gif_level', 10 );
|
53 |
update_option( 'ewww_image_optimizer_webp', true );
|
54 |
update_option( 'ewww_image_optimizer_png_level', 40 );
|
55 |
update_site_option( 'ewww_image_optimizer_webp', true );
|
tests/test-tables.php
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Class EWWWIO_Table_Tests
|
4 |
+
*
|
5 |
+
* @link https://ewww.io
|
6 |
+
* @package Ewww_Image_Optimizer
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Custom table test cases.
|
11 |
+
*/
|
12 |
+
class EWWWIO_Table_Tests extends WP_UnitTestCase {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* The location of the test GIF image.
|
16 |
+
*
|
17 |
+
* @var string $test_gif
|
18 |
+
*/
|
19 |
+
public static $test_gif = '';
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Downloads test images.
|
23 |
+
*/
|
24 |
+
public static function setUpBeforeClass() {
|
25 |
+
self::$test_gif = download_url( 'https://s3-us-west-2.amazonaws.com/exactlywww/gifsiclelogo.gif' );
|
26 |
+
ewww_image_optimizer_set_defaults();
|
27 |
+
update_option( 'ewww_image_optimizer_gif_level', 10 );
|
28 |
+
update_site_option( 'ewww_image_optimizer_gif_level', 10 );
|
29 |
+
ewww_image_optimizer_install_tools();
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Initializes the plugin and installs the ewwwio_images table.
|
34 |
+
*/
|
35 |
+
function setUp() {
|
36 |
+
parent::setUp();
|
37 |
+
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
|
38 |
+
ewww_image_optimizer_install_table();
|
39 |
+
add_filter( 'query', array( $this, '_create_temporary_tables' ) );
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Copies the test GIF to a temp file, optimizes it, and returns the results.
|
44 |
+
*
|
45 |
+
* @return array The results of the ewww_image_optimizer() function.
|
46 |
+
*/
|
47 |
+
protected function optimize_gif( $original = false ) {
|
48 |
+
if ( ! $original ) {
|
49 |
+
$original = self::$test_gif;
|
50 |
+
}
|
51 |
+
$_REQUEST['ewww_force'] = 1;
|
52 |
+
$filename = $original . ".gif";
|
53 |
+
copy( $original, $filename );
|
54 |
+
$results = ewww_image_optimizer( $filename, 1 );
|
55 |
+
return $results;
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Test updating records in table.
|
60 |
+
*/
|
61 |
+
function test_ewwwio_images_table() {
|
62 |
+
global $wpdb;
|
63 |
+
global $ewww_image;
|
64 |
+
$orig_size = filesize( self::$test_gif );
|
65 |
+
$results = $this->optimize_gif();
|
66 |
+
$ewww_image = false;
|
67 |
+
|
68 |
+
$opt_file = $results[0];
|
69 |
+
$results_msg = ewww_image_optimizer_check_table( $opt_file, $orig_size );
|
70 |
+
$this->assertEmpty( $results_msg );
|
71 |
+
|
72 |
+
$ewww_image = false;
|
73 |
+
$file_size = filesize( $opt_file );
|
74 |
+
$results_msg = ewww_image_optimizer_check_table( $opt_file, $file_size );
|
75 |
+
$this->assertStringStartsWith( 'Reduced by', $results_msg );
|
76 |
+
|
77 |
+
$second_results_msg = ewww_image_optimizer_update_table( $opt_file, $file_size - 500, $orig_size );
|
78 |
+
$this->assertStringStartsWith( 'Reduced by', $second_results_msg );
|
79 |
+
$this->assertNotEquals( $results_msg, $second_results_msg );
|
80 |
+
|
81 |
+
$ewww_image = false;
|
82 |
+
$results_msg = ewww_image_optimizer_check_table( $opt_file, $file_size - 500 );
|
83 |
+
$this->assertStringStartsWith( $second_results_msg, $results_msg );
|
84 |
+
|
85 |
+
$record = ewww_image_optimizer_find_already_optimized( $opt_file );
|
86 |
+
unset( $record['id'] );
|
87 |
+
$record['image_size'] = $file_size;
|
88 |
+
$wpdb->insert( $wpdb->ewwwio_images, $record );
|
89 |
+
$record['image_size'] = 0;
|
90 |
+
$record['results'] = '';
|
91 |
+
$wpdb->insert( $wpdb->ewwwio_images, $record );
|
92 |
+
|
93 |
+
$ewww_image = false;
|
94 |
+
$results_msg = ewww_image_optimizer_check_table( $opt_file, $file_size );
|
95 |
+
|
96 |
+
$this->assertStringStartsWith( 'Reduced by', $results_msg );
|
97 |
+
|
98 |
+
unlink( $results[0] );
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Cleans up ewwwio_images table.
|
103 |
+
*/
|
104 |
+
function tearDown() {
|
105 |
+
global $wpdb;
|
106 |
+
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
|
107 |
+
$wpdb->query( "DROP TABLE IF EXISTS $wpdb->ewwwio_images" );
|
108 |
+
add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
|
109 |
+
delete_option( 'ewww_image_optimizer_version' );
|
110 |
+
delete_site_option( 'ewww_image_optimizer_version' );
|
111 |
+
parent::tearDown();
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* Cleans up the temp images.
|
116 |
+
*/
|
117 |
+
public static function tearDownAfterClass() {
|
118 |
+
if ( is_file( self::$test_gif ) ) {
|
119 |
+
unlink( self::$test_gif );
|
120 |
+
}
|
121 |
+
ewww_image_optimizer_remove_binaries();
|
122 |
+
}
|
123 |
+
}
|