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 Provider |
| 20 | * Record and share video messages of your screen, cam, or both. Faster than typing an email or me... |
| 21 | * |
| 22 | * @link https://www.loom.com |
| 23 | * |
| 24 | */ |
| 25 | class Loom extends ProviderAdapter implements ProviderInterface |
| 26 | { |
| 27 | /** inline {@inheritDoc} */ |
| 28 | protected $endpoint = 'https://www.loom.com/v1/oembed/'; |
| 29 | |
| 30 | /** inline {@inheritDoc} */ |
| 31 | protected static $hosts = [ |
| 32 | 'loom.com', 'www.loom.com', |
| 33 | ]; |
| 34 | |
| 35 | /** inline {@inheritdoc} */ |
| 36 | protected $allowedParams = [ 'maxwidth', 'maxheight' ]; |
| 37 | |
| 38 | /** inline {@inheritdoc} */ |
| 39 | protected $httpsSupport = true; |
| 40 | |
| 41 | /** inline {@inheritdoc} */ |
| 42 | protected $responsiveSupport = false; |
| 43 | |
| 44 | /** inline {@inheritDoc} */ |
| 45 | public function validateUrl(Url $url) |
| 46 | { |
| 47 | return (bool) preg_match('~loom.com\/[share|embed]+\/([a-z0-9]+)~i', (string) $this->url); |
| 48 | } |
| 49 | |
| 50 | /** inline {@inheritDoc} */ |
| 51 | public function normalizeUrl(Url $url) |
| 52 | { |
| 53 | if (preg_match('~loom.com\/embed\/([a-z0-9]+)~i', (string) $url, $matches)) { |
| 54 | $url->overwrite('https://www.loom.com/share/' . $matches[1]); |
| 55 | } |
| 56 | |
| 57 | return $url; |
| 58 | } |
| 59 | |
| 60 | public function getFakeResponse() |
| 61 | { |
| 62 | preg_match('~loom.com\/share\/([a-z0-9]+)~i', (string) $this->url, $matches); |
| 63 | $id = $matches[1]; |
| 64 | |
| 65 | $embedUrl = 'https://www.loom.com/embed/'.$id; |
| 66 | |
| 67 | $attr = [ |
| 68 | 'src="'.$embedUrl.'"', |
| 69 | 'frameborder="0"', |
| 70 | 'width="{width}"', |
| 71 | 'height="{height}"', |
| 72 | 'webkitallowfullscreen', |
| 73 | 'mozallowfullscreen', |
| 74 | 'allowfullscreen', |
| 75 | ]; |
| 76 | |
| 77 | return [ |
| 78 | 'type' => 'video', |
| 79 | 'version' => '1.0', |
| 80 | 'html' => '<iframe '.implode(' ', $attr).'></iframe>', |
| 81 | 'title' => 'Untitled Video', |
| 82 | 'height' => 960, |
| 83 | 'width' => 1280, |
| 84 | 'provider_name' => 'Loom', |
| 85 | 'provider_url' => 'https://www.loom.com', |
| 86 | 'thumbnail_height' => 960, |
| 87 | 'thumbnail_width' => 1280, |
| 88 | 'thumbnail_url' => 'https://cdn.loom.com/sessions/thumbnails/'.$id.'-00001.png', |
| 89 | 'duration' => 0, |
| 90 | ]; |
| 91 | } |
| 92 | } |
| 93 |