AMP
2 years ago
Analytics
9 months ago
Elementor
1 month ago
Ends
1 month ago
Gutenberg
1 month ago
Includes
1 month ago
Plugins
1 year ago
Providers
1 month ago
ThirdParty
1 month ago
AutoLoader.php
2 years ago
Compatibility.php
2 years ago
Core.php
2 months ago
CoreLegacy.php
2 months ago
DisablerLegacy.php
2 years ago
Loader.php
2 years ago
MilestoneNotification.php
6 months ago
RestAPI.php
3 months ago
Shortcode.php
1 month ago
index.html
7 years ago
simple_html_dom.php
4 years ago
RestAPI.php
100 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 | // Prevent infinite recursion: this endpoint IS the oembed provider, |
| 32 | // so if it triggers another oembed fetch that resolves back here, stop immediately. |
| 33 | static $is_processing = false; |
| 34 | if ($is_processing) { |
| 35 | return new WP_ErrorAlias( |
| 36 | 'embedpress_recursion', |
| 37 | 'Recursive oEmbed request detected', |
| 38 | ['status' => 508] |
| 39 | ); |
| 40 | } |
| 41 | $is_processing = true; |
| 42 | |
| 43 | $url = esc_url_raw($request->get_param('url')); |
| 44 | $playlist_id = $request->get_param( 'list'); |
| 45 | if ( !empty( $playlist_id) ) { |
| 46 | $url .= "&list=$playlist_id"; |
| 47 | } |
| 48 | |
| 49 | $atts = $request->get_params(); |
| 50 | |
| 51 | |
| 52 | if (empty($url)) { |
| 53 | $is_processing = false; |
| 54 | return new WP_ErrorAlias('embedpress_invalid_url', 'Invalid Embed URL', ['status' => 404]); |
| 55 | } |
| 56 | |
| 57 | // Validate URL has a proper scheme to reject malformed URLs early |
| 58 | if (!preg_match('#^https?://#i', $url)) { |
| 59 | $is_processing = false; |
| 60 | return new WP_ErrorAlias('embedpress_invalid_url', 'Invalid URL scheme', ['status' => 400]); |
| 61 | } |
| 62 | |
| 63 | $atts = Helper::removeQuote($atts); |
| 64 | |
| 65 | // Map Meetup-specific Gutenberg attributes to shortcode attributes |
| 66 | if (!empty($url) && strpos($url, 'meetup.com') !== false) { |
| 67 | if (isset($atts['meetupOrderBy'])) { |
| 68 | $atts['orderby'] = $atts['meetupOrderBy']; |
| 69 | } |
| 70 | if (isset($atts['meetupOrder'])) { |
| 71 | $atts['order'] = $atts['meetupOrder']; |
| 72 | } |
| 73 | if (isset($atts['meetupPerPage'])) { |
| 74 | $atts['per_page'] = $atts['meetupPerPage']; |
| 75 | } |
| 76 | if (isset($atts['meetupEnablePagination'])) { |
| 77 | $atts['enable_pagination'] = $atts['meetupEnablePagination']; |
| 78 | } |
| 79 | if (isset($atts['meetupTimezone'])) { |
| 80 | $atts['timezone'] = $atts['meetupTimezone']; |
| 81 | } |
| 82 | if (isset($atts['meetupDateFormat'])) { |
| 83 | $atts['date_format'] = $atts['meetupDateFormat']; |
| 84 | } |
| 85 | if (isset($atts['meetupTimeFormat'])) { |
| 86 | $atts['time_format'] = $atts['meetupTimeFormat']; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | $urlInfo = Shortcode::parseContent( $url, true, $atts); |
| 91 | $is_processing = false; |
| 92 | if (empty($urlInfo)) { |
| 93 | return new WP_ErrorAlias('embedpress_invalid_url', 'Invalid Embed URL', ['status' => 404]); |
| 94 | } |
| 95 | return new WP_REST_Response($urlInfo, 200); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | } |
| 100 |