Scribd.php
| 1 | <?php |
| 2 | /** |
| 3 | * Scribd.php |
| 4 | * |
| 5 | * @package Embera |
| 6 | * @author Michael Pratt <yo@michael-pratt.com> |
| 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\Provider; |
| 14 | |
| 15 | use Embera\Url; |
| 16 | |
| 17 | /** |
| 18 | * Scribd Provider |
| 19 | * @link https://scribd.com |
| 20 | */ |
| 21 | class Scribd extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $endpoint = 'https://www.scribd.com/services/oembed/?format=json'; |
| 25 | |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected static $hosts = [ |
| 28 | 'scribd.com' |
| 29 | ]; |
| 30 | |
| 31 | /** inline {@inheritdoc} */ |
| 32 | protected $httpsSupport = true; |
| 33 | |
| 34 | /** inline {@inheritdoc} */ |
| 35 | protected $responsiveSupport = true; |
| 36 | |
| 37 | /** inline {@inheritdoc} */ |
| 38 | public function validateUrl(Url $url) |
| 39 | { |
| 40 | return (bool) (preg_match('~scribd\.com/(doc|document)/([0-9]+)/([^/]+)~i', (string) $url)); |
| 41 | } |
| 42 | |
| 43 | /** inline {@inheritdoc} */ |
| 44 | public function normalizeUrl(Url $url) |
| 45 | { |
| 46 | $url->convertToHttps(); |
| 47 | $url->removeQueryString(); |
| 48 | $url->removeLastSlash(); |
| 49 | |
| 50 | return $url; |
| 51 | } |
| 52 | |
| 53 | /** inline {@inheritdoc} */ |
| 54 | public function getFakeResponse() |
| 55 | { |
| 56 | preg_match('~/(doc|document)/([\d]+)/~i', (string) $this->url, $matches); |
| 57 | |
| 58 | $embedUrl = 'https://www.scribd.com/embeds/' . $matches['1'] . '/content'; |
| 59 | |
| 60 | $attr = []; |
| 61 | $attr[] = 'class="scribd_iframe_embed"'; |
| 62 | $attr[] = 'src="' . $embedUrl . '"'; |
| 63 | $attr[] = 'data-aspect-ratio=""'; |
| 64 | $attr[] = 'scrolling="no"'; |
| 65 | $attr[] = 'id="' . $matches['1'] . '"'; |
| 66 | $attr[] = 'width="100%"'; |
| 67 | $attr[] = 'height="{height}"'; |
| 68 | $attr[] = 'frameborder="0"'; |
| 69 | |
| 70 | return [ |
| 71 | 'type' => 'rich', |
| 72 | 'provider_name' => 'Scribd', |
| 73 | 'provider_url' => 'https://scribd.com', |
| 74 | 'title' => 'Unknown title', |
| 75 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe><script type="text/javascript"> (function() { var scribd = document.createElement("script"); scribd.type = "text/javascript"; scribd.async = true; scribd.src = "https://www.scribd.com/javascripts/embed_code/inject.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(scribd, s); })() </script>', |
| 76 | ]; |
| 77 | } |
| 78 | |
| 79 | } |
| 80 |