← All changes
|
includes/import/image-parsers/ablocks/image-comparison-parser.php
+27
-0
2.7.4
→
2.14.0
View file →
| @@ -1,0 +1,27 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace ABlocks\import\ImageParsers\ablocks; | |
| 4 | + | |
| 5 | +use ABlocks\import\ImageParsers\AbstractImageParser; | |
| 6 | +use DOMDocument; | |
| 7 | + | |
| 8 | +class ImageComparisonParser extends AbstractImageParser { | |
| 9 | + | |
| 10 | + protected function parse() { | |
| 11 | + $dom = new DOMDocument(); | |
| 12 | + $dom->loadHTML( $this->block['innerHTML'], LIBXML_NOERROR | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD ); | |
| 13 | + | |
| 14 | + $before_parsed_img = $this->parse_img_tag( $dom, 0 ); | |
| 15 | + $after_parsed_img = $this->parse_img_tag( $dom, 1 ); | |
| 16 | + if ( ! $before_parsed_img || ! $after_parsed_img ) { | |
| 17 | + return; | |
| 18 | + } | |
| 19 | + list( , $before_attachment_url, $before_image_url ) = $before_parsed_img; | |
| 20 | + list( , $after_attachment_url, $after_image_url ) = $after_parsed_img; | |
| 21 | + | |
| 22 | + $this->block['attrs']['beforeImage'] = $before_attachment_url; | |
| 23 | + $this->block['attrs']['afterImage'] = $after_attachment_url; | |
| 24 | + $this->block['innerHTML'] = str_replace( [ $before_image_url, $after_image_url ], [ $before_attachment_url, $after_attachment_url ], $this->block['innerHTML'] ); | |
| 25 | + $this->block['innerContent'] = array_map( fn( $content) => str_replace( [ $before_image_url, $after_image_url ], [ $before_attachment_url, $after_attachment_url ], $content ), $this->block['innerContent'] ); | |
| 26 | + } | |
| 27 | +} | |