Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Ability to send settings to `CurlClient`. Added the `cookies_path` setting to customize the file used for cookies. #345
- `Document::selectCss()` function to select elements using css selectors instead xpath (it requires symfony/css-selector)
- `Document::removeCss()` function to remove elements using css selectors instead xpath (it requires symfony/css-selector)
- Ability to configure OEmbed parameters from the outside

## 4.0.0 - 2020-03-13
Full library refactoring.
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ $oembed->int('width'); //Return the value as integer
$oembed->url('url'); //Return the value as full url (converts relative urls to absolutes)
```

Additional oEmbed parameters (like instagrams `hidecaption`) can also be provided:
```php
$embed = new Embed();

$result = $embed->get('https://www.instagram.com/p/B_C0wheCa4V/');
$result->setSettings([
'oembed:query_parameters' => ['hidecaption' => true]
]);
$oembed = $info->getOEmbed();
```

## LinkedData

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

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.

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.
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.

```php
use Embed\Embed;
Expand Down
2 changes: 1 addition & 1 deletion src/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function getSettings(): array
return $this->settings;
}

public function getSetting(string $key): ?string
public function getSetting(string $key)
{
return $this->settings[$key] ?? null;
}
Expand Down
9 changes: 8 additions & 1 deletion src/OEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ private static function getProviders(): array
return self::$providers;
}

public function getOembedQueryParameters(string $url): array
{
$queryParameters = ['url' => $url, 'format' => 'json'];

return array_merge($queryParameters, $this->extractor->getSetting('oembed:query_parameters') ?? []);
}

protected function fetchData(): array
{
$this->endpoint = $this->detectEndpoint();
Expand Down Expand Up @@ -63,7 +70,7 @@ private function detectEndpointFromProviders(): ?UriInterface

return $this->extractor->getCrawler()
->createUri($endpoint)
->withQuery(http_build_query(['url' => $url, 'format' => 'json']));
->withQuery(http_build_query($this->getOembedQueryParameters($url)));
}

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