Tickcounter.php
| 1 | <?php |
| 2 | /** |
| 3 | * Tickcounter.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 | * Tickcounter Provider |
| 19 | * @link https://tickcounter.com |
| 20 | */ |
| 21 | class Tickcounter extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $endpoint = 'https://www.tickcounter.com/oembed?format=json'; |
| 25 | |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected static $hosts = [ |
| 28 | 'tickcounter.com' |
| 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('~tickcounter\.com/(countdown|countup|ticker|worldclock)/([^/]+)~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 modifyResponse(array $response = []) |
| 52 | { |
| 53 | if (!empty($response['html'])) { |
| 54 | $response['html'] = preg_replace('~title="(.+)"~i', 'title=""', $response['html']); |
| 55 | } |
| 56 | |
| 57 | return $response; |
| 58 | } |
| 59 | |
| 60 | /** inline {@inheritdoc} */ |
| 61 | public function getFakeResponse() |
| 62 | { |
| 63 | preg_match('~(countdown|countup|ticker|worldclock)/([^/]+)~', (string) $this->url, $m); |
| 64 | $embedUrl = 'https://www.tickcounter.com/widget/' . $m['1'] . '/' . $m['2']; |
| 65 | |
| 66 | $attr = []; |
| 67 | $attr[] = 'src="' . $embedUrl . '"'; |
| 68 | $attr[] = 'width="{width}"'; |
| 69 | $attr[] = 'height="{height}"'; |
| 70 | $attr[] = 'frameborder="0"'; |
| 71 | $attr[] = 'scrolling="no"'; |
| 72 | $attr[] = 'title=""'; |
| 73 | |
| 74 | return [ |
| 75 | 'type' => 'rich', |
| 76 | 'provider_name' => 'Tickcounter', |
| 77 | 'provider_url' => 'https://tickcounter.com', |
| 78 | 'title' => 'Unknown title', |
| 79 | 'html' => '<iframe ' . implode(' ', $attr). '></iframe>', |
| 80 | ]; |
| 81 | } |
| 82 | |
| 83 | } |
| 84 |