From 86aeec71c5f9e38c29762f8fb460e9b11bec16f1 Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Sat, 30 Mar 2024 07:33:11 +1000 Subject: [PATCH 01/10] Init 1.9.1 release --- README.md | 2 +- cf-images.php | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ed46325..6ee8ff2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Donate link: https://www.paypal.com/donate/?business=JRR6QPRGTZ46N&no_recurring= Requires at least: 5.6 Requires PHP: 7.0 Tested up to: 6.5 -Stable tag: 1.9.0 +Stable tag: 1.9.1 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html diff --git a/cf-images.php b/cf-images.php index 7dd2b67..085f208 100644 --- a/cf-images.php +++ b/cf-images.php @@ -14,7 +14,7 @@ * Plugin Name: Offload Media to Cloudflare Images * Plugin URI: https://vcore.au * Description: Offload media library images to the `Cloudflare Images` service. - * Version: 1.9.0 + * Version: 1.9.1-beta.1 * Author: Anton Vanyukov * Author URI: https://vcore.au * License: GPL-2.0+ @@ -31,7 +31,7 @@ die; } -define( 'CF_IMAGES_VERSION', '1.9.0' ); +define( 'CF_IMAGES_VERSION', '1.9.1-beta.1' ); define( 'CF_IMAGES_DIR_URL', plugin_dir_url( __FILE__ ) ); require_once 'app/class-activator.php'; diff --git a/package.json b/package.json index 68fb71d..024d956 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cf-images", "description": "Offload, Store, Resize & Optimize with Cloudflare Images", - "version": "1.9.0", + "version": "1.9.1-beta.1", "main": "cf-images.php", "author": "Anton Vanyukov", "license": "GPL-2.0-or-later", From 6efafd7d0cef1d8290fd72ce656aa6f8ca11f424 Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Sat, 30 Mar 2024 07:34:52 +1000 Subject: [PATCH 02/10] Improve disable WordPress image sizes option --- CHANGELOG.md | 5 +++++ README.md | 5 +++++ app/class-image.php | 6 +++++- app/modules/class-cloudflare-images.php | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66c54d6..b7c90a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ += 1.9.1 = + +Fixed: +* "Disable WordPress image sizes" option causing issues with image URLs + = 1.9.0 - 22.03.2024 = Added: diff --git a/README.md b/README.md index 6ee8ff2..c950bf7 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,11 @@ If something is still not working for you, please let me know by creating a supp == Changelog == += 1.9.1 = + +Fixed: +* "Disable WordPress image sizes" option causing issues with image URLs + = 1.9.0 - 22.03.2024 = Added: diff --git a/app/class-image.php b/app/class-image.php index 49c2079..7969a63 100644 --- a/app/class-image.php +++ b/app/class-image.php @@ -324,7 +324,11 @@ private function generate_url( string $image_url, bool $is_src = false ) { $original = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $image_url ); } elseif ( false !== strpos( $image_url, '-scaled.' ) ) { $original = str_replace( '-scaled.', '.', $image_url ); - $size[1] = apply_filters( 'big_image_size_threshold', 2560 ); + + $scaled_size = apply_filters( 'big_image_size_threshold', 2560 ); + $scaled_size = false === $scaled_size ? 2560 : $scaled_size; + + $size[1] = $scaled_size; } else { $original = $image_url; } diff --git a/app/modules/class-cloudflare-images.php b/app/modules/class-cloudflare-images.php index 4ccfb8a..347e157 100644 --- a/app/modules/class-cloudflare-images.php +++ b/app/modules/class-cloudflare-images.php @@ -202,6 +202,7 @@ public function get_attachment_image_src( $image, $attachment_id, $size ) { // Handle `scaled` images. if ( false !== strpos( $image[0], '-scaled' ) ) { $scaled_size = apply_filters( 'big_image_size_threshold', 2560 ); + $scaled_size = false === $scaled_size ? 2560 : $scaled_size; /** * This covers two cases: From 4629d8bc0278eb72f8fd13b4ed17fd2528917dc4 Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Sat, 30 Mar 2024 07:35:21 +1000 Subject: [PATCH 03/10] Adjust changelog --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c950bf7..e228984 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ If something is still not working for you, please let me know by creating a supp = 1.9.1 = Fixed: + * "Disable WordPress image sizes" option causing issues with image URLs = 1.9.0 - 22.03.2024 = From 0d420691d21ebd96d0e7c2afb8d5fc4ef21d6f9f Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Sat, 30 Mar 2024 08:06:08 +1000 Subject: [PATCH 04/10] Improve WPML compatibility --- CHANGELOG.md | 1 + README.md | 2 +- app/class-image.php | 5 ++++- app/integrations/class-wpml.php | 6 ++++++ app/modules/class-cloudflare-images.php | 3 +++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c90a0..dce10c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ = 1.9.1 = Fixed: +* WPML compatibility * "Disable WordPress image sizes" option causing issues with image URLs = 1.9.0 - 22.03.2024 = diff --git a/README.md b/README.md index e228984..9fb6a95 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ If something is still not working for you, please let me know by creating a supp = 1.9.1 = Fixed: - +* WPML compatibility * "Disable WordPress image sizes" option causing issues with image URLs = 1.9.0 - 22.03.2024 = diff --git a/app/class-image.php b/app/class-image.php index 7969a63..860548e 100644 --- a/app/class-image.php +++ b/app/class-image.php @@ -361,7 +361,10 @@ private function generate_url( string $image_url, bool $is_src = false ) { return false; } - list( $hash, $this->cf_image_id ) = Cloudflare_Images::get_hash_id_url_string( $this->id ); + // This is used with WPML integration. + $attachment_id = apply_filters( 'cf_images_media_post_id', $this->id ); + + list( $hash, $this->cf_image_id ) = Cloudflare_Images::get_hash_id_url_string( $attachment_id ); if ( empty( $this->cf_image_id ) || ( empty( $hash ) && ! apply_filters( 'cf_images_module_enabled', false, 'custom-path' ) ) ) { return false; diff --git a/app/integrations/class-wpml.php b/app/integrations/class-wpml.php index afebd0a..6287c12 100644 --- a/app/integrations/class-wpml.php +++ b/app/integrations/class-wpml.php @@ -32,6 +32,12 @@ class Wpml { * @since 1.4.0 */ public function __construct() { + global $sitepress; + + if ( ! $sitepress ) { + return; + } + add_filter( 'cf_images_media_post_id', array( $this, 'get_original_image_id' ) ); add_action( 'cf_images_before_wp_query', array( $this, 'remove_wpml_filters' ) ); add_action( 'cf_images_upload_success', array( $this, 'update_image_meta' ), 10, 2 ); diff --git a/app/modules/class-cloudflare-images.php b/app/modules/class-cloudflare-images.php index 347e157..9d7f42b 100644 --- a/app/modules/class-cloudflare-images.php +++ b/app/modules/class-cloudflare-images.php @@ -149,6 +149,9 @@ public function get_attachment_image_src( $image, $attachment_id, $size ) { return $image; } + // This is used with WPML integration. + $attachment_id = apply_filters( 'cf_images_media_post_id', $attachment_id ); + list( $hash, $cloudflare_image_id ) = self::get_hash_id_url_string( (int) $attachment_id ); if ( empty( $cloudflare_image_id ) || ( empty( $hash ) && ! $this->is_module_enabled( false, 'custom-path' ) ) ) { From 0fbf82d1930a5f2da7eb51a5d25aeef015b3f561 Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Sun, 14 Apr 2024 08:06:27 +1000 Subject: [PATCH 05/10] Fix number of tags --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9fb6a95..94a9bd3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ === Offload, AI & Optimize with Cloudflare Images === Plugin Name: Offload, AI & Optimize with Cloudflare Images Contributors: vanyukov -Tags: cdn, cloudflare images, offload images, compress, cloudflare, optimize +Tags: cdn, cloudflare images, offload images, compress, optimize Donate link: https://www.paypal.com/donate/?business=JRR6QPRGTZ46N&no_recurring=0&item_name=Help+support+the+development+of+the+Cloudflare+Images+plugin+for+WordPress¤cy_code=AUD Requires at least: 5.6 Requires PHP: 7.0 From 1f81843fae18c809fc4931851f2ed2462d9a57a1 Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Sun, 21 Apr 2024 09:26:50 +1000 Subject: [PATCH 06/10] Add integration with Elementor lightbox --- CHANGELOG.md | 3 ++ app/class-core.php | 1 + app/integrations/class-elementor.php | 71 ++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 app/integrations/class-elementor.php diff --git a/CHANGELOG.md b/CHANGELOG.md index dce10c0..5fd80f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ = 1.9.1 = +Added: +* Integration with Elementor lightbox + Fixed: * WPML compatibility * "Disable WordPress image sizes" option causing issues with image URLs diff --git a/app/class-core.php b/app/class-core.php index 4c7b3ae..9c0ef4e 100644 --- a/app/class-core.php +++ b/app/class-core.php @@ -188,6 +188,7 @@ private function init_integrations() { $loader->integration( 'acf' ); $loader->integration( 'wpml' ); $loader->integration( 'shortpixel' ); + $loader->integration( 'elementor' ); } /** diff --git a/app/integrations/class-elementor.php b/app/integrations/class-elementor.php new file mode 100644 index 0000000..9883555 --- /dev/null +++ b/app/integrations/class-elementor.php @@ -0,0 +1,71 @@ + + * @since 1.9.1 + */ + +namespace CF_Images\App\Integrations; + +use CF_Images\App\Traits; +use Elementor\Widget_Base; +use Elementor\Widget_Image_Carousel; + +if ( ! defined( 'WPINC' ) ) { + die; +} + +/** + * Elementor class. + * + * @since 1.9.1 + */ +class Elementor { + use Traits\Helpers; + + /** + * Class constructor. + * + * @since 1.9.1 + */ + public function __construct() { + add_filter( 'elementor/widget/render_content', array( $this, 'add_lightbox_support' ), 10, 2 ); + } + + /** + * Fix lightbox widgets in Elementor. + * + * The frontend.js script in Elementor has the isLightboxLink() function which checks if the lightbox link is valid. + * This function checks if a link ends with a supported extension (png|jpe?g|gif|svg|webp). Cloudflare Images links, + * on the other hand, do not end with an extension, but rather with a set of parameters. To fix this we can append + * a hash #.jpg to the end of all image URLs. + * + * @since 1.9.1 + * + * @param string $widget_content The content of the widget. + * @param Widget_Base $widget The widget. + */ + public function add_lightbox_support( string $widget_content, Widget_Base $widget ): string { + if ( ! $widget instanceof Widget_Image_Carousel ) { + return $widget_content; + } + + // Regular expression to find tags with data-elementor-open-lightbox="yes" and Cloudflare Images links. + $pattern = '/(]*data-elementor-open-lightbox="yes"[^>]*href=")(' . preg_quote( $this->get_cdn_domain(), '/' ) . '[^"]+)(")/i'; + + // Callback function to append '#.jpg' to the href attribute. + $callback = function ( $matches ) { + // Append '#.jpg' only if it's not already appended. + return $matches[1] . $matches[2] . ( substr( $matches[2], -5 ) !== '#.jpg' ? '#.jpg' : '' ) . $matches[3]; + }; + + return preg_replace_callback( $pattern, $callback, $widget_content ); + } +} From 321d299604dcc749809c72950aa500e3c869c5dc Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Sun, 21 Apr 2024 12:23:09 +1000 Subject: [PATCH 07/10] Fix AI image captioning --- CHANGELOG.md | 1 + README.md | 4 ++++ app/modules/class-image-ai.php | 13 ++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fd80f6..ed66501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Added: * Integration with Elementor lightbox Fixed: +* AI image captioning when custom image paths are set * WPML compatibility * "Disable WordPress image sizes" option causing issues with image URLs diff --git a/README.md b/README.md index 94a9bd3..b35fbe9 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,11 @@ If something is still not working for you, please let me know by creating a supp = 1.9.1 = +Added: +* Integration with Elementor lightbox + Fixed: +* AI image captioning when custom image paths are set * WPML compatibility * "Disable WordPress image sizes" option causing issues with image URLs diff --git a/app/modules/class-image-ai.php b/app/modules/class-image-ai.php index 84ff1ad..56d7167 100644 --- a/app/modules/class-image-ai.php +++ b/app/modules/class-image-ai.php @@ -138,12 +138,23 @@ public function ajax_caption_image() { * @return string|void|WP_Error */ private function caption_image( int $attachment_id ) { + $restore_filter = false; + if ( has_filter( 'cf_images_hash', '__return_empty_string' ) ) { + $restore_filter = true; + remove_filter( 'cf_images_hash', '__return_empty_string' ); + } + list( $hash, $cloudflare_image_id ) = Cloudflare_Images::get_hash_id_url_string( $attachment_id ); if ( empty( $cloudflare_image_id ) || ( empty( $hash ) && ! $this->is_module_enabled( false, 'custom-path' ) ) ) { $image = wp_get_original_image_url( $attachment_id ); } else { - $image = trailingslashit( $this->get_cdn_domain() . "/$hash" ) . "$cloudflare_image_id/w=9999"; + // Use the default Cloudflare Images URL here, so we do not get issues with access. + $image = trailingslashit( "https://imagedelivery.net/$hash" ) . "$cloudflare_image_id/w=9999"; + } + + if ( $restore_filter ) { + add_filter( 'cf_images_hash', '__return_empty_string' ); } try { From 9b3c8a4f8def710fcb318fe8b52b0dd85e9e2cd9 Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Mon, 22 Apr 2024 20:23:23 +1000 Subject: [PATCH 08/10] Fix NaN undefined error --- CHANGELOG.md | 1 + README.md | 1 + assets/_src/js/helpers/format.ts | 2 +- assets/_src/modules/fuzion/ai-stats.tsx | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed66501..9aa8048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Added: * Integration with Elementor lightbox Fixed: +* NaN undefined error in compression savings stats * AI image captioning when custom image paths are set * WPML compatibility * "Disable WordPress image sizes" option causing issues with image URLs diff --git a/README.md b/README.md index b35fbe9..b85cf03 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ Added: * Integration with Elementor lightbox Fixed: +* NaN undefined error in compression savings stats * AI image captioning when custom image paths are set * WPML compatibility * "Disable WordPress image sizes" option causing issues with image URLs diff --git a/assets/_src/js/helpers/format.ts b/assets/_src/js/helpers/format.ts index f220bdf..1670106 100644 --- a/assets/_src/js/helpers/format.ts +++ b/assets/_src/js/helpers/format.ts @@ -1,5 +1,5 @@ export const formatBytes = (bytes: number, decimals: number = 2) => { - if (bytes === 0) { + if (isNaN(bytes) || bytes <= 0) { return '0 B'; } diff --git a/assets/_src/modules/fuzion/ai-stats.tsx b/assets/_src/modules/fuzion/ai-stats.tsx index 8de8c1d..4b2c934 100644 --- a/assets/_src/modules/fuzion/ai-stats.tsx +++ b/assets/_src/modules/fuzion/ai-stats.tsx @@ -100,8 +100,8 @@ const CompressionStats = () => {

{formatBytes( - (stats.size_before ?? 0) - - (stats.size_after ?? 0) + Number(stats.size_before ?? 0) - + Number(stats.size_after ?? 0) )}

From e3dd4ace15c63fae58d22caf417340cfa1f8ac6d Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Mon, 22 Apr 2024 20:24:02 +1000 Subject: [PATCH 09/10] Adjust tags in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b85cf03..a5e0ee7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ === Offload, AI & Optimize with Cloudflare Images === Plugin Name: Offload, AI & Optimize with Cloudflare Images Contributors: vanyukov -Tags: cdn, cloudflare images, offload images, compress, optimize +Tags: cdn, cloudflare images, image ai, compress, optimize Donate link: https://www.paypal.com/donate/?business=JRR6QPRGTZ46N&no_recurring=0&item_name=Help+support+the+development+of+the+Cloudflare+Images+plugin+for+WordPress¤cy_code=AUD Requires at least: 5.6 Requires PHP: 7.0 From 8e8bcf99a798b1d0314f36b9974cc3a258eb060a Mon Sep 17 00:00:00 2001 From: Anton Vanyukov Date: Tue, 23 Apr 2024 17:23:12 +1000 Subject: [PATCH 10/10] Prepare for 1.9.1 release --- CHANGELOG.md | 2 +- README.md | 2 +- cf-images.php | 4 ++-- package.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9aa8048..05b3508 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -= 1.9.1 = += 1.9.1 - 23.04.2024 = Added: * Integration with Elementor lightbox diff --git a/README.md b/README.md index a5e0ee7..cfb3162 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ If something is still not working for you, please let me know by creating a supp == Changelog == -= 1.9.1 = += 1.9.1 - 23.04.2024 = Added: * Integration with Elementor lightbox diff --git a/cf-images.php b/cf-images.php index 085f208..27df360 100644 --- a/cf-images.php +++ b/cf-images.php @@ -14,7 +14,7 @@ * Plugin Name: Offload Media to Cloudflare Images * Plugin URI: https://vcore.au * Description: Offload media library images to the `Cloudflare Images` service. - * Version: 1.9.1-beta.1 + * Version: 1.9.1 * Author: Anton Vanyukov * Author URI: https://vcore.au * License: GPL-2.0+ @@ -31,7 +31,7 @@ die; } -define( 'CF_IMAGES_VERSION', '1.9.1-beta.1' ); +define( 'CF_IMAGES_VERSION', '1.9.1' ); define( 'CF_IMAGES_DIR_URL', plugin_dir_url( __FILE__ ) ); require_once 'app/class-activator.php'; diff --git a/package.json b/package.json index 024d956..7abcf72 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cf-images", "description": "Offload, Store, Resize & Optimize with Cloudflare Images", - "version": "1.9.1-beta.1", + "version": "1.9.1", "main": "cf-images.php", "author": "Anton Vanyukov", "license": "GPL-2.0-or-later",