Boomplay.php
5 years ago
Giphy.php
5 years ago
GoogleDocs.php
5 years ago
GoogleMaps.php
5 years ago
Twitch.php
5 years ago
index.html
7 years ago
GoogleMaps.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Providers; |
| 4 | |
| 5 | use Embera\Provider\ProviderAdapter; |
| 6 | use Embera\Provider\ProviderInterface; |
| 7 | use Embera\Url; |
| 8 | |
| 9 | (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed."); |
| 10 | |
| 11 | /** |
| 12 | * Entity responsible to support GoogleMaps embeds. |
| 13 | * |
| 14 | * @package EmbedPress |
| 15 | * @subpackage EmbedPress/Providers |
| 16 | * @author EmbedPress <help@embedpress.com> |
| 17 | * @copyright Copyright (C) 2020 WPDeveloper. All rights reserved. |
| 18 | * @license GPLv3 or later |
| 19 | * @since 1.0.0 |
| 20 | */ |
| 21 | class GoogleMaps extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected static $hosts = ["google.com", "google.com.*", "maps.google.com", "goo.gl", "google.co.*"]; |
| 25 | /** |
| 26 | * Method that verifies if the embed URL belongs to GoogleMaps. |
| 27 | * |
| 28 | * @param Url $url |
| 29 | * @return boolean |
| 30 | * @since 1.0.0 |
| 31 | * |
| 32 | */ |
| 33 | public function validateUrl(Url $url) |
| 34 | { |
| 35 | |
| 36 | return (bool) preg_match('~http[s]?:\/\/(?:(?:(?:www\.|maps\.)?(?:google\.com?))|(?:goo\.gl))(?:\.[a-z]{2})?\/(?:maps\/)?(?:place\/)?(?:[a-z0-9\/%+\-_]*)?([a-z0-9\/%,+\-_=!:@\.&*\$#?\']*)~i', |
| 37 | (string) $url); |
| 38 | |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * This method fakes an Oembed response. |
| 43 | * |
| 44 | * @since 1.0.0 |
| 45 | * |
| 46 | * @return array |
| 47 | */ |
| 48 | public function fakeResponse() |
| 49 | { |
| 50 | // Check if the url is already converted to the embed format |
| 51 | if (preg_match('~(maps/embed|output=embed)~i', $this->url)) { |
| 52 | $iframeSrc = $this->url; |
| 53 | } else { |
| 54 | // Extract coordinates and zoom from the url |
| 55 | if (preg_match('~@(-?[0-9\.]+,-?[0-9\.]+).+,([0-9\.]+[a-z])~i', $this->url, $matches)) { |
| 56 | $z = floatval( $matches[2]); |
| 57 | $iframeSrc = 'https://maps.google.com/maps?hl=en&ie=UTF8&ll=' . $matches[1] . '&spn=' . $matches[1] . '&t=m&z=' . round($z) . '&output=embed'; |
| 58 | } else { |
| 59 | return []; |
| 60 | } |
| 61 | } |
| 62 | $width = isset( $this->config['maxwidth']) ? $this->config['maxwidth']: 600; |
| 63 | $height = isset( $this->config['maxheight']) ? $this->config['maxheight']: 450; |
| 64 | return [ |
| 65 | 'type' => 'rich', |
| 66 | 'provider_name' => 'Google Maps', |
| 67 | 'provider_url' => 'https://maps.google.com', |
| 68 | 'title' => 'Unknown title', |
| 69 | 'html' => '<iframe width="'.$width.'" height="'.$height.'" src="' . $iframeSrc . '" frameborder="0"></iframe>', |
| 70 | ]; |
| 71 | } |
| 72 | /** inline @inheritDoc */ |
| 73 | public function modifyResponse( array $response = []) |
| 74 | { |
| 75 | return $this->fakeResponse(); |
| 76 | } |
| 77 | |
| 78 | } |
| 79 |