Loom.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Loom.php |
| 5 | * |
| 6 | * @package Embera |
| 7 | * @author Andrew Minion |
| 8 | * @link https://andrewrminion.com/ |
| 9 | * |
| 10 | * For the full copyright and license information, please view the LICENSE |
| 11 | * file that was distributed with this source code. |
| 12 | */ |
| 13 | |
| 14 | namespace Embera\Provider; |
| 15 | |
| 16 | use Embera\Url; |
| 17 | |
| 18 | /** |
| 19 | * loom.com Provider |
| 20 | * @link https://www.loom.com |
| 21 | */ |
| 22 | class Loom extends ProviderAdapter implements ProviderInterface |
| 23 | { |
| 24 | /** inline {@inheritDoc} */ |
| 25 | protected $endpoint = 'https://www.loom.com/v1/oembed/'; |
| 26 | |
| 27 | /** inline {@inheritDoc} */ |
| 28 | protected static $hosts = [ |
| 29 | 'loom.com', 'www.loom.com', |
| 30 | ]; |
| 31 | |
| 32 | /** inline {@inheritdoc} */ |
| 33 | protected $allowedParams = [ 'maxwidth', 'maxheight' ]; |
| 34 | |
| 35 | /** inline {@inheritdoc} */ |
| 36 | protected $httpsSupport = true; |
| 37 | |
| 38 | /** inline {@inheritdoc} */ |
| 39 | protected $responsiveSupport = false; |
| 40 | |
| 41 | /** inline {@inheritDoc} */ |
| 42 | public function validateUrl(Url $url) |
| 43 | { |
| 44 | return (bool) preg_match('~loom.com\/[share|embed]+\/([a-z0-9]+)~i', (string) $this->url); |
| 45 | } |
| 46 | |
| 47 | /** inline {@inheritDoc} */ |
| 48 | public function normalizeUrl(Url $url) |
| 49 | { |
| 50 | if (preg_match('~loom.com\/embed\/([a-z0-9]+)~i', (string) $url, $matches)) { |
| 51 | $url->overwrite('https://www.loom.com/share/' . $matches[1]); |
| 52 | } |
| 53 | |
| 54 | return $url; |
| 55 | } |
| 56 | |
| 57 | public function getFakeResponse() |
| 58 | { |
| 59 | preg_match('~loom.com\/share\/([a-z0-9]+)~i', (string) $this->url, $matches); |
| 60 | $id = $matches[1]; |
| 61 | |
| 62 | $embedUrl = 'https://www.loom.com/embed/'.$id; |
| 63 | |
| 64 | $attr = [ |
| 65 | 'src="'.$embedUrl.'"', |
| 66 | 'frameborder="0"', |
| 67 | 'width="{width}"', |
| 68 | 'height="{height}"', |
| 69 | 'webkitallowfullscreen', |
| 70 | 'mozallowfullscreen', |
| 71 | 'allowfullscreen', |
| 72 | ]; |
| 73 | |
| 74 | return [ |
| 75 | 'type' => 'video', |
| 76 | 'version' => '1.0', |
| 77 | 'html' => '<iframe '.implode(' ', $attr).'></iframe>', |
| 78 | 'title' => 'Untitled Video', |
| 79 | 'height' => 960, |
| 80 | 'width' => 1280, |
| 81 | 'provider_name' => 'Loom', |
| 82 | 'provider_url' => 'https://www.loom.com', |
| 83 | 'thumbnail_height' => 960, |
| 84 | 'thumbnail_width' => 1280, |
| 85 | 'thumbnail_url' => 'https://cdn.loom.com/sessions/thumbnails/'.$id.'-00001.png', |
| 86 | 'duration' => 0, |
| 87 | ]; |
| 88 | } |
| 89 | } |
| 90 |