Boomplay.php
5 years ago
Calendly.php
2 years ago
Giphy.php
2 years ago
GitHub.php
2 years ago
GoogleDocs.php
2 years ago
GoogleDrive.php
2 years ago
GoogleMaps.php
2 years ago
Gumroad.php
2 years ago
NRKRadio.php
2 years ago
OpenSea.php
3 years ago
SelfHosted.php
2 years ago
Twitch.php
2 years ago
Wrapper.php
2 years ago
Youtube.php
2 years ago
index.html
7 years ago
GoogleDrive.php
85 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 Googledrive embeds. |
| 13 | * |
| 14 | * @package EmbedPress |
| 15 | * @subpackage EmbedPress/Providers |
| 16 | * @author EmbedPress <help@embedpress.com> |
| 17 | * @copyright Copyright (C) 2023 WPDeveloper. All rights reserved. |
| 18 | * @license GPLv3 or later |
| 19 | * @since 1.0.0 |
| 20 | */ |
| 21 | class GoogleDrive extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected static $hosts = ["google.com", "google.com.*", "drive.google.com", "goo.gl", "google.co.*"]; |
| 25 | /** |
| 26 | * Method that verifies if the embed URL belongs to Googledrive. |
| 27 | * |
| 28 | * @param Url $url |
| 29 | * @return boolean |
| 30 | * @since 1.0.0 |
| 31 | * |
| 32 | */ |
| 33 | public function validateUrl(Url $url) |
| 34 | { |
| 35 | return (bool) preg_match( |
| 36 | '~http[s]?:\/\/(?:(?:(?:www\.|drive\.)?(?:google\.com?))|(?:goo\.gl))(?:\.[a-z]{2})?\/(?:drive\/)?(?:place\/)?(?:[a-z0-9\/%+\-_]*)?([a-z0-9\/%,+\-_=!:@\.&*\$#?\']*)~i', |
| 37 | (string) $url |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | public function validateGoogleDriveUrl($url) |
| 42 | { |
| 43 | return (bool) preg_match( |
| 44 | '~http[s]?:\/\/(?:(?:(?:www\.|drive\.)?(?:google\.com?))|(?:goo\.gl))(?:\.[a-z]{2})?\/(?:drive\/)?(?:place\/)?(?:[a-z0-9\/%+\-_]*)?([a-z0-9\/%,+\-_=!:@\.&*\$#?\']*)~i', |
| 45 | (string) $url |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * This method fakes an Oembed response. |
| 51 | * |
| 52 | * @since 1.0.0 |
| 53 | * |
| 54 | * @return array |
| 55 | */ |
| 56 | public function fakeResponse() |
| 57 | { |
| 58 | $src_url = urldecode($this->url); |
| 59 | |
| 60 | // Check if the url is already converted to the embed format |
| 61 | if (preg_match('/^https:\/\/drive\.google\.com\/file\/d\/(.+?)\/.*$/', $src_url, $matches)) { |
| 62 | $file_id = $matches[1]; |
| 63 | $iframeSrc = 'https://drive.google.com/file/d/' . $file_id . '/preview'; |
| 64 | } else { |
| 65 | return []; |
| 66 | } |
| 67 | |
| 68 | $width = isset($this->config['maxwidth']) ? $this->config['maxwidth'] : 600; |
| 69 | $height = isset($this->config['maxheight']) ? $this->config['maxheight'] : 450; |
| 70 | |
| 71 | return [ |
| 72 | 'type' => 'rich', |
| 73 | 'provider_name' => 'Google drive', |
| 74 | 'provider_url' => 'https://drive.google.com', |
| 75 | 'title' => 'Unknown title', |
| 76 | 'html' => '<iframe title="" width="' . $width . '" height="' . $height . '" src="' . $iframeSrc . '" ></iframe>', |
| 77 | ]; |
| 78 | } |
| 79 | /** inline @inheritDoc */ |
| 80 | public function modifyResponse(array $response = []) |
| 81 | { |
| 82 | return $this->fakeResponse(); |
| 83 | } |
| 84 | } |
| 85 |