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