Provider.tpl
87 lines
| 1 | <?php |
| 2 | /** |
| 3 | * {provider}.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 | * {provider} Provider |
| 19 | * @link https://{host} |
| 20 | */ |
| 21 | class {provider} extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $endpoint = '{endpoint}'; |
| 25 | |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected static $hosts = [ |
| 28 | '{host}' |
| 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 | return (bool) (preg_match('~{host_escaped}/([^/]+)~i', (string) $url)); |
| 44 | } |
| 45 | |
| 46 | /** inline {@inheritdoc} */ |
| 47 | public function normalizeUrl(Url $url) |
| 48 | { |
| 49 | $url->convertToHttps(); |
| 50 | $url->removeQueryString(); |
| 51 | $url->removeLastSlash(); |
| 52 | |
| 53 | return $url; |
| 54 | } |
| 55 | |
| 56 | /** inline {@inheritdoc} */ |
| 57 | public function modifyResponse(array $response = []) |
| 58 | { |
| 59 | return $response; |
| 60 | } |
| 61 | |
| 62 | /** inline {@inheritdoc} */ |
| 63 | public function getFakeResponse() |
| 64 | { |
| 65 | preg_match('~v=([a-z0-9_\-]+)~i', (string) $this->url, $matches); |
| 66 | |
| 67 | $embedUrl = ''; |
| 68 | |
| 69 | $attr = []; |
| 70 | $attr[] = 'width="{width}"'; |
| 71 | $attr[] = 'height="{height}"'; |
| 72 | $attr[] = 'src="' . $embedUrl . '"'; |
| 73 | $attr[] = 'frameborder="0"'; |
| 74 | $attr[] = 'allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"'; |
| 75 | $attr[] = 'allowfullscreen'; |
| 76 | |
| 77 | return [ |
| 78 | 'type' => '', |
| 79 | 'provider_name' => '{provider}', |
| 80 | 'provider_url' => 'https://{host}', |
| 81 | 'title' => 'Unknown title', |
| 82 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe>', |
| 83 | ]; |
| 84 | } |
| 85 | |
| 86 | } |
| 87 |