Skip to content

Commit

Permalink
Add url() method
Browse files Browse the repository at this point in the history
  • Loading branch information
jcisio committed Nov 8, 2017
1 parent a67b6bf commit 341d34f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 9 deletions.
4 changes: 2 additions & 2 deletions MediaWrapper/Wrapper/Dailymotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function thumbnail($absolute = TRUE) {
/**
* {@inheritdoc}
*/
public function title() {
return '';
public function url() {
return 'https://www.dailymotion.com/video/' . $this->info['id'];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions MediaWrapper/Wrapper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function thumbnail($absolute = TRUE) {
/**
* {@inheritdoc}
*/
public function title() {
return '';
public function url() {
return 'https://instagram.com/p/' . $this->info['id'];
}

/**
Expand Down
6 changes: 3 additions & 3 deletions MediaWrapper/Wrapper/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Twitter extends Wrapper {
*/
public function __construct($text) {
self::$patterns = array(
'#https?://twitter\.com/[a-zA-Z0-9_]+/status/(?<id>\d+)#',
'#https?://twitter\.com/(?<screenname>[a-zA-Z0-9_]+)/status/(?<id>\d+)#',
);

$this->options += array(
Expand All @@ -50,8 +50,8 @@ public function thumbnail($absolute = TRUE) {
/**
* {@inheritdoc}
*/
public function title() {
return '';
public function url() {
return 'https://twitter.com/' . $this->info['screenname'] . '/status/' . $this->info['id'];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions MediaWrapper/Wrapper/Vimeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function thumbnail($absolute = TRUE) {
/**
* {@inheritdoc}
*/
public function title() {
return '';
public function url() {
return 'https://vimeo.com/' . $this->info['id'];
}

/**
Expand Down
20 changes: 20 additions & 0 deletions MediaWrapper/Wrapper/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ function __construct($text) {
if (preg_match($pattern, $text, $match)) {
$id = isset($match['id']) ? $match['id'] : $match[1];
$this->info = array('id' => $id);
// Save all named matches into the info variable.
foreach ($match as $key => $value) {
if (!is_numeric($key)) {
$this->info[$key] = $value;
}
}
break;
}
}
Expand Down Expand Up @@ -71,6 +77,20 @@ public function player_options(array $options, $set = TRUE) {
return $options;
}

/**
* {@inheritdoc}
*/
public function url() {
return '';
}

/**
* {@inheritdoc}
*/
public function title() {
return '';
}

/**
* Set API keys.
*/
Expand Down
7 changes: 7 additions & 0 deletions MediaWrapper/Wrapper/WrapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public function thumbnail($absolute = TRUE);
*/
public function title();

/**
* Returns url to the media.
*
* @return string
*/
public function url();

/**
* Renders an embedded player.
*
Expand Down
7 changes: 7 additions & 0 deletions MediaWrapper/Wrapper/Youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ public function title() {
return '';
}

/**
* {@inheritdoc}
*/
public function url() {
return 'https://www.youtube.com/watch?v=' . $this->info['id'];
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 4 additions & 0 deletions Tests/MediaWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function testYoutube() {

$m = MediaWrapper::getInstance()->getWrapper('http://www.youtube.com/watch?v=9bZkp7q19f0');
$this->assertEquals('http://img.youtube.com/vi/9bZkp7q19f0/maxresdefault.jpg', $m->thumbnail());
$this->assertEquals('https://www.youtube.com/watch?v=9bZkp7q19f0', $m->url());
$this->assertEquals('//img.youtube.com/vi/9bZkp7q19f0/maxresdefault.jpg', $m->thumbnail(FALSE));
$this->assertImageUrl($m->thumbnail());
$this->assertEquals('<iframe class="youtube-player" type="text/html" width="560" height="315" src="//www.youtube.com/embed/9bZkp7q19f0?wmode=transparent" frameborder="0"></iframe>', $m->player());
Expand Down Expand Up @@ -60,6 +61,7 @@ public function testYoutubeSpecial() {
public function testDailymotion() {
$m = MediaWrapper::getInstance()->getWrapper('http://www.dailymotion.com/video/x1mun8');
$this->assertEquals('x1mun8', $m->getInfo('id'));
$this->assertEquals('https://www.dailymotion.com/video/x1mun8', $m->url());

$m = MediaWrapper::getInstance()->getWrapper('http://www.dailymotion.com/video/6pU29dPYNlqCLbwiw');
$this->assertInstanceOf('MediaWrapper\Wrapper\Dailymotion', $m);
Expand All @@ -77,13 +79,15 @@ public function testVimeo() {
$m = MediaWrapper::getInstance()->getWrapper('http://vimeo.com/56488043');
$this->assertImageUrl($m->thumbnail());
$this->assertEquals('http://i.vimeocdn.com/video/515444387_640.jpg', $m->thumbnail());
$this->assertEquals('https://vimeo.com/56488043', $m->url());
$this->assertEquals('//i.vimeocdn.com/video/515444387_640.jpg', $m->thumbnail(FALSE));
$this->assertEquals('<iframe class="vimeo-player" type="text/html" width="560" height="315" src="//player.vimeo.com/video/56488043?byline=0&portrait=0" frameborder="0"></iframe>', $m->player());
}

public function testInstagram() {
$m = MediaWrapper::getInstance()->getWrapper('http://instagram.com/p/Batz8EDlmR8');
$this->assertImageUrl($m->thumbnail());
$this->assertEquals('https://instagram.com/p/Batz8EDlmR8', $m->url());
$this->assertContains('class="instagram-media"', $m->player());
}

Expand Down

0 comments on commit 341d34f

Please sign in to comment.