Skip to content

Commit 71a3535

Browse files
authored
Merge pull request #120 from aaronpk/issue-114
parse poster attribute for video tags
2 parents 26e4ed4 + 9fb3c21 commit 71a3535

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Mf2/Parser.php

+2
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,8 @@ public function parseU(\DOMElement $u) {
615615
$uValue = $u->getAttribute('href');
616616
} elseif (in_array($u->tagName, array('img', 'audio', 'video', 'source')) and $u->hasAttribute('src')) {
617617
$uValue = $u->getAttribute('src');
618+
} elseif ($u->tagName == 'video' and !$u->hasAttribute('src') and $u->hasAttribute('poster')) {
619+
$uValue = $u->getAttribute('poster');
618620
} elseif ($u->tagName == 'object' and $u->hasAttribute('data')) {
619621
$uValue = $u->getAttribute('data');
620622
}

tests/Mf2/ParseUTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ public function testParseUHandlesSource() {
222222
$this->assertEquals('http://example.com/video.ogg', $output['items'][0]['properties']['video'][1]);
223223
}
224224

225+
/**
226+
* @group parseU
227+
*/
228+
public function testParseUHandlesVideoPoster() {
229+
$input = '<div class="h-entry"><video class="u-photo" poster="http://example.com/posterimage.jpg"><source class="u-video" src="http://example.com/video.mp4" type="video/mp4"></video></div>';
230+
$parser = new Parser($input);
231+
$output = $parser->parse();
232+
233+
$this->assertArrayHasKey('video', $output['items'][0]['properties']);
234+
$this->assertEquals('http://example.com/video.mp4', $output['items'][0]['properties']['video'][0]);
235+
$this->assertEquals('http://example.com/posterimage.jpg', $output['items'][0]['properties']['photo'][0]);
236+
}
237+
225238
/**
226239
* @group parseU
227240
*/

0 commit comments

Comments
 (0)