Skip to content

Commit

Permalink
Add new option to allow you to set missing URL query params that are …
Browse files Browse the repository at this point in the history
…supported by the providers oembed protocol. ([#29](#29) & [#30](#30))
  • Loading branch information
reganlawton committed Jan 29, 2020
1 parent 554032a commit e500db7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# oEmbed Changelog

## 1.2.2 - 2020-01-30

### Updated
- Updated README with usage of new feature.

### Added
- *(NEW FEATURE)* Add new `params` option to allow you to set missing URL query params that are supported by the providers oembed protocol. ([#24](https://github.com/wrav/oembed/issues/24) & [#30](https://github.com/wrav/oembed/issues/30))

## 1.2.1 - 2020-01-19

### Updated
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ We also provide option to use as a Twig variable
{% set embed = craft.oembed.embed(url, options) %}
{% set media = craft.oembed.media(url, options) %}

Updating the embed URL , such as autoplay, rel, mute paramaters. This allows for you to support features the provider might not yet support

{{
entry.oembed_field.render({
params: {
autoplay: 1,
rel: 0,
mute: 0,
loop: 1,
autopause: 1,
}
})
}}

You can access additional media details using the examples below.

entry.field.media.title
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "1.2.1",
"version": "1.2.2",
"keywords": [
"craft",
"cms",
Expand Down
7 changes: 7 additions & 0 deletions src/services/OembedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function __call(string $name , array $arguments )
};
}


// Wrapping to be safe :)
try {
$html = $media->code;
Expand All @@ -72,6 +73,12 @@ public function __call(string $name , array $arguments )
$iframe = $dom->getElementsByTagName('iframe')->item(0);
$src = $iframe->getAttribute('src');

if(!empty($options['params'])) {
foreach((array)$options['params'] as $key => $value) {
$src = preg_replace('/\?(.*)$/i', '?'.$key.'='. $value .'&${1}', $src);
}
}

// Autoplay
if (!empty($options['autoplay']) && strpos($html, 'autoplay=') === false && $src) {
$src = preg_replace('/\?(.*)$/i', '?autoplay='. (!!$options['autoplay'] ? '1' : '0') .'&${1}', $src);
Expand Down

0 comments on commit e500db7

Please sign in to comment.