Smugmug.php
| 1 | <?php |
| 2 | /** |
| 3 | * Smugmug.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 | * Smugmug Provider |
| 19 | * @link https://*.smugmug.com |
| 20 | * @link https://api.smugmug.com/services/oembed |
| 21 | */ |
| 22 | class Smugmug extends ProviderAdapter implements ProviderInterface |
| 23 | { |
| 24 | /** inline {@inheritdoc} */ |
| 25 | protected $endpoint = 'https://api.smugmug.com/services/oembed/?format=json'; |
| 26 | |
| 27 | /** inline {@inheritdoc} */ |
| 28 | protected static $hosts = [ |
| 29 | '*.smugmug.com' |
| 30 | ]; |
| 31 | |
| 32 | /** inline {@inheritdoc} */ |
| 33 | protected $httpsSupport = true; |
| 34 | |
| 35 | /** inline {@inheritdoc} */ |
| 36 | public function validateUrl(Url $url) |
| 37 | { |
| 38 | return (bool) (preg_match('~smugmug\.com/([^/]+)/([^/]+)/([^/]+)$~i', (string) $url)); |
| 39 | } |
| 40 | |
| 41 | /** inline {@inheritdoc} */ |
| 42 | public function normalizeUrl(Url $url) |
| 43 | { |
| 44 | $url->convertToHttps(); |
| 45 | $url->removeQueryString(); |
| 46 | $url->removeLastSlash(); |
| 47 | |
| 48 | return $url; |
| 49 | } |
| 50 | |
| 51 | /** inline {@inheritdoc} */ |
| 52 | public function modifyResponse(array $response = []) |
| 53 | { |
| 54 | if (empty($response['html']) && $response['type'] == 'photo') { |
| 55 | $html = []; |
| 56 | $html[] = '<div class="smugmug-html">'; |
| 57 | $html[] = '<a href="' . $response['gallery_url'] . '" title="">'; |
| 58 | $html[] = '<img src="' . $response['url'] . '" alt=""" title="">'; |
| 59 | $html[] = '</a>'; |
| 60 | $html[] = '</div>'; |
| 61 | |
| 62 | $response['html'] = implode('', $html); |
| 63 | } |
| 64 | |
| 65 | return $response; |
| 66 | } |
| 67 | |
| 68 | } |
| 69 |