class-wpml-media-element-parser.php
905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace WPML\Media\Classes;
use WPML\LIB\WP\Attachment;
abstract class WPML_Media_Element_Parser {
private static $getAttachmentsRegex = '/(\S+)\\s*=\\s*["\']?((?:.(?!["\']?\s+(?:\S+)=|[>"\']))+.)["\']?/';
protected $blockText;
public function __construct( $blockText ) {
$this->blockText = $blockText;
}
abstract public function getMediaElements();
abstract public function getMediaSrcFromAttributes( $attrs );
abstract public function validate();
protected function getAttachments( $matches ) {
$attachments = [];
foreach ( $matches[1] as $i => $match ) {
if ( preg_match_all( self::$getAttachmentsRegex, $match, $attribute_matches ) ) {
$attributes = [];
foreach ( $attribute_matches[1] as $k => $key ) {
$attributes[ $key ] = $attribute_matches[2][ $k ];
}
$attachments[ $i ]['attributes'] = $attributes;
}
}
return $attachments;
}
}