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