Ludus.php
| 1 | <?php |
| 2 | /** |
| 3 | * Ludus.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 | * Ludus Provider |
| 19 | * @link https://app.ludus.one |
| 20 | */ |
| 21 | class Ludus extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $endpoint = 'https://app.ludus.one/oembed?format=json'; |
| 25 | |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected static $hosts = [ |
| 28 | 'app.ludus.one' |
| 29 | ]; |
| 30 | |
| 31 | /** inline {@inheritdoc} */ |
| 32 | protected $allowedParams = [ 'maxwidth', 'maxheight' ]; |
| 33 | |
| 34 | /** inline {@inheritdoc} */ |
| 35 | protected $httpsSupport = true; |
| 36 | |
| 37 | /** inline {@inheritdoc} */ |
| 38 | protected $responsiveSupport = false; |
| 39 | |
| 40 | /** inline {@inheritdoc} */ |
| 41 | public function validateUrl(Url $url) |
| 42 | { |
| 43 | // a4465cd5-ee82-4534-9755-5e658a7cb198 |
| 44 | return (bool) (preg_match('~\.ludus\.one/(\w{8})-((\w{4}-){3})(\w{12})$~i', (string) $url)); |
| 45 | } |
| 46 | |
| 47 | /** inline {@inheritdoc} */ |
| 48 | public function normalizeUrl(Url $url) |
| 49 | { |
| 50 | $url->convertToHttps(); |
| 51 | $url->removeQueryString(); |
| 52 | $url->removeLastSlash(); |
| 53 | |
| 54 | return $url; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /** inline {@inheritdoc} */ |
| 59 | public function getFakeResponse() |
| 60 | { |
| 61 | // <iframe width="960" height="540" src="https://app.ludus.one/fd01598e-5ed7-4edb-8d0e-cf75a36e0a07/full" frameborder="0" allowfullscreen></iframe> |
| 62 | $embedUrl = $this->url . '/full'; |
| 63 | |
| 64 | $attr = []; |
| 65 | $attr[] = 'width="{width}"'; |
| 66 | $attr[] = 'height="{height}"'; |
| 67 | $attr[] = 'src="' . $embedUrl . '"'; |
| 68 | $attr[] = 'frameborder="0"'; |
| 69 | $attr[] = 'allowfullscreen'; |
| 70 | |
| 71 | return [ |
| 72 | 'type' => 'rich', |
| 73 | 'provider_name' => 'Ludus', |
| 74 | 'provider_url' => 'https://app.ludus.one', |
| 75 | 'title' => 'Unknown title', |
| 76 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe>', |
| 77 | ]; |
| 78 | } |
| 79 | |
| 80 | } |
| 81 |