← All changes
|
includes/import/image-parsers/ablocks/flip-box-parser.php
+57
-0
2.7.6
→
2.15.0
View file →
| @@ -1,0 +1,57 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace ABlocks\import\ImageParsers\ablocks; | |
| 4 | + | |
| 5 | +use ABlocks\import\ImageParsers\AbstractImageParser; | |
| 6 | + | |
| 7 | +class FlipBoxParser extends AbstractImageParser { | |
| 8 | + | |
| 9 | + public function parse() { | |
| 10 | + $this->parse_background(); | |
| 11 | + $this->parse_background_hover(); | |
| 12 | + } | |
| 13 | + | |
| 14 | + private function parse_background() { | |
| 15 | + if ( ! isset( $this->block['attrs']['frontCardBackground'] ) || 'image' !== $this->block['attrs']['frontCardBackground']['backgroundType'] ) { | |
| 16 | + return; | |
| 17 | + } | |
| 18 | + | |
| 19 | + $imgUrl = $this->block['attrs']['frontCardBackground']['imgUrl']; | |
| 20 | + if ( empty( $imgUrl ) ) { | |
| 21 | + return; | |
| 22 | + } | |
| 23 | + | |
| 24 | + if ( $this->check_external_url( $imgUrl ) ) { | |
| 25 | + $attachment_id = $this->upload_file( $imgUrl ); | |
| 26 | + if ( is_wp_error( $attachment_id ) ) { | |
| 27 | + return; | |
| 28 | + } | |
| 29 | + | |
| 30 | + $attachment_url = wp_get_attachment_url( $attachment_id ); | |
| 31 | + $this->block['attrs']['frontCardBackground']['imgId'] = $attachment_id; | |
| 32 | + $this->block['attrs']['frontCardBackground']['imgUrl'] = $attachment_url; | |
| 33 | + } | |
| 34 | + } | |
| 35 | + | |
| 36 | + private function parse_background_hover() { | |
| 37 | + if ( ! isset( $this->block['attrs']['frontCardBackground'] ) || 'image' !== $this->block['attrs']['frontCardBackground']['backgroundTypeH'] ) { | |
| 38 | + return; | |
| 39 | + } | |
| 40 | + | |
| 41 | + $imgUrl = $this->block['attrs']['frontCardBackground']['imgUrlH']; | |
| 42 | + if ( empty( $imgUrl ) ) { | |
| 43 | + return; | |
| 44 | + } | |
| 45 | + | |
| 46 | + if ( $this->check_external_url( $imgUrl ) ) { | |
| 47 | + $attachment_id = $this->upload_file( $imgUrl ); | |
| 48 | + if ( is_wp_error( $attachment_id ) ) { | |
| 49 | + return; | |
| 50 | + } | |
| 51 | + | |
| 52 | + $attachment_url = wp_get_attachment_url( $attachment_id ); | |
| 53 | + $this->block['attrs']['frontCardBackground']['imgIdH'] = $attachment_id; | |
| 54 | + $this->block['attrs']['frontCardBackground']['imgUrlH'] = $attachment_url; | |
| 55 | + } | |
| 56 | + } | |
| 57 | +} | |