Fader.php
| 1 | <?php |
| 2 | /** |
| 3 | * Fader.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 | * Fader Provider |
| 19 | * @link https://app.getfader.com |
| 20 | */ |
| 21 | class Fader extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $endpoint = 'https://app.getfader.com/api/oembed?format=json'; |
| 25 | |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected static $hosts = [ |
| 28 | 'app.getfader.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('~app\.getfader\.com/projects/([^/]+)/publish/?$~i', (string) $url)); |
| 38 | } |
| 39 | |
| 40 | /** inline {@inheritdoc} */ |
| 41 | public function normalizeUrl(Url $url) |
| 42 | { |
| 43 | $url->convertToHttps(); |
| 44 | $url->removeQueryString(); |
| 45 | $url->removeLastSlash(); |
| 46 | |
| 47 | return $url; |
| 48 | } |
| 49 | |
| 50 | /** inline {@inheritdoc} */ |
| 51 | public function getFakeResponse() |
| 52 | { |
| 53 | $embedUrl = $this->url; |
| 54 | // <iframe allowfullscreen="allowfullscreen" allowvr="allowvr" width=1200 height=600 src="https://app.getfader.com/projects/89a73dd0-4926-4f05-a9a8-6896a0a07a71/publish"></iframe> |
| 55 | |
| 56 | $attr = []; |
| 57 | $attr[] = 'allowfullscreen="allowfullscreen"'; |
| 58 | $attr[] = 'allowvr="allowvr"'; |
| 59 | $attr[] = 'width="{width}"'; |
| 60 | $attr[] = 'height="{height}"'; |
| 61 | $attr[] = 'src="' . $embedUrl . '"'; |
| 62 | |
| 63 | return [ |
| 64 | 'type' => 'rich', |
| 65 | 'provider_name' => 'Fader', |
| 66 | 'provider_url' => 'https://app.getfader.com', |
| 67 | 'title' => 'Unknown title', |
| 68 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe>', |
| 69 | ]; |
| 70 | } |
| 71 | |
| 72 | } |
| 73 |