Skip to content

Commit f29633a

Browse files
committed
Added Flickr adapter
1 parent 8614ec5 commit f29633a

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

src/Adapters/Flickr.php

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Adapter provider more information from flickr
4+
*/
5+
namespace Embed\Adapters;
6+
7+
use Embed\Url;
8+
use Embed\Request;
9+
use Embed\Utils;
10+
11+
class Flickr extends Webpage implements AdapterInterface
12+
{
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
public static function check(Request $request)
17+
{
18+
return $request->match([
19+
'https://www.flickr.com/photos/*'
20+
]);
21+
}
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function getCode()
27+
{
28+
$url = new Url($this->request->url->getUrl());
29+
$url->setDirectory(null, 'player');
30+
31+
return Utils::iframe($url->getUrl(), $this->width, $this->height);
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function getWidth()
38+
{
39+
return 640;
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function getHeight()
46+
{
47+
return 425;
48+
}
49+
50+
/**
51+
* {@inheritdoc}
52+
*/
53+
public function getProviderName()
54+
{
55+
return 'Flickr';
56+
}
57+
}

src/Url.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,16 @@ public function getDomain($first_level = false)
150150
/**
151151
* Edit a specific directory in the path of the url
152152
*
153-
* @param int $key The position of the subdirectory (0 based index)
154-
* @param string $value The new value
153+
* @param int|null $key The position of the subdirectory (0 based index). Null to append
154+
* @param string $value The new value
155155
*/
156156
public function setDirectory($key, $value)
157157
{
158-
if ($key > count($this->info['path'])) {
159-
$this->info['path'][] = $this->info['file'];
158+
if (($key === null) || $key > count($this->info['path'])) {
159+
if (isset($this->info['file'])) {
160+
$this->info['path'][] = $this->info['file'];
161+
}
162+
160163
$this->info['file'] = $value;
161164

162165
return;

tests/FlickrTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
class FlickrTest extends PHPUnit_Framework_TestCase
3+
{
4+
public function testSets()
5+
{
6+
$info = Embed\Embed::create('https://www.flickr.com/photos/desescribir/sets/72157650686499888');
7+
8+
$this->assertEquals($info->imageWidth, 640);
9+
$this->assertEquals($info->imageHeight, 425);
10+
$this->assertEquals($info->code, '<iframe src="https://www.flickr.com/photos/desescribir/sets/72157650686499888/player" frameborder="0" allowTransparency="true" style="border:none;overflow:hidden;width:640px;height:425px;"></iframe>');
11+
$this->assertEquals($info->type, 'rich');
12+
}
13+
14+
public function testProfile()
15+
{
16+
$info = Embed\Embed::create('https://www.flickr.com/photos/desescribir');
17+
18+
$this->assertEquals($info->imageWidth, 640);
19+
$this->assertEquals($info->imageHeight, 425);
20+
$this->assertEquals($info->code, '<iframe src="https://www.flickr.com/photos/desescribir/player" frameborder="0" allowTransparency="true" style="border:none;overflow:hidden;width:640px;height:425px;"></iframe>');
21+
$this->assertEquals($info->type, 'rich');
22+
}
23+
}

0 commit comments

Comments
 (0)