TemplateLayouts
1 year ago
AirTable.php
1 year ago
Boomplay.php
1 year ago
Calendly.php
2 years ago
Canva.php
1 year ago
FITE.php
1 year ago
Giphy.php
2 years ago
GitHub.php
3 years ago
GoogleDocs.php
2 years ago
GoogleDrive.php
2 years ago
GoogleMaps.php
2 years ago
GooglePhotos.php
1 year ago
Gumroad.php
2 years ago
InstagramFeed.php
1 year ago
LinkedIn.php
2 years ago
NRKRadio.php
2 years ago
OneDrive.php
1 year ago
OpenSea.php
2 years ago
SelfHosted.php
2 years ago
Spreaker.php
1 year ago
TikTok.php
2 years ago
Twitch.php
2 years ago
Wrapper.php
3 years ago
X.php
2 years ago
Youtube.php
1 year ago
index.html
7 years ago
Canva.php
75 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 Canva 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 Canva extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected static $hosts = ["canva.com", "www.canva.com"]; |
| 25 | |
| 26 | /** |
| 27 | * Method that verifies if the embed URL belongs to Canva. |
| 28 | * |
| 29 | * @param Url $url |
| 30 | * @return boolean |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | public function validateUrl(Url $url) |
| 34 | { |
| 35 | return (bool) preg_match('~https?:\/\/(?:www\.)?canva\.com\/design\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)~i', (string) $url); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * This method fakes an OEmbed response for Canva. |
| 40 | * |
| 41 | * @since 1.0.0 |
| 42 | * @return array |
| 43 | */ |
| 44 | public function fakeResponse() |
| 45 | { |
| 46 | $src_url = urldecode($this->url); |
| 47 | |
| 48 | // Check if the URL matches a Canva design link with full structure |
| 49 | if (preg_match('~https?:\/\/(?:www\.)?canva\.com\/design\/([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)~i', $src_url, $matches)) { |
| 50 | $design_id = $matches[1]; |
| 51 | $unique_id = $matches[2]; |
| 52 | $iframeSrc = "https://www.canva.com/design/{$design_id}/{$unique_id}/view?embed"; |
| 53 | } else { |
| 54 | return []; |
| 55 | } |
| 56 | |
| 57 | $width = isset($this->config['maxwidth']) ? $this->config['maxwidth'] : 800; |
| 58 | $height = isset($this->config['maxheight']) ? $this->config['maxheight'] : 600; |
| 59 | |
| 60 | return [ |
| 61 | 'type' => 'rich', |
| 62 | 'provider_name' => 'Canva', |
| 63 | 'provider_url' => 'https://www.canva.com', |
| 64 | 'title' => 'Canva Design', |
| 65 | 'html' => '<iframe title="Canva Design" width="' . esc_attr($width) . '" height="' . esc_attr($height) . '" src="' . esc_url($iframeSrc) . '" frameborder="0" allowfullscreen></iframe>', |
| 66 | ]; |
| 67 | } |
| 68 | |
| 69 | /** inline @inheritDoc */ |
| 70 | public function modifyResponse(array $response = []) |
| 71 | { |
| 72 | return $this->fakeResponse(); |
| 73 | } |
| 74 | } |
| 75 |