|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* DotSub.php |
|
4
|
|
|
* |
|
5
|
|
|
* @package Providers |
|
6
|
|
|
* @author Michael Pratt <[email protected]> |
|
7
|
|
|
* @link http://www.michael-pratt.com/ |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Embera\Providers; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The dotsub.com Provider |
|
17
|
|
|
* @link http://dotsub.com/ |
|
18
|
|
|
* @link http://dotsub.com/solutions/oEmbed |
|
19
|
|
|
*/ |
|
20
|
|
|
class DotSub extends \Embera\Adapters\Service |
|
21
|
|
|
{ |
|
22
|
|
|
/** inline {@inheritdoc} */ |
|
23
|
|
|
protected $apiUrl = 'http://dotsub.com/services/oembed?format=json'; |
|
24
|
|
|
|
|
25
|
|
|
/** inline {@inheritdoc} */ |
|
26
|
2 |
|
protected function validateUrl() |
|
27
|
|
|
{ |
|
28
|
2 |
|
$this->url->stripQueryString(); |
|
29
|
2 |
|
$this->url->stripLastSlash(); |
|
30
|
|
|
|
|
31
|
2 |
|
return (preg_match('~dotsub\.com/view/(?:[a-f0-9]+)-(?:[a-f0-9]+)-(?:[a-f0-9]+)-(?:[a-f0-9]+)-(?:[a-f0-9]+)$~i', $this->url)); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** inline {@inheritdoc} */ |
|
35
|
2 |
|
protected function normalizeUrl() |
|
36
|
|
|
{ |
|
37
|
2 |
|
if (preg_match('~/(?:media|view)/([0-9a-f\-]+)~i', $this->url, $matches)) |
|
38
|
2 |
|
$this->url = new \Embera\Url('http://dotsub.com/view/' . $matches['1']); |
|
39
|
2 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** inline {@inheritdoc} */ |
|
42
|
2 |
|
public function fakeResponse() |
|
43
|
|
|
{ |
|
44
|
2 |
|
$url = str_replace('/view/', '/media/', $this->url); |
|
45
|
|
|
return array( |
|
46
|
2 |
|
'type' => 'video', |
|
47
|
2 |
|
'provider_name' => 'DotSUB', |
|
48
|
2 |
|
'provider_url' => 'http://dotsub.com', |
|
49
|
2 |
|
'thumbnail_url' => $url . '/t', |
|
50
|
2 |
|
'html' => '<iframe src="' . $url . '/e/c?width={width}&height={height}" frameborder="0" width="{width}" height="{height}"></iframe>', |
|
51
|
2 |
|
); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
?> |
|
|
|
|
|
|
56
|
|
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.