Skip to content

Commit 4e300ae

Browse files
committed
Added adapter to fix marca.com videos
1 parent 5e4ca41 commit 4e300ae

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Embed/Adapters/Marca.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Adapter to fix the embed code from marca.com
4+
*/
5+
namespace Embed\Adapters;
6+
7+
use Embed\Url;
8+
use Embed\Viewers;
9+
10+
class Marca extends Webpage implements AdapterInterface {
11+
12+
static public function check (Url $Url) {
13+
return $Url->match(array(
14+
'http://www.marca.com/*'
15+
));
16+
}
17+
18+
public function getCode () {
19+
if (($code = parent::getCode())) {
20+
$errors = libxml_use_internal_errors(true);
21+
$html = new \DOMDocument();
22+
$result = $html->loadHtml($code);
23+
libxml_use_internal_errors($errors);
24+
25+
if ($result) {
26+
$startValue = 'http://cachevideos.marca.com/multimedia/reproductores/v2/reproductor_video.swf';
27+
$startValueLength = strlen($startValue);
28+
29+
foreach ($html->getElementsByTagName('param') as $param) {
30+
if ($param->getAttribute('name') === 'movie') {
31+
$value = $param->getAttribute('value');
32+
33+
if (substr($value, 0, $startValueLength) === $startValue) {
34+
$value = substr($value, $startValueLength);
35+
}
36+
37+
return Viewers::videoHtml($this->getImage(), $value);
38+
}
39+
}
40+
}
41+
}
42+
43+
return $code;
44+
}
45+
}

0 commit comments

Comments
 (0)