VoxSnap.php
| 1 | <?php |
| 2 | /** |
| 3 | * VoxSnap.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 | * VoxSnap Provider |
| 19 | * Let your content be heard! Create audio blogs, podcasts, Amazon Alexa or Google Home content, a... |
| 20 | * |
| 21 | * @link https://voxsnap.com |
| 22 | * |
| 23 | */ |
| 24 | class VoxSnap extends ProviderAdapter implements ProviderInterface |
| 25 | { |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected $endpoint = 'https://data.voxsnap.com/oembed?format=json'; |
| 28 | |
| 29 | /** inline {@inheritdoc} */ |
| 30 | protected static $hosts = [ |
| 31 | 'article.voxsnap.com' |
| 32 | ]; |
| 33 | |
| 34 | /** inline {@inheritdoc} */ |
| 35 | protected $httpsSupport = true; |
| 36 | |
| 37 | /** inline {@inheritdoc} */ |
| 38 | public function validateUrl(Url $url) |
| 39 | { |
| 40 | return (bool) (preg_match('~voxsnap\.com/([^/]+)/([^/]+)~i', (string) $url)); |
| 41 | } |
| 42 | |
| 43 | /** inline {@inheritdoc} */ |
| 44 | public function normalizeUrl(Url $url) |
| 45 | { |
| 46 | $url->convertToHttps(); |
| 47 | $url->removeQueryString(); |
| 48 | $url->removeLastSlash(); |
| 49 | |
| 50 | return $url; |
| 51 | } |
| 52 | |
| 53 | /** inline {@inheritdoc} */ |
| 54 | public function getFakeResponse() |
| 55 | { |
| 56 | preg_match('~voxsnap\.com/([^/]+)/([^/]+)~i', (string) $this->url, $matches); |
| 57 | |
| 58 | $embedUrl = 'https://player.voxsnap.com/oembed/' . $matches['1'] . '/' . $matches['2']; |
| 59 | |
| 60 | $attr = []; |
| 61 | $attr[] = 'height="{height}"'; |
| 62 | $attr[] = 'width="{width}"'; |
| 63 | $attr[] = 'frameborder="0"'; |
| 64 | $attr[] = 'src="' . $embedUrl . '"'; |
| 65 | |
| 66 | return [ |
| 67 | 'type' => 'rich', |
| 68 | 'provider_name' => 'VoxSnap', |
| 69 | 'provider_url' => 'https://article.voxsnap.com', |
| 70 | 'title' => 'Unknown title', |
| 71 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe>', |
| 72 | ]; |
| 73 | } |
| 74 | |
| 75 | } |
| 76 |