Ted.php
| 1 | <?php |
| 2 | /** |
| 3 | * Ted.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 | * Ted Provider |
| 19 | * @link https://ted.com |
| 20 | */ |
| 21 | class Ted extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $endpoint = 'https://www.ted.com/services/v1/oembed.json'; |
| 25 | |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected static $hosts = [ |
| 28 | 'ted.com' |
| 29 | ]; |
| 30 | |
| 31 | /** inline {@inheritdoc} */ |
| 32 | protected $httpsSupport = true; |
| 33 | |
| 34 | /** inline {@inheritdoc} */ |
| 35 | public function validateUrl(Url $url) |
| 36 | { |
| 37 | return (bool) (preg_match('~ted\.com/talks/([^/]+)~i', (string) $url)); |
| 38 | } |
| 39 | |
| 40 | /** inline {@inheritdoc} */ |
| 41 | public function normalizeUrl(Url $url) |
| 42 | { |
| 43 | $url->convertToHttps(); |
| 44 | $url->removeWWW(); |
| 45 | $url->removeQueryString(); |
| 46 | $url->removeLastSlash(); |
| 47 | |
| 48 | return $url; |
| 49 | } |
| 50 | |
| 51 | /** inline {@inheritdoc} */ |
| 52 | public function getFakeResponse() |
| 53 | { |
| 54 | $this->url->setHost('embed.ted.com'); |
| 55 | |
| 56 | $attr = []; |
| 57 | $attr[] = 'src="' . (string) $this->url . '"'; |
| 58 | $attr[] = 'width="{width}"'; |
| 59 | $attr[] = 'height="{height}"'; |
| 60 | $attr[] = 'frameborder="0"'; |
| 61 | $attr[] = 'scrolling="no"'; |
| 62 | $attr[] = 'webkitAllowFullScreen mozallowfullscreen allowFullScreen'; |
| 63 | |
| 64 | return [ |
| 65 | 'type' => 'video', |
| 66 | 'provider_name' => 'Ted', |
| 67 | 'provider_url' => 'https://ted.com', |
| 68 | 'title' => 'Unknown title', |
| 69 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe>', |
| 70 | ]; |
| 71 | } |
| 72 | |
| 73 | } |
| 74 |