AMP
6 years ago
Ends
6 years ago
Plugins
6 years ago
Providers
6 years ago
ThirdParty
6 years ago
AutoLoader.php
6 years ago
Compatibility.php
6 years ago
Core.php
6 years ago
CoreLegacy.php
6 years ago
DisablerLegacy.php
6 years ago
Loader.php
6 years ago
RestAPI.php
6 years ago
Shortcode.php
6 years ago
index.html
6 years ago
RestAPI.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress; |
| 4 | |
| 5 | (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed."); |
| 6 | |
| 7 | /** |
| 8 | * Entity responsible for maintaining and registering all hooks that power the plugin. |
| 9 | * |
| 10 | * @package EmbedPress |
| 11 | * @author EmbedPress <help@embedpress.com> |
| 12 | * @copyright Copyright (C) 2018 EmbedPress. All rights reserved. |
| 13 | * @license GPLv2 or later |
| 14 | * @since 1.0.0 |
| 15 | */ |
| 16 | class RestAPI |
| 17 | { |
| 18 | /** |
| 19 | * @param \WP_REST_Request $request |
| 20 | */ |
| 21 | public static function oembed($request) |
| 22 | { |
| 23 | $url = sanitize_url($request->get_param('url')); |
| 24 | |
| 25 | if (empty($url)) { |
| 26 | return new \WP_Error('embedpress_invalid_url', 'Invalid Embed URL', ['status' => 404]); |
| 27 | } |
| 28 | |
| 29 | $config = []; |
| 30 | $embera = new \Embera\Embera($config); |
| 31 | |
| 32 | $additionalServiceProviders = Core::getAdditionalServiceProviders(); |
| 33 | if ( ! empty($additionalServiceProviders)) { |
| 34 | foreach ($additionalServiceProviders as $serviceProviderClassName => $serviceProviderUrls) { |
| 35 | Shortcode::addServiceProvider($serviceProviderClassName, $serviceProviderUrls, $embera); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | $urlInfo = $embera->getUrlInfo($url); |
| 40 | if (isset($urlInfo[$url])) { |
| 41 | $urlInfo = (object)$urlInfo[$url]; |
| 42 | $response['canBeResponsive'] = Core::canServiceProviderBeResponsive($urlInfo->provider_alias); |
| 43 | } |
| 44 | |
| 45 | if (empty($urlInfo)) { |
| 46 | return new \WP_Error('embedpress_invalid_url', 'Invalid Embed URL', ['status' => 404]); |
| 47 | } |
| 48 | |
| 49 | return new \WP_REST_Response($urlInfo, 202); |
| 50 | } |
| 51 | } |
| 52 |