AMP
2 years ago
Analytics
9 months ago
Elementor
6 months ago
Ends
6 months ago
Gutenberg
7 months ago
Includes
6 months ago
Plugins
1 year ago
Providers
6 months ago
ThirdParty
9 months ago
AutoLoader.php
2 years ago
Compatibility.php
2 years ago
Core.php
7 months ago
CoreLegacy.php
9 months ago
DisablerLegacy.php
2 years ago
Loader.php
2 years ago
MilestoneNotification.php
6 months ago
RestAPI.php
7 months ago
Shortcode.php
7 months ago
index.html
7 years ago
simple_html_dom.php
4 years ago
RestAPI.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress; |
| 4 | |
| 5 | use EmbedPress\Includes\Classes\Helper; |
| 6 | use Embera\Embera; |
| 7 | use WP_Error as WP_ErrorAlias; |
| 8 | use WP_REST_Request; |
| 9 | use WP_REST_Response; |
| 10 | |
| 11 | (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed."); |
| 12 | |
| 13 | /** |
| 14 | * Entity responsible for maintaining and registering all hooks that power the plugin. |
| 15 | * |
| 16 | * @package EmbedPress |
| 17 | * @author EmbedPress <help@embedpress.com> |
| 18 | * @copyright Copyright (C) 2023 WPDeveloper. All rights reserved. |
| 19 | * @license GPLv3 or later |
| 20 | * @since 1.0.0 |
| 21 | */ |
| 22 | class RestAPI |
| 23 | { |
| 24 | /** |
| 25 | * @param WP_REST_Request $request |
| 26 | * |
| 27 | * @return WP_REST_Response | WP_ErrorAlias |
| 28 | */ |
| 29 | public static function oembed($request) |
| 30 | { |
| 31 | $url = esc_url_raw($request->get_param('url')); |
| 32 | $playlist_id = $request->get_param( 'list'); |
| 33 | if ( !empty( $playlist_id) ) { |
| 34 | $url .= "&list=$playlist_id"; |
| 35 | } |
| 36 | |
| 37 | $atts = $request->get_params(); |
| 38 | |
| 39 | |
| 40 | if (empty($url)) { |
| 41 | return new WP_ErrorAlias('embedpress_invalid_url', 'Invalid Embed URL', ['status' => 404]); |
| 42 | } |
| 43 | |
| 44 | $atts = Helper::removeQuote($atts); |
| 45 | |
| 46 | // Map Meetup-specific Gutenberg attributes to shortcode attributes |
| 47 | if (!empty($url) && strpos($url, 'meetup.com') !== false) { |
| 48 | if (isset($atts['meetupOrderBy'])) { |
| 49 | $atts['orderby'] = $atts['meetupOrderBy']; |
| 50 | } |
| 51 | if (isset($atts['meetupOrder'])) { |
| 52 | $atts['order'] = $atts['meetupOrder']; |
| 53 | } |
| 54 | if (isset($atts['meetupPerPage'])) { |
| 55 | $atts['per_page'] = $atts['meetupPerPage']; |
| 56 | } |
| 57 | if (isset($atts['meetupEnablePagination'])) { |
| 58 | $atts['enable_pagination'] = $atts['meetupEnablePagination']; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | $urlInfo = Shortcode::parseContent( $url, true, $atts); |
| 63 | if (empty($urlInfo)) { |
| 64 | return new WP_ErrorAlias('embedpress_invalid_url', 'Invalid Embed URL', ['status' => 404]); |
| 65 | } |
| 66 | return new WP_REST_Response($urlInfo, 200); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | } |
| 71 |