Update dependencies

This commit is contained in:
Jay Trees 2022-01-13 13:47:56 +01:00
parent 03196c3e53
commit ceb1512149
14 changed files with 233 additions and 14 deletions

24
composer.lock generated
View file

@ -84,16 +84,16 @@
},
{
"name": "embed/embed",
"version": "v4.3.5",
"version": "v4.4.0",
"source": {
"type": "git",
"url": "https://github.com/oscarotero/Embed.git",
"reference": "4dd2b05119462142ea4adfcf42e75f31dc056975"
"reference": "24fe9376e8de48c536ddaddf0025ae39cae5ddfe"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/oscarotero/Embed/zipball/4dd2b05119462142ea4adfcf42e75f31dc056975",
"reference": "4dd2b05119462142ea4adfcf42e75f31dc056975",
"url": "https://api.github.com/repos/oscarotero/Embed/zipball/24fe9376e8de48c536ddaddf0025ae39cae5ddfe",
"reference": "24fe9376e8de48c536ddaddf0025ae39cae5ddfe",
"shasum": ""
},
"require": {
@ -153,9 +153,9 @@
"support": {
"email": "oom@oscarotero.com",
"issues": "https://github.com/oscarotero/Embed/issues",
"source": "https://github.com/oscarotero/Embed/tree/v4.3.5"
"source": "https://github.com/oscarotero/Embed/tree/v4.4.0"
},
"time": "2021-10-10T17:10:44+00:00"
"time": "2022-01-08T13:26:18+00:00"
},
{
"name": "grandel/include-directory",
@ -687,16 +687,16 @@
},
{
"name": "squizlabs/php_codesniffer",
"version": "3.6.1",
"version": "3.6.2",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "f268ca40d54617c6e06757f83f699775c9b3ff2e"
"reference": "5e4e71592f69da17871dba6e80dd51bce74a351a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/f268ca40d54617c6e06757f83f699775c9b3ff2e",
"reference": "f268ca40d54617c6e06757f83f699775c9b3ff2e",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a",
"reference": "5e4e71592f69da17871dba6e80dd51bce74a351a",
"shasum": ""
},
"require": {
@ -739,7 +739,7 @@
"source": "https://github.com/squizlabs/PHP_CodeSniffer",
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
},
"time": "2021-10-11T04:00:11+00:00"
"time": "2021-12-12T21:44:58+00:00"
}
],
"aliases": [],
@ -749,5 +749,5 @@
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.0.0"
"plugin-api-version": "2.1.0"
}

View file

@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [4.4.0] - 2022-01-08
### Added
- New settings option `twitter:token` to use Twitter API to get the data [#364] [#468].
### Fixed
- Headers not sent properly by curl [#466], [#467].
## [4.3.5] - 2021-10-10
### Fixed
- Updated oEmbed endpoints
@ -98,7 +105,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `Document::removeCss()` function to remove elements using css selectors instead xpath (it requires `symfony/css-selector`)
- Ability to configure OEmbed parameters from the outside using the `oembed:query_parameters` setting [#346]
## 4.0.0 - 2020-03-13
## [4.0.0] - 2020-03-13
Full library refactoring.
### Added
@ -129,6 +136,7 @@ Full library refactoring.
[#355]: https://github.com/oscarotero/Embed/issues/355
[#356]: https://github.com/oscarotero/Embed/issues/356
[#357]: https://github.com/oscarotero/Embed/issues/357
[#364]: https://github.com/oscarotero/Embed/issues/364
[#366]: https://github.com/oscarotero/Embed/issues/366
[#375]: https://github.com/oscarotero/Embed/issues/375
[#380]: https://github.com/oscarotero/Embed/issues/380
@ -155,7 +163,11 @@ Full library refactoring.
[#452]: https://github.com/oscarotero/Embed/issues/452
[#456]: https://github.com/oscarotero/Embed/issues/456
[#459]: https://github.com/oscarotero/Embed/issues/459
[#466]: https://github.com/oscarotero/Embed/issues/466
[#467]: https://github.com/oscarotero/Embed/issues/467
[#468]: https://github.com/oscarotero/Embed/issues/468
[4.4.0]: https://github.com/oscarotero/Embed/compare/v4.3.5...v4.4.0
[4.3.5]: https://github.com/oscarotero/Embed/compare/v4.3.4...v4.3.5
[4.3.4]: https://github.com/oscarotero/Embed/compare/v4.3.3...v4.3.4
[4.3.3]: https://github.com/oscarotero/Embed/compare/v4.3.2...v4.3.3
@ -172,3 +184,4 @@ Full library refactoring.
[4.2.0]: https://github.com/oscarotero/Embed/compare/v4.1.1...v4.2.0
[4.1.1]: https://github.com/oscarotero/Embed/compare/v4.1.0...v4.1.1
[4.1.0]: https://github.com/oscarotero/Embed/compare/v4.0.0...v4.1.0
[4.0.0]: https://github.com/oscarotero/Embed/releases/tag/v4.0.0

View file

@ -332,6 +332,7 @@ $embed->setSettings([
'twitch:parent' => 'example.com', //Required to embed twitch videos as iframe
'facebook:token' => '1234|5678', //Required to embed content from Facebook
'instagram:token' => '1234|5678', //Required to embed content from Instagram
'twitter:token' => 'asdf', //Improve the data from twitter
]);
$info = $embed->get($url);
```

View file

@ -0,0 +1,36 @@
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter;
use function Embed\getDirectory;
use Embed\HttpApiTrait;
class Api
{
use HttpApiTrait;
protected function fetchData(): array
{
$token = $this->extractor->getSetting('twitter:token');
if (!$token) {
return [];
}
$uri = $this->extractor->getUri();
$id = getDirectory($uri->getPath(), 2);
if (empty($id)) {
return [];
}
$this->extractor->getCrawler()->addDefaultHeaders(array('Authorization' => "Bearer $token"));
$this->endpoint = $this->extractor->getCrawler()->createUri("https://api.twitter.com/2/tweets/{$id}?expansions=author_id,attachments.media_keys&tweet.fields=created_at&media.fields=preview_image_url,url&user.fields=id,name");
$data = $this->fetchJSON($this->endpoint);
return $data ?? [];
}
}

View file

@ -0,0 +1,17 @@
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter\Detectors;
use Embed\Detectors\AuthorName as Detector;
class AuthorName extends Detector
{
public function detect(): ?string
{
$api = $this->extractor->getApi();
return $api->str('includes', 'users', '0', 'name')
?: parent::detect();
}
}

View file

@ -0,0 +1,22 @@
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter\Detectors;
use Embed\Detectors\AuthorUrl as Detector;
use Psr\Http\Message\UriInterface;
class AuthorUrl extends Detector
{
public function detect(): ?UriInterface
{
$api = $this->extractor->getApi();
$username = $api->str('includes', 'users', '0', 'username');
if ($username) {
return $this->extractor->getCrawler()->createUri("https://twitter.com/{$username}");
}
return parent::detect();
}
}

View file

@ -0,0 +1,17 @@
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter\Detectors;
use Embed\Detectors\Description as Detector;
class Description extends Detector
{
public function detect(): ?string
{
$api = $this->extractor->getApi();
return $api->str('data', 'text')
?: parent::detect();
}
}

View file

@ -0,0 +1,28 @@
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter\Detectors;
use Embed\Detectors\Image as Detector;
use Psr\Http\Message\UriInterface;
class Image extends Detector
{
public function detect(): ?UriInterface
{
$api = $this->extractor->getApi();
$preview = $api->url('includes', 'media', '0', 'preview_image_url');
if ($preview) {
return $preview;
}
$regular = $api->url('includes', 'media', '0', 'url');
if ($regular) {
return $regular;
}
return parent::detect();
}
}

View file

@ -0,0 +1,14 @@
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter\Detectors;
use Embed\Detectors\ProviderName as Detector;
class ProviderName extends Detector
{
public function detect(): string
{
return 'Twitter';
}
}

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter\Detectors;
use Datetime;
use Embed\Detectors\PublishedTime as Detector;
class PublishedTime extends Detector
{
public function detect(): ?Datetime
{
$api = $this->extractor->getApi();
return $api->time('data', 'created_at')
?: parent::detect();
}
}

View file

@ -0,0 +1,21 @@
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter\Detectors;
use Embed\Detectors\Title as Detector;
class Title extends Detector
{
public function detect(): ?string
{
$api = $this->extractor->getApi();
$name = $api->str('includes', 'users', '0', 'name');
if ($name) {
return "Tweet by $name";
}
return parent::detect();
}
}

View file

@ -0,0 +1,31 @@
<?php
declare(strict_types = 1);
namespace Embed\Adapters\Twitter;
use Embed\Extractor as Base;
class Extractor extends Base
{
private Api $api;
public function getApi(): Api
{
return $this->api;
}
public function createCustomDetectors(): array
{
$this->api = new Api($this);
return [
'authorName' => new Detectors\AuthorName($this),
'authorUrl' => new Detectors\AuthorUrl($this),
'description' => new Detectors\Description($this),
'image' => new Detectors\Image($this),
'providerName' => new Detectors\ProviderName($this),
'publishedTime' => new Detectors\PublishedTime($this),
'title' => new Detectors\Title($this),
];
}
}

View file

@ -29,6 +29,7 @@ class ExtractorFactory
'youtube.com' => Adapters\Youtube\Extractor::class,
'twitch.tv' => Adapters\Twitch\Extractor::class,
'bandcamp.com' => Adapters\Bandcamp\Extractor::class,
'twitter.com' => Adapters\Twitter\Extractor::class,
];
private array $customDetectors = [];
private array $settings;

View file

@ -166,7 +166,7 @@ final class CurlDispatcher
case 'user-agent':
break;
default:
$headers[$name] = implode(', ', $values);
$headers[] = $name . ':' . implode(', ', $values);
}
}