Skip to content

Commit 4f1693d

Browse files
committed
Merge pull request #69 from daveross/feature/wordpress-tv
Feature/wordpress tv
2 parents 067f14c + b470f48 commit 4f1693d

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

src/Providers/OEmbed.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function run()
2424
$endPoint = null;
2525
$params = $this->config['parameters'];
2626

27-
if (!($html = $this->request->getHtmlContent()) || !($endPoint = self::getEndPointFromDom($html))) {
27+
if (self::providerEmbedInDomIsBroken($this->request) || (!($html = $this->request->getHtmlContent()) || !($endPoint = self::getEndPointFromDom($html)))) {
2828
if (($info = self::getEndPointFromRequest($this->request, $this->config))) {
2929
$endPoint = $info['endPoint'];
3030
$params += $info['params'];
@@ -235,7 +235,7 @@ protected static function getEndPointFromDom(\DOMDocument $html)
235235
protected static function getEndPointFromRequest(Request $request, array $config)
236236
{
237237
//Search the oembed provider using the domain
238-
$class = 'Embed\\Providers\\OEmbed\\'.str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $request->getDomain()))));
238+
$class = self::getClassFromRequest($request);
239239

240240
if (class_exists($class) && $request->match($class::getPatterns())) {
241241
return [
@@ -252,4 +252,30 @@ protected static function getEndPointFromRequest(Request $request, array $config
252252
];
253253
}
254254
}
255+
256+
/**
257+
* Return the class name implementing an oEmbed provider
258+
* @param Request $request
259+
*
260+
* @return string
261+
*/
262+
protected static function getClassFromRequest(Request $request) {
263+
return 'Embed\\Providers\\OEmbed\\'.str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $request->getDomain()))));
264+
}
265+
266+
/**
267+
* @param Request $request
268+
*
269+
* @return bool
270+
*/
271+
protected static function providerEmbedInDomIsBroken(Request $request) {
272+
$class = self::getClassFromRequest( $request );
273+
274+
if ( class_exists( $class ) && $request->match( $class::getPatterns() ) ) {
275+
return $class::embedInDomIsBroken();
276+
}
277+
278+
// Fall-through default in case this called for an invalid class
279+
return false;
280+
}
255281
}

src/Providers/OEmbed/OEmbedImplementation.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,14 @@ public static function getParams(Url $url)
3939
{
4040
return [];
4141
}
42+
43+
/**
44+
* @access public
45+
* @author Dave Ross
46+
* @return bool
47+
*/
48+
public static function embedInDomIsBroken()
49+
{
50+
return false;
51+
}
4252
}

src/Providers/OEmbed/WordPress.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Embed\Providers\OEmbed;
3+
4+
/**
5+
* Class WordPress
6+
* WordPress.tv embeds
7+
* @package Embed\Providers\OEmbed
8+
* @todo Class is named 'WordPress' to fit existing naming scheme, but could be confused with WordPress.com or WordPress.org
9+
*/
10+
class WordPress extends OEmbedImplementation
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public static function getEndPoint()
16+
{
17+
return 'https://wordpress.tv/oembed';
18+
}
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
public static function getPatterns()
24+
{
25+
return ['https?://wordpress.tv/*'];
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public static function embedInDomIsBroken()
32+
{
33+
return true;
34+
}
35+
}

tests/WordPressTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
class WordPressTest extends PHPUnit_Framework_TestCase
3+
{
4+
public function testOne()
5+
{
6+
$info = Embed\Embed::create('http://wordpress.tv/2013/09/06/dave-ross-optimize-image-files-like-a-pro/');
7+
8+
$this->assertEquals($info->title, 'Dave Ross: Optimize Image Files Like a Pro');
9+
$this->assertEquals($info->imageWidth, 400);
10+
$this->assertEquals($info->imageHeight, 224);
11+
$this->assertEquals($info->type, 'video');
12+
$this->assertEquals($info->authorName, '@WordPressTV');
13+
$this->assertEquals($info->providerName, 'WordPress.tv');
14+
$this->assertEquals($info->providerUrl, 'http://wordpress.tv');
15+
}
16+
}

0 commit comments

Comments
 (0)