| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\import\ImageParsers\ablocks; |
| 4 |
|
| 5 |
use ABlocks\import\ImageParsers\AbstractImageParser; |
| 6 |
|
| 7 |
class ModalParser 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']['panelBackground'] ) || 'image' !== $this->block['attrs']['panelBackground']['backgroundType'] ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
$imgUrl = $this->block['attrs']['panelBackground']['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']['panelBackground']['imgId'] = $attachment_id; |
| 32 |
$this->block['attrs']['panelBackground']['imgUrl'] = $attachment_url; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
private function parse_background_hover() { |
| 37 |
if ( ! isset( $this->block['attrs']['panelBackground'] ) || 'image' !== $this->block['attrs']['panelBackground']['backgroundTypeH'] ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
$imgUrl = $this->block['attrs']['panelBackground']['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']['panelBackground']['imgIdH'] = $attachment_id; |
| 54 |
$this->block['attrs']['panelBackground']['imgUrlH'] = $attachment_url; |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|