PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
← All changes | includes/import/image-parsers/ablocks/image-hotspot-parser.php +49 -0 2.7.4 → 2.14.0 View file →
@@ -1,0 +1,49 @@
1 +<?php
2 +
3 +namespace ABlocks\import\ImageParsers\ablocks;
4 +
5 +use ABlocks\import\ImageParsers\AbstractImageParser;
6 +
7 +class ImageHotspotParser extends AbstractImageParser {
8 +
9 + protected function parse() {
10 + if ( ! isset( $this->block['attrs']['backgroundImage'] ) ) {
11 + return;
12 + }
13 +
14 + $image_url = $this->block['attrs']['backgroundImage'];
15 + if ( ! $this->check_external_url( $image_url ) ) {
16 + return;
17 + }
18 +
19 + $attachment_id = $this->upload_file( $image_url );
20 + if ( is_wp_error( $attachment_id ) ) {
21 + return;
22 + }
23 +
24 + $attachment_url = wp_get_attachment_url( $attachment_id );
25 + $this->block['attrs']['backgroundImage'] = $attachment_url;
26 + $remote_images = [ $image_url => $attachment_url ];
27 +
28 + if ( isset( $this->block['attrs']['imageSizes']['thumbnail'] ) ) {
29 + $thumbnail_url = wp_get_attachment_image_url( $attachment_id );
30 + $remote_images[ $this->block['attrs']['imageSizes']['thumbnail']['url'] ] = $thumbnail_url;
31 + $this->block['attrs']['imageSizes']['thumbnail']['url'] = $thumbnail_url;
32 + }
33 +
34 + if ( isset( $this->block['attrs']['imageSizes']['medium'] ) ) {
35 + $medium_url = wp_get_attachment_image_url( $attachment_id, 'medium' );
36 + $remote_images[ $this->block['attrs']['imageSizes']['medium']['url'] ] = $medium_url;
37 + $this->block['attrs']['imageSizes']['medium']['url'] = $medium_url;
38 + }
39 +
40 + if ( isset( $this->block['attrs']['imageSizes']['full'] ) ) {
41 + $full_url = wp_get_attachment_image_url( $attachment_id, 'full' );
42 + $remote_images[ $this->block['attrs']['imageSizes']['full']['url'] ] = $full_url;
43 + $this->block['attrs']['imageSizes']['full']['url'] = $full_url;
44 + }
45 +
46 + $this->block['innerHTML'] = str_replace( array_keys( $remote_images ), array_values( $remote_images ), $this->block['innerHTML'] );
47 + $this->block['innerContent'] = array_map( fn( $content) => str_replace( array_keys( $remote_images ), array_values( $remote_images ), $content ), $this->block['innerContent'] );
48 + }
49 +}