From 16bf5884d26bd41bace45d2c23814ef70d2ca52d Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 5 Apr 2022 15:57:40 +0100 Subject: [PATCH 1/4] Some times attachments can be something else than images --- php/class-delivery.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index 60a45c87d..7ad07395b 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -199,7 +199,12 @@ public function filter_out_cloudinary( $content ) { $original_url = $urls[ $result['public_id'] ]; $size = $this->media->get_size_from_url( $original_url ); $transformations = $this->media->get_transformations_from_string( $original_url ); - $attachment_url = wp_get_attachment_image_url( $result['post_id'], $size ); + + if ( 'image' === $this->media->get_resource_type( $result['post_id'] ) ) { + $attachment_url = wp_get_attachment_image_url( $result['post_id'], $size ); + } else { + $attachment_url = wp_get_attachment_url( $result['post_id'] ); + } if ( ! empty( $transformations ) ) { $transformations = array_filter( $transformations, From 7436ff2d213ee613b727ed4c9b20d56d4f3f0684 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 5 Apr 2022 15:58:30 +0100 Subject: [PATCH 2/4] The `poster` on videos can also be local URLs --- php/media/class-video.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/php/media/class-video.php b/php/media/class-video.php index 7940658b5..01c93e823 100644 --- a/php/media/class-video.php +++ b/php/media/class-video.php @@ -262,6 +262,17 @@ public function filter_video_block_pre_render( $block, $source_block ) { } else { $url = $this->media->cloudinary_url( $attachment_id ); $content = str_replace( $attributes['src'], $url, $content ); + + if ( ! empty( $attributes['poster'] ) ) { + // Maybe local URL. + if ( ! $this->media->is_cloudinary_url( $attributes['poster'] ) ) { + $post_id = attachment_url_to_postid( $attributes['poster'] ); + $url = $this->media->cloudinary_url( $post_id ); + if ( $url ) { + $content = str_replace( $attributes['poster'], $url, $content ); + } + } + } } } } @@ -343,6 +354,13 @@ protected function build_video_embed( $attachment_id, $attributes = array(), $ov // Set the poster. if ( isset( $attributes['poster'] ) ) { $poster_id = $this->media->get_public_id_from_url( $attributes['poster'] ); + + // Maybe poster is a local URL. + if ( empty( $poster_id ) ) { + $post_id = attachment_url_to_postid( $attributes['poster'] ); + $poster_id = $this->media->get_public_id( $post_id ); + } + if ( $poster_id ) { $params['source']['poster']['public_id'] = $poster_id; $poster_transformation = array( From 3366145ccbc5ecd4cc73d7e22018fc28d1843821 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 5 Apr 2022 15:58:50 +0100 Subject: [PATCH 3/4] Prevent infinit loop --- src/js/inline-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/inline-loader.js b/src/js/inline-loader.js index 503868fd0..8083a6be8 100644 --- a/src/js/inline-loader.js +++ b/src/js/inline-loader.js @@ -170,7 +170,7 @@ const CloudinaryLoader = { width = image.width; let height = Math.round( width / ratio ); - while ( -1 === this.sizeBands.indexOf( width ) || ( height < image.height && width < maxSize ) ) { + while ( -1 === this.sizeBands.indexOf( width ) && height < image.height && width < maxSize ) { width++; height = Math.round( width / ratio ); } From c680b7df56f56758361b4d07b8c07fd8d6a11c75 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Tue, 5 Apr 2022 15:59:09 +0100 Subject: [PATCH 4/4] Update compiled assets --- js/inline-loader.asset.php | 2 +- js/inline-loader.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/inline-loader.asset.php b/js/inline-loader.asset.php index 390a29dff..303850ea0 100644 --- a/js/inline-loader.asset.php +++ b/js/inline-loader.asset.php @@ -1 +1 @@ - array('wp-polyfill'), 'version' => '07dbede220b80a24f3f811ea67147d4b'); \ No newline at end of file + array('wp-polyfill'), 'version' => '39ba4cb29fd218134452ff60f8146083'); \ No newline at end of file diff --git a/js/inline-loader.js b/js/inline-loader.js index 055cdc136..5b65e3d36 100644 --- a/js/inline-loader.js +++ b/js/inline-loader.js @@ -1 +1 @@ -!function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(i,n,function(t){return e[t]}.bind(null,n));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=161)}({14:function(e,t,r){var i=r(9);e.exports=function(e,t){if(e){if("string"==typeof e)return i(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},161:function(e,t,r){"use strict";r.r(t);var i=r(8),n=r.n(i),o={deviceDensity:window.devicePixelRatio?window.devicePixelRatio:"auto",density:null,config:CLDLB||{},lazyThreshold:0,enabled:!1,sizeBands:[],iObserver:null,pObserver:null,rObserver:null,aboveFold:!0,minPlaceholderThreshold:500,bind:function(e){var t=this;e.CLDbound=!0,this.enabled||this._init();var r=e.dataset.size.split(" ");e.originalWidth=r[0],e.originalHeight=r[1],this.pObserver?(this.aboveFold&&this.inInitialView(e)?this.buildImage(e):(this.pObserver.observe(e),this.iObserver.observe(e)),e.addEventListener("error",(function(r){e.srcset="",e.src='data:image/svg+xml;utf8,%26%23x26A0%3B︎',t.rObserver.unobserve(e)}))):this.setupFallback(e)},buildImage:function(e){e.dataset.srcset?(e.cld_loaded=!0,e.srcset=e.dataset.srcset):(e.src=this.getSizeURL(e),e.dataset.responsive&&this.rObserver.observe(e))},inInitialView:function(e){var t=e.getBoundingClientRect();return this.aboveFold=t.top=t;)e-=r,this.sizeBands.push(e);"undefined"!=typeof IntersectionObserver&&this._setupObservers(),this.enabled=!0},_setupObservers:function(){var e=this,t={rootMargin:this.lazyThreshold+"px 0px "+this.lazyThreshold+"px 0px"},r=this.minPlaceholderThreshold<2*this.lazyThreshold?2*this.lazyThreshold:this.minPlaceholderThreshold,i={rootMargin:r+"px 0px "+r+"px 0px"};this.rObserver=new ResizeObserver((function(t,r){t.forEach((function(t){t.target.cld_loaded&&t.contentRect.width>=t.target.cld_loaded&&(t.target.src=e.getSizeURL(t.target))}))})),this.iObserver=new IntersectionObserver((function(t,r){t.forEach((function(t){t.isIntersecting&&(e.buildImage(t.target),r.unobserve(t.target),e.pObserver.unobserve(t.target))}))}),t),this.pObserver=new IntersectionObserver((function(t,r){t.forEach((function(t){t.isIntersecting&&(t.target.src=e.getPlaceholderURL(t.target),r.unobserve(t.target))}))}),i)},_calcThreshold:function(){var e=this.config.lazy_threshold.replace(/[^0-9]/g,""),t=0;switch(this.config.lazy_threshold.replace(/[0-9]/g,"").toLowerCase()){case"em":t=parseFloat(getComputedStyle(document.body).fontSize)*e;break;case"rem":t=parseFloat(getComputedStyle(document.documentElement).fontSize)*e;break;case"vh":t=window.innerHeight/e*100;break;default:t=e}this.lazyThreshold=parseInt(t,10)},_getDensity:function(){var e=this.config.dpr?this.config.dpr.replace("X",""):"off";if("off"===e)return this.density=1,1;var t=this.deviceDensity;"max"!==e&&"auto"!==t&&(e=parseFloat(e),t=t>Math.ceil(e)?e:t),this.density=t},scaleWidth:function(e,t,r){var i=parseInt(this.config.max_width);if(!t){t=e.width;for(var n=Math.round(t/r);-1===this.sizeBands.indexOf(t)||ni&&(t=i),e.originalWidthe.length)&&(t=e.length);for(var r=0,i=new Array(t);r%26%23x26A0%3B︎',t.rObserver.unobserve(e)}))):this.setupFallback(e)},buildImage:function(e){e.dataset.srcset?(e.cld_loaded=!0,e.srcset=e.dataset.srcset):(e.src=this.getSizeURL(e),e.dataset.responsive&&this.rObserver.observe(e))},inInitialView:function(e){var t=e.getBoundingClientRect();return this.aboveFold=t.top=t;)e-=r,this.sizeBands.push(e);"undefined"!=typeof IntersectionObserver&&this._setupObservers(),this.enabled=!0},_setupObservers:function(){var e=this,t={rootMargin:this.lazyThreshold+"px 0px "+this.lazyThreshold+"px 0px"},r=this.minPlaceholderThreshold<2*this.lazyThreshold?2*this.lazyThreshold:this.minPlaceholderThreshold,i={rootMargin:r+"px 0px "+r+"px 0px"};this.rObserver=new ResizeObserver((function(t,r){t.forEach((function(t){t.target.cld_loaded&&t.contentRect.width>=t.target.cld_loaded&&(t.target.src=e.getSizeURL(t.target))}))})),this.iObserver=new IntersectionObserver((function(t,r){t.forEach((function(t){t.isIntersecting&&(e.buildImage(t.target),r.unobserve(t.target),e.pObserver.unobserve(t.target))}))}),t),this.pObserver=new IntersectionObserver((function(t,r){t.forEach((function(t){t.isIntersecting&&(t.target.src=e.getPlaceholderURL(t.target),r.unobserve(t.target))}))}),i)},_calcThreshold:function(){var e=this.config.lazy_threshold.replace(/[^0-9]/g,""),t=0;switch(this.config.lazy_threshold.replace(/[0-9]/g,"").toLowerCase()){case"em":t=parseFloat(getComputedStyle(document.body).fontSize)*e;break;case"rem":t=parseFloat(getComputedStyle(document.documentElement).fontSize)*e;break;case"vh":t=window.innerHeight/e*100;break;default:t=e}this.lazyThreshold=parseInt(t,10)},_getDensity:function(){var e=this.config.dpr?this.config.dpr.replace("X",""):"off";if("off"===e)return this.density=1,1;var t=this.deviceDensity;"max"!==e&&"auto"!==t&&(e=parseFloat(e),t=t>Math.ceil(e)?e:t),this.density=t},scaleWidth:function(e,t,r){var i=parseInt(this.config.max_width);if(!t){t=e.width;for(var n=Math.round(t/r);-1===this.sizeBands.indexOf(t)&&ni&&(t=i),e.originalWidthe.length)&&(t=e.length);for(var r=0,i=new Array(t);r