diff --git a/CHANGELOG.md b/CHANGELOG.md index d5f2a3c..f91d058 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # oEmbed Changelog +## 3.0.6 - 2023-12-15 + +### Update +- Fixed issue with src attribute not being set on iframe. Reported by @holiday-jan in issue #146. Thanks @holiday-jan +- Rework preview handling +- Updated README docs +- Fallback .code for certain providers, this completely blocked GraphQL users. Reported by @yoannisj in issue #129. Thanks @yoannisj + ## 3.0.5 - 2023-12-08 ### Update diff --git a/README.md b/README.md index c4e6c3b..55fdf88 100755 --- a/README.md +++ b/README.md @@ -65,13 +65,11 @@ Updating the embed URL, such as autoplay, rel, mute paramaters. This allows for {{ entry.oembed_field.render({ - params: { - autoplay: 1, - rel: 0, - mute: 0, - loop: 1, - autopause: 1, - }, + autoplay: 1, + rel: 0, + mute: 0, + loop: 1, + autopause: 1, attributes: { title: 'Main title', 'data-title': 'Some other title', diff --git a/composer.json b/composer.json index 166c53f..1a7596d 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "wrav/oembed", "description": "A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.", "type": "craft-plugin", - "version": "3.0.5", + "version": "3.0.6", "keywords": [ "craft", "cms", diff --git a/src/adapters/EmbedAdapter.php b/src/adapters/EmbedAdapter.php index 3dc310b..9a6c3f6 100755 --- a/src/adapters/EmbedAdapter.php +++ b/src/adapters/EmbedAdapter.php @@ -52,6 +52,9 @@ public function __construct($data) $this->$key = $this->data[$keyName] ?? null; } + // Fallback for .code incase it's empty + $this->code = $this->code ?: $this->getCode(); + // Custom mapping // Fallback for .image diff --git a/src/services/OembedService.php b/src/services/OembedService.php index d9e1754..e4f3ac1 100755 --- a/src/services/OembedService.php +++ b/src/services/OembedService.php @@ -152,7 +152,7 @@ public function embed($url, array $options = [], array $cacheProps = []) } // Autoplay - if (!empty($options['autoplay']) && strpos($html, 'autoplay=') === false && $src) { + if (!empty($options['autoplay']) && strpos($src, 'autoplay=') === false && $src) { $src = preg_replace('/\?(.*)$/i', '?autoplay=' . (!!$options['autoplay'] ? '1' : '0') . '&${1}', $src); } @@ -167,28 +167,34 @@ public function embed($url, array $options = [], array $cacheProps = []) } // Looping - if (!empty($options['loop']) && strpos($html, 'loop=') === false && $src) { + if (!empty($options['loop']) && strpos($src, 'loop=') === false && $src) { $src = preg_replace('/\?(.*)$/i', '?loop=' . (!!$options['loop'] ? '1' : '0') . '&${1}', $src); } // Autopause - if (!empty($options['autopause']) && strpos($html, 'autopause=') === false && $src) { + if (!empty($options['autopause']) && strpos($src, 'autopause=') === false && $src) { $src = preg_replace('/\?(.*)$/i', '?autopause=' . (!!$options['autopause'] ? '1' : '0') . '&${1}', $src); } // Rel - if (!empty($options['rel']) && strpos($html, 'rel=') === false && $src) { + if (!empty($options['rel']) && strpos($src, 'rel=') === false && $src) { $src = preg_replace('/\?(.*)$/i', '?rel=' . (!!$options['rel'] ? '1' : '0') . '&${1}', $src); } + // Apply attributes to the iframe if (!empty($options['attributes'])) { foreach ((array)$options['attributes'] as $key => $value) { $iframe->setAttribute($key, $value); } } + // Set the SRC $iframe->setAttribute('src', $src); - $media->code = $dom->saveXML($iframe, LIBXML_NOEMPTYTAG); + + // Set the code + $code = $dom->saveXML($iframe, LIBXML_NOEMPTYTAG); + + $media->code = $code; } catch (\Exception $exception) { Craft::info($exception->getMessage(), 'oembed'); } finally { diff --git a/src/templates/preview.twig b/src/templates/preview.twig index 66717e8..ca1b8dc 100755 --- a/src/templates/preview.twig +++ b/src/templates/preview.twig @@ -1,7 +1,9 @@ -{% set media = craft.oembed.embed(url) %} - -{% if media and media.code|default(false) %} - {{ media.code|default('')|raw }} +{% if url is defined and url is not null and url is not empty or craft.oembed.valid(url) %} + {{ + craft.oembed.render( + url, + ) + }} {% else %}

Please check your URL.

{% endif %}