Skip to content

Commit a8fceaa

Browse files
authored
Merge pull request #346 from RedaktionsNetzwerk-Deutschland/feature/configurable-oembed
make oembed configurable for additional oembed parameters
2 parents f255552 + 252cf35 commit a8fceaa

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- Ability to send settings to `CurlClient`. Added the `cookies_path` setting to customize the file used for cookies. #345
1111
- `Document::selectCss()` function to select elements using css selectors instead xpath (it requires symfony/css-selector)
1212
- `Document::removeCss()` function to remove elements using css selectors instead xpath (it requires symfony/css-selector)
13+
- Ability to configure OEmbed parameters from the outside
1314

1415
## 4.0.0 - 2020-03-13
1516
Full library refactoring.

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ $oembed->int('width'); //Return the value as integer
167167
$oembed->url('url'); //Return the value as full url (converts relative urls to absolutes)
168168
```
169169

170+
Additional oEmbed parameters (like instagrams `hidecaption`) can also be provided:
171+
```php
172+
$embed = new Embed();
173+
174+
$result = $embed->get('https://www.instagram.com/p/B_C0wheCa4V/');
175+
$result->setSettings([
176+
'oembed:query_parameters' => ['hidecaption' => true]
177+
]);
178+
$oembed = $info->getOEmbed();
179+
```
180+
170181
## LinkedData
171182

172183
Another API available by default, used to extract info using the [JsonLD](https://www.w3.org/TR/json-ld/) schema.
@@ -247,7 +258,7 @@ The `Extractor` class has many `Detectors`. Each detector is responsible to dete
247258

248259
So, an adapter is basically an extractor created specifically for a site. It can contains also custom detectors or apis. If you see the `src/Adapters` folder you can see all adapters.
249260

250-
If you create an adapter, you need also register to Embed, so it knows in which website needs to use. To do that, there's the `ExtractorFactory` object, that is responsible for instantiate the right extractor for each site.
261+
If you create an adapter, you need also register to Embed, so it knows in which website needs to use. To do that, there's the `ExtractorFactory` object, that is responsible for instantiate the right extractor for each site.
251262

252263
```php
253264
use Embed\Embed;

src/Extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function getSettings(): array
129129
return $this->settings;
130130
}
131131

132-
public function getSetting(string $key): ?string
132+
public function getSetting(string $key)
133133
{
134134
return $this->settings[$key] ?? null;
135135
}

src/OEmbed.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ private static function getProviders(): array
2222
return self::$providers;
2323
}
2424

25+
public function getOembedQueryParameters(string $url): array
26+
{
27+
$queryParameters = ['url' => $url, 'format' => 'json'];
28+
29+
return array_merge($queryParameters, $this->extractor->getSetting('oembed:query_parameters') ?? []);
30+
}
31+
2532
protected function fetchData(): array
2633
{
2734
$this->endpoint = $this->detectEndpoint();
@@ -63,7 +70,7 @@ private function detectEndpointFromProviders(): ?UriInterface
6370

6471
return $this->extractor->getCrawler()
6572
->createUri($endpoint)
66-
->withQuery(http_build_query(['url' => $url, 'format' => 'json']));
73+
->withQuery(http_build_query($this->getOembedQueryParameters($url)));
6774
}
6875

6976
private static function searchEndpoint(array $providers, string $url): ?string

0 commit comments

Comments
 (0)