Boomplay.php
5 years ago
Giphy.php
5 years ago
GoogleDocs.php
5 years ago
GoogleMaps.php
5 years ago
Twitch.php
5 years ago
index.html
7 years ago
Boomplay.php
106 lines
| 1 | <?php |
| 2 | namespace EmbedPress\Providers; |
| 3 | |
| 4 | use Embera\Provider\ProviderAdapter; |
| 5 | use Embera\Provider\ProviderInterface; |
| 6 | use Embera\Url; |
| 7 | |
| 8 | (defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed. or EmbedPress is not loaded yet."); |
| 9 | |
| 10 | /** |
| 11 | * Entity responsible to support Boomplay embeds. |
| 12 | * |
| 13 | * @package EmbedPress |
| 14 | * @subpackage EmbedPress/Providers |
| 15 | * @author EmbedPress <help@embedpress.com> |
| 16 | * @copyright Copyright (C) 2021 WPDeveloper. All rights reserved. |
| 17 | * @license GPLv3 or later |
| 18 | * @since 1.5.0 |
| 19 | */ |
| 20 | class Boomplay extends ProviderAdapter implements ProviderInterface |
| 21 | { |
| 22 | /** |
| 23 | * The regex which identifies Boomplay URLs. |
| 24 | * |
| 25 | * @since 1.5.0 |
| 26 | * @access private |
| 27 | * |
| 28 | * @var string |
| 29 | */ |
| 30 | private $urlRegexPattern = '/boomplay\.com\/(songs|playlists|albums)\/(\d+)/'; |
| 31 | |
| 32 | /** |
| 33 | * Method that verifies if the embed URL belongs to Boomplay. |
| 34 | * |
| 35 | * @param Url $url |
| 36 | * @return boolean |
| 37 | * |
| 38 | */ |
| 39 | public function validateUrl(Url $url) |
| 40 | { |
| 41 | return (bool) preg_match($this->urlRegexPattern, $this->url); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * This method fakes an Oembed response. |
| 46 | * |
| 47 | * @since 1.5.0 |
| 48 | * |
| 49 | * @return array |
| 50 | */ |
| 51 | public function fakeResponse() |
| 52 | { |
| 53 | $url = $this->getUrl(); |
| 54 | $providerUrl = 'https://www.boomplay.com'; |
| 55 | |
| 56 | if (preg_match("{$this->urlRegexPattern}i", $url, $matches)) { |
| 57 | $type = $matches[1]; // songs | playlists | album |
| 58 | $content_id = $matches[2]; |
| 59 | $endpoint_type = apply_filters( 'embedpress_boomplay_content_type', 'MUSIC', $type); |
| 60 | |
| 61 | $width = isset( $this->config['maxwidth']) ? $this->config['maxwidth']: '100%'; |
| 62 | $height = isset( $this->config['maxheight']) ? $this->config['maxheight']: 450; |
| 63 | |
| 64 | $html = "<iframe src='https://www.boomplay.com/embed/$content_id/$endpoint_type' frameborder='0' height='$height' width='$width'></iframe>"; |
| 65 | |
| 66 | |
| 67 | |
| 68 | $response = [ |
| 69 | 'type' => $type, |
| 70 | 'content_id' => $content_id, |
| 71 | 'provider_name' => 'Boomplay', |
| 72 | 'provider_url' => $providerUrl, |
| 73 | 'url' => $url, |
| 74 | 'html' => $html, |
| 75 | ]; |
| 76 | |
| 77 | if ( in_array( $type, ['albums', 'playlists'])) { |
| 78 | $alert_message = sprintf( '<p><strong>%s</strong>. <span style="font-size: 13px;">%s</span></p>', __( 'Embedding Boomplay playlists and albums are supported in EmbedPress Pro', 'embedpress'), __( 'This message is only visible to you.', 'embedpress')); |
| 79 | // for gutenberg |
| 80 | |
| 81 | if ( !is_embedpress_pro_active() ) { |
| 82 | $response['alert'] = $alert_message; |
| 83 | } |
| 84 | |
| 85 | if ( is_admin() && !is_embedpress_pro_active() ) { |
| 86 | $response['html'] = $alert_message; |
| 87 | } |
| 88 | |
| 89 | if ( !is_admin() && !is_embedpress_pro_active() ) { |
| 90 | $response['html'] = $url; |
| 91 | } |
| 92 | |
| 93 | } |
| 94 | } else { |
| 95 | $response = []; |
| 96 | } |
| 97 | |
| 98 | return $response; |
| 99 | } |
| 100 | /** inline @inheritDoc */ |
| 101 | public function modifyResponse( array $response = []) |
| 102 | { |
| 103 | return $this->fakeResponse(); |
| 104 | } |
| 105 | } |
| 106 |