OverflowIO.php
| 1 | <?php |
| 2 | /** |
| 3 | * OverflowIO.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 | * OverflowIO Provider |
| 19 | * @link https://overflow.io |
| 20 | */ |
| 21 | class OverflowIO extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $endpoint = 'https://overflow.io/services/oembed?format=json'; |
| 25 | |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected static $hosts = [ |
| 28 | 'overflow.io' |
| 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('~overflow\.io/s/([^/]+)$~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 | /* <iframe width="600" height="800" src="https://overflow.io/embed/9ST7SX" scrolling="no" allowfullscreen style="border: 1px solid #E9EAEC; border-radius: 4px;"></iframe> */ |
| 54 | $embedUrl = str_replace('/s/', '/embed/', $this->url); |
| 55 | |
| 56 | $attr = []; |
| 57 | $attr[] = 'width="{width}"'; |
| 58 | $attr[] = 'height="{height}"'; |
| 59 | $attr[] = 'src="' . $embedUrl . '"'; |
| 60 | $attr[] = 'scrolling="no"'; |
| 61 | $attr[] = 'allowfullscreen'; |
| 62 | $attr[] = 'style="border: 1px solid #E9EAEC; border-radius: 4px;"'; |
| 63 | |
| 64 | return [ |
| 65 | 'type' => 'rich', |
| 66 | 'provider_name' => 'OverflowIO', |
| 67 | 'provider_url' => 'https://overflow.io', |
| 68 | 'title' => 'Unknown title', |
| 69 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe>', |
| 70 | ]; |
| 71 | } |
| 72 | |
| 73 | } |
| 74 |