From fa9ff9eb1804cde13d66bc2c4851561fc4ca4f1d Mon Sep 17 00:00:00 2001 From: Andrew Zhdanovskih Date: Sat, 8 May 2021 10:24:59 +0500 Subject: [PATCH 1/2] Fix UUID generation --- includes/UcFront.php | 41 ++++++++++++++++++++++--------------- includes/UploadcareMain.php | 2 +- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/includes/UcFront.php b/includes/UcFront.php index cd32e3c..1f7c556 100644 --- a/includes/UcFront.php +++ b/includes/UcFront.php @@ -4,7 +4,7 @@ class UcFront { - const IMAGE_REGEX = '/(ID, 'uploadcare_url', true))) { + $ucUrl = \get_post_meta($attachment->ID, 'uploadcare_url_modifiers', true); + if ($ucUrl) { return $response; } + $uuid = \get_post_meta($attachment->ID, 'uploadcare_uuid', true); + if (empty($uuid)) { + $uuid = UploadcareMain::getUuid($ucUrl); + } + $response['meta'] = [ 'uploadcare_url_modifiers' => \get_post_meta($attachment->ID, 'uploadcare_url_modifiers', true), - 'uploadcare_url' => \get_post_meta($attachment->ID, 'uploadcare_url', true), - 'uploadcare_uuid' => \get_post_meta($attachment->ID, 'uploadcare_uuid', true), + 'uploadcare_url' => $ucUrl, + 'uploadcare_uuid' => $uuid, ]; return $response; @@ -122,15 +128,13 @@ protected function changeContent(string $content, int $imageId): string $modifiers = \get_post_meta($imageId, 'uploadcare_url_modifiers', true); $crawler->filterXPath('//img')->each(function (Crawler $node) use (&$collation, $imageId, $modifiers) { - $imageUrl = $node->attr('src'); $attachedFile = \get_post_meta($imageId, '_wp_attached_file', true); $isLocal = true; if (\strpos($attachedFile, \get_option('uploadcare_cdn_base')) !== false) { - $imageUrl = \sprintf('https://%s/%s/', \get_option('uploadcare_cdn_base'), \get_post_meta($imageId, 'uploadcare_uuid', true)); + $imageUrl = \sprintf('https://%s/%s/', \get_option('uploadcare_cdn_base'), $this->getUuid($imageId)); $isLocal = false; - } - if ($isLocal && \strpos($imageUrl, \get_option('uploadcare_cdn_base')) !== true) { + } else { $imageUrl = \wp_get_attachment_image_url($imageId, 'large'); } @@ -140,15 +144,7 @@ protected function changeContent(string $content, int $imageId): string } // If Adaptive delivery is on and Secure uploads is on too we have to change url to uuid and ignore all local files if ($this->adaptiveDelivery && $this->secureUploads) { - $uuid = \get_post_meta($imageId, 'uploadcare_uuid', true); - if (!$uuid) { - $uuid = UploadcareMain::getUuid(\get_post_meta($imageId, 'uploadcare_url', true)); - if ($uuid !== null) { - \update_post_meta($imageId, 'uploadcare_uuid', $uuid); - } - } - - $imageUrl = !$isLocal ? $uuid : null; + $imageUrl = !$isLocal ? $this->getUuid($imageId) : null; } if ($imageUrl !== null && $isLocal === false) { $imageUrl = \sprintf('%s/%s', \rtrim($imageUrl, '/'), $modifiers); @@ -180,6 +176,17 @@ protected function changeContent(string $content, int $imageId): string return $content; } + protected function getUuid(int $postId): string + { + $uuid = \get_post_meta($postId, 'uploadcare_uuid', true); + if (empty($uuid)) { + $uuid = UploadcareMain::getUuid(\get_post_meta($postId, 'uploadcare_url', true)); + \update_post_meta($postId, 'uploadcare_uuid', $uuid); + } + + return $uuid; + } + /** * Calls on `post_thumbnail_html`. If thumbnail is an uploadcare image, make it an adaptive delivered. * diff --git a/includes/UploadcareMain.php b/includes/UploadcareMain.php index 455d312..859c694 100644 --- a/includes/UploadcareMain.php +++ b/includes/UploadcareMain.php @@ -6,7 +6,7 @@ class UploadcareMain public const SCALE_CROP_TEMPLATE = '%s-/preview/%s/'; public const RESIZE_TEMPLATE = '%s-/preview/%s/-/quality/lightest/-/format/auto/'; public const PREVIEW_TEMPLATE = '%s-/preview/160x160/-/resize/160x/-/scale_crop/160x160/'; - public const UUID_REGEX = '/\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/'; + public const UUID_REGEX = '/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/'; /** * @var UcLoader From bfb21f35145ca6439c9912a10bc953342ea52177 Mon Sep 17 00:00:00 2001 From: Roman Sedykh Date: Wed, 26 May 2021 14:34:59 +0300 Subject: [PATCH 2/2] Bump to 3.0.6 w/ changelog --- CHANGELOG.md | 11 +++++++++-- readme.txt | 11 ++++++++--- uploadcare.php | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40a55d7..83e5345 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,12 @@ All notable changes to this project will be documented in this file. The format is based now on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [3.1.0] — 2021-04-07 +## [3.0.6] — 2021-05-26 + +* Fixed an issue with missing UUIDs for previously uploaded images, which led to an error while rendering images. +* Various fixes and improvements. + +## [3.0.5] — 2021-04-07 * Now you can copy your WordPress Media Library to Uploadcare cloud storage. Files in Media Library don’t get removed. * Image source URLs in posts don’t change. However, when a post is rendered, images get delivered with Uploadcare CDN powered by Adaptive Delivery technology. @@ -279,7 +284,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. [uploadcare/uploadcare-php]: https://github.com/uploadcare/uploadcare-php -[Unreleased]: https://github.com/uploadcare/uploadcare-wordpress/compare/v3.0.4..HEAD +[Unreleased]: https://github.com/uploadcare/uploadcare-wordpress/compare/v3.0.6..HEAD +[3.0.6]: https://github.com/uploadcare/uploadcare-wordpress/compare/v3.0.5..v3.0.6 +[3.0.5]: https://github.com/uploadcare/uploadcare-wordpress/compare/v3.0.4..v3.0.5 [3.0.4]: https://github.com/uploadcare/uploadcare-wordpress/compare/v3.0.3..v3.0.4 [3.0.3]: https://github.com/uploadcare/uploadcare-wordpress/compare/v3.0.2..v3.0.3 [3.0.2]: https://github.com/uploadcare/uploadcare-wordpress/compare/v3.0.1..v3.0.2 diff --git a/readme.txt b/readme.txt index d53819c..1d3eff3 100644 --- a/readme.txt +++ b/readme.txt @@ -3,9 +3,9 @@ Contributors: andrew72ru, rsedykh Tags: file upload, cdn, storage, adaptive delivery, responsive, lazy loading, optimization, performance Requires at least: 5.0 -Tested up to: 5.7 +Tested up to: 5.7.2 Requires PHP: 7.1 -Stable tag: 3.0.4 +Stable tag: 3.0.6 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Donate link: https://uploadcare.com/pricing/ @@ -132,7 +132,12 @@ Access all files in your Uploadcare account via Media Library. == Changelog == -= 3.1.0 = += 3.0.6 = + +* Fixed an issue with missing UUIDs for previously uploaded images, which led to an error while rendering images. +* Various fixes and improvements. + += 3.0.5 = * Now you can copy your WordPress Media Library to Uploadcare cloud storage. Files in Media Library don’t get removed. * Image source URLs in posts don’t change. However, when a post is rendered, images get delivered with Uploadcare CDN powered by Adaptive Delivery technology. diff --git a/uploadcare.php b/uploadcare.php index 692298c..dc533bf 100644 --- a/uploadcare.php +++ b/uploadcare.php @@ -9,7 +9,7 @@ * Plugin Name: Uploadcare File Uploader and Adaptive Delivery * Plugin URI: https://github.com/uploadcare/uploadcare-wordpress * Description: Upload and store any file of any size from any device or cloud. No more slow downs when serving your images with automatic responsiviness and lazy loading. Improve your WP performance to boost Customer Experience and SEO. - * Version: 3.0.5 + * Version: 3.0.6 * Author: Uploadcare * Author URI: https://uploadcare.com/ * License: GPL-2.0+ @@ -19,7 +19,7 @@ */ class Uploadcare_Wordpress_Plugin { - public const UPLOADCARE_VERSION = '3.0.5'; + public const UPLOADCARE_VERSION = '3.0.6'; public function __construct() {