Skip to content

Commit ef6c3cb

Browse files
committed
Merge pull request #93 from zyuhel/master
Adding partial 500px support
2 parents 38c4bf1 + 66f8fcb commit ef6c3cb

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

src/Adapters/N500px.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* Adapter to provide all information from any webpage.
5+
*/
6+
namespace Embed\Adapters;
7+
8+
use Embed\Request;
9+
use Embed\Providers;
10+
use Embed\Utils;
11+
12+
class N500px extends Adapter implements AdapterInterface
13+
{
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public static function check(Request $request)
19+
{
20+
return $request->isValid() && $request->match([
21+
'https?://500px.com/photo/*',
22+
]);;
23+
}
24+
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getCode()
30+
{
31+
if (is_numeric($this->request->getDirectoryPosition(1))) {
32+
return Utils::iframe($this->request->createUrl()->withDirectoryPosition(2,'embed.html'), $this->width, $this->height);
33+
}
34+
35+
return '';
36+
}
37+
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public function run()
43+
{
44+
//order is important
45+
$this->addProvider('oembed', new Providers\OEmbed());
46+
$this->addProvider('opengraph', new Providers\OpenGraph());
47+
echo $this->request->getUrl();
48+
}
49+
}

src/Providers/OEmbed/N500px.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Embed\Providers\OEmbed;
4+
use Embed\Url;
5+
6+
/**
7+
* Class N500px
8+
* 500px.com embeds.
9+
*/
10+
class N500px extends OEmbedImplementation
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public static function getEndPoint(Url $url)
16+
{
17+
18+
if (is_numeric($url->getDirectoryPosition(1))) {
19+
return $url->createUrl()->withDirectoryPosition(2,'oembed.json');
20+
}
21+
return '';
22+
}
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public static function getPatterns()
28+
{
29+
return ['https?://500px.com/photo/*'];
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public static function embedInDomIsBroken()
36+
{
37+
return true;
38+
}
39+
}

tests/N500Test.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
class N500Test extends TestCaseBase
4+
{
5+
public function testPhoto()
6+
{
7+
$this->assertEmbed(
8+
'https://500px.com/photo/127505793/nude-girl-retro-by-david-dubnitskiy',
9+
[
10+
'imageWidth' => 280,
11+
'image'=>'https://drscdn.500px.org/photo/127505793/w%3D280_h%3D280/c415195ae6156c9ba2a3db37130c22be?v=2',
12+
'imageHeight' => 280,
13+
'authorName' => 'David Dubnitskiy',
14+
'type' => 'photo',
15+
]
16+
);
17+
}
18+
}

0 commit comments

Comments
 (0)