|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Scribd.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 scribd.com Provider |
|
17
|
|
|
* @link http://scribd.com |
|
18
|
|
|
*/ |
|
19
|
|
|
class Scribd extends \Embera\Adapters\Service |
|
20
|
|
|
{ |
|
21
|
|
|
/** inline {@inheritdoc} */ |
|
22
|
|
|
protected $apiUrl = 'http://www.scribd.com/services/oembed/?format=json'; |
|
23
|
|
|
|
|
24
|
|
|
/** inline {@inheritdoc} */ |
|
25
|
2 |
|
protected function validateUrl() |
|
26
|
|
|
{ |
|
27
|
2 |
|
$this->url->stripQueryString(); |
|
28
|
|
|
|
|
29
|
2 |
|
return (preg_match('~scribd\.com/(doc|document)/(?:[0-9]+)/(?:[^/]+)/?$~i', $this->url)); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** inline {@inheritdoc} */ |
|
33
|
2 |
|
protected function modifyResponse(array $response = array()) |
|
34
|
|
|
{ |
|
35
|
2 |
|
if (!empty($response['html'])) |
|
36
|
2 |
|
{ |
|
37
|
2 |
|
$response['html'] = str_replace('#{root_url}', 'https://www.scribd.com/', $response['html']); |
|
38
|
2 |
|
$response['html'] = preg_replace('~\s+~i', ' ', $response['html']); // Remove double spaces |
|
39
|
2 |
|
} |
|
40
|
|
|
|
|
41
|
2 |
|
return $response; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** inline {@inheritdoc} */ |
|
45
|
2 |
|
public function fakeResponse() |
|
46
|
|
|
{ |
|
47
|
2 |
|
preg_match('~/(doc|document)/([\d]+)/~i', $this->url, $matches); |
|
48
|
|
|
|
|
49
|
|
|
return array( |
|
50
|
2 |
|
'type' => 'rich', |
|
51
|
2 |
|
'provider_name' => 'Scribd', |
|
52
|
2 |
|
'provider_url' => 'https://www.scribd.com', |
|
53
|
2 |
|
'html' => '<iframe class="scribd_iframe_embed" data-aspect-ratio="" frameborder="0" height="{height}" id="' . $matches['1'] . '" scrolling="no" src="https://www.scribd.com/embeds/' . $matches['1'] . '/content" width="100%"></iframe><script type="text/javascript">(function() { var scribd = document.createElement("script"); scribd.type = "text/javascript"; scribd.async = true; scribd.src = "http://www.scribd.com/javascripts/embed_code/inject.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(scribd, s); })();</script>', |
|
54
|
2 |
|
); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|