Skip to content

Commit 471b7d8

Browse files
committed
Added snipplr.com support #156
1 parent 10c96b2 commit 471b7d8

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/Adapters/Snipplr.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Embed\Adapters;
4+
5+
use Embed\Request;
6+
use Embed\Utils;
7+
8+
/**
9+
* Adapter to generate embed code from snipplr.com.
10+
*/
11+
class Snipplr extends Webpage implements AdapterInterface
12+
{
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
public static function check(Request $request)
17+
{
18+
return $request->isValid() && $request->match([
19+
'https?://snipplr.com/view/*',
20+
]);
21+
}
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function getCode()
27+
{
28+
$this->width = null;
29+
$this->height = null;
30+
31+
$id = $this->request->getDirectoryPosition(1);
32+
33+
return <<<CODE
34+
<div id="snipplr_embed_{$id}" class="snipplr_embed"><a target_"blank" href="http://snipplr.com/view/{$id}">View this snippet</a> on Snipplr</div><script type="text/javascript" src="http://snipplr.com/js/embed.js"></script><script type="text/javascript" src="http://snipplr.com/json/{$id}"></script>
35+
CODE;
36+
}
37+
}

tests/SnipplrTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
class SnipplrTest extends TestCaseBase
4+
{
5+
public function testOne()
6+
{
7+
$this->assertEmbed(
8+
'http://snipplr.com/view/72914/better-html-5-basic-starter-template',
9+
[
10+
'title' => 'Better HTML 5 basic starter template - HTML - Snipplr Social Snippet Repository',
11+
'type' => 'rich',
12+
'providerName' => 'snipplr',
13+
'providerUrl' => 'http://snipplr.com',
14+
'code' => '<div id="snipplr_embed_72914" class="snipplr_embed"><a target_"blank" href="http://snipplr.com/view/72914">View this snippet</a> on Snipplr</div><script type="text/javascript" src="http://snipplr.com/js/embed.js"></script><script type="text/javascript" src="http://snipplr.com/json/72914"></script>'
15+
]
16+
);
17+
}
18+
}

0 commit comments

Comments
 (0)