Altru.php
| 1 | <?php |
| 2 | /** |
| 3 | * Altru.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 | * altrulabs.com Provider |
| 19 | * @link https://altrulabs.com |
| 20 | */ |
| 21 | class Altru extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $endpoint = 'https://api.altrulabs.com/api/v1/social/oembed?format=json'; |
| 25 | |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected static $hosts = [ |
| 28 | 'app.altrulabs.com' |
| 29 | ]; |
| 30 | |
| 31 | /** inline {@inheritdoc} */ |
| 32 | protected $httpsSupport = true; |
| 33 | |
| 34 | /** inline {@inheritdoc} */ |
| 35 | public function validateUrl(Url $url) |
| 36 | { |
| 37 | return (bool) ( |
| 38 | preg_match('~\.com/(?:[^/]+)/(?:[^/]+)/?\?answer_id=(?:[0-9]+)~i', (string) $url) || |
| 39 | preg_match('~\.com/player/([0-9]+)~i', (string) $url) |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | /** inline {@inheritdoc} */ |
| 44 | public function normalizeUrl(Url $url) |
| 45 | { |
| 46 | $url->convertToHttps(); |
| 47 | return $url; |
| 48 | } |
| 49 | |
| 50 | /** inline {@inheritdoc} */ |
| 51 | public function getFakeResponse() |
| 52 | { |
| 53 | if (preg_match('~answer_id=([0-9]+)~i', (string) $this->url, $matches)) { |
| 54 | $embedUrl = 'https://api.altrulabs.com/api/v1/social/embed_player/' . $matches['1']; |
| 55 | } else if (preg_match('~/player/([0-9]+)~i', (string) $this->url, $matches)) { |
| 56 | $embedUrl = 'https://api.altrulabs.com/api/v1/social/embed_player/' . $matches['1']; |
| 57 | } |
| 58 | |
| 59 | $attr = []; |
| 60 | $attr[] = 'width="{width}"'; |
| 61 | $attr[] = 'height="{height}"'; |
| 62 | $attr[] = 'src="' . $embedUrl . '"'; |
| 63 | $attr[] = 'frameborder="0"'; |
| 64 | $attr[] = 'allow="autoplay; encrypted-media"'; |
| 65 | $attr[] = 'allowfullscreen'; |
| 66 | |
| 67 | return [ |
| 68 | 'type' => 'video', |
| 69 | 'provider_name' => 'Altru', |
| 70 | 'provider_url' => 'https://www.altrulabs.com', |
| 71 | 'title' => 'Unknown title', |
| 72 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe>', |
| 73 | ]; |
| 74 | } |
| 75 | |
| 76 | } |
| 77 |