Skip to content

Commit

Permalink
Fixed redirection urls
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed May 25, 2020
1 parent e20b821 commit 1640d64
Show file tree
Hide file tree
Showing 10 changed files with 736 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,10 @@ 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.2.1] - 2020-05-25
### Fixed
- Redirect urls like `t.co`.

## [4.2.0] - 2020-05-23
### Added
- Added the `ignored_errors` settings to ignore some curls errors instead throw an exception [#355]
Expand Down Expand Up @@ -56,6 +60,7 @@ Full library refactoring.
[#355]: https://github.com/oscarotero/Embed/issues/355
[#356]: https://github.com/oscarotero/Embed/issues/356

[4.2.1]: https://github.com/oscarotero/Embed/compare/v4.2.0...v4.2.1
[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
2 changes: 1 addition & 1 deletion src/Detectors/Redirect.php
Expand Up @@ -10,7 +10,7 @@ class Redirect extends Detector
public function detect(): ?UriInterface
{
$document = $this->extractor->getDocument();
$value = $document->select('.//meta', ['http-equiv' => 'refresh'])->str();
$value = $document->select('.//meta', ['http-equiv' => 'refresh'])->str('content');

return $value ? $this->extract($value) : null;
}
Expand Down
1 change: 1 addition & 0 deletions tests/PagesTest.php
Expand Up @@ -168,6 +168,7 @@ public function testTwitch()
public function testTwitter()
{
$this->assertEmbed('https://twitter.com/pepephone/status/436461658601713664');
$this->assertEmbed('https://t.co/4DK3Jc2BTt');
}

public function testTikTok()
Expand Down
258 changes: 258 additions & 0 deletions tests/cache/buff.ly.2usohds.php

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions tests/cache/t.co.4dk3jc2btt.php
@@ -0,0 +1,55 @@
<?php
declare(strict_types = 1);

return [
'headers' => [
'cache-control' => [
'private,max-age=300'
],
'content-encoding' => [
'gzip'
],
'content-length' => [
'177'
],
'content-type' => [
'text/html; charset=utf-8'
],
'date' => [
'Mon, 25 May 2020 12:14:51 GMT'
],
'expires' => [
'Mon, 25 May 2020 12:19:51 GMT'
],
'server' => [
'tsa_f'
],
'set-cookie' => [
'muc=309dc6f1-7be6-4358-9a6b-8160b5741e97; Max-Age=63072000; Expires=Wed, 25 May 2022 12:14:51 GMT; Domain=t.co; Secure; SameSite=None'
],
'strict-transport-security' => [
'max-age=0'
],
'vary' => [
'Origin'
],
'x-connection-hash' => [
'3d9a006e278127b0557f8feef2737c10'
],
'x-response-time' => [
'122'
],
'x-xss-protection' => [
'0'
],
'Content-Location' => [
'https://t.co/4DK3Jc2BTt'
],
'X-Request-Time' => [
'0.340 ms'
]
],
'statusCode' => 200,
'reasonPhrase' => 'OK',
'body' => '<head><noscript><META http-equiv="refresh" content="0;URL=https://buff.ly/2uSOHDs"></noscript><title>https://buff.ly/2uSOHDs</title></head><script>window.opener = null; location.replace("https:\\/\\/buff.ly\\/2uSOHDs")</script>'
];

Large diffs are not rendered by default.

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions tests/fixtures/buff.ly.2usohds.php
@@ -0,0 +1,96 @@
<?php
declare(strict_types = 1);

return [
'authorName' => '@graffica_info',
'authorUrl' => 'https://twitter.com/graffica_info',
'cms' => null,
'code' => null,
'description' => 'El lenguaje, sea cual sea el idioma, siempre esconde entre los orígenes de sus palabras muchas curiosidades. Este es el caso del origen del ampersand.',
'favicon' => 'https://graffica.info/favicon.ico',
'feeds' => [
'https://graffica.info/feed/'
],
'icon' => null,
'image' => 'https://graffica.info/wp-content/uploads/2020/02/el-origen-de-la-Ampersand-destacado.jpg',
'keywords' => [],
'language' => 'es',
'languages' => [],
'license' => null,
'providerName' => 'Gràffica',
'providerUrl' => 'https://graffica.info',
'publishedTime' => '2020-02-20 09:30:00',
'redirect' => null,
'title' => 'El origen del ampersand que desconocen muchos diseñadores',
'url' => 'https://graffica.info/sabes-cual-es-el-origen-del-ampersand/',
'linkedData' => [
'@context' => 'https://schema.org',
'@graph' => [
[
'@type' => 'WebSite',
'@id' => 'https://graffica.info/#website',
'url' => 'https://graffica.info/',
'name' => 'Gràffica',
'description' => 'Revista de noticias del mundo del diseño, en especial del diseño gráfico, la creatividad y la cultura visual. Tipografía, ilustración, branding y mucho más.',
'potentialAction' => [
[
'@type' => 'SearchAction',
'target' => 'https://graffica.info/?s={search_term_string}',
'query-input' => 'required name=search_term_string'
]
],
'inLanguage' => 'es'
],
[
'@type' => 'ImageObject',
'@id' => 'https://graffica.info/sabes-cual-es-el-origen-del-ampersand/#primaryimage',
'inLanguage' => 'es',
'url' => 'https://graffica.info/wp-content/uploads/2020/02/el-origen-de-la-Ampersand-destacado.jpg',
'width' => 1000,
'height' => 659
],
[
'@type' => 'WebPage',
'@id' => 'https://graffica.info/sabes-cual-es-el-origen-del-ampersand/#webpage',
'url' => 'https://graffica.info/sabes-cual-es-el-origen-del-ampersand/',
'name' => 'El origen del ampersand que desconocen muchos diseñadores',
'isPartOf' => [
'@id' => 'https://graffica.info/#website'
],
'primaryImageOfPage' => [
'@id' => 'https://graffica.info/sabes-cual-es-el-origen-del-ampersand/#primaryimage'
],
'datePublished' => '2020-02-20T09:30:00+00:00',
'dateModified' => '2020-02-20T09:17:48+00:00',
'author' => [
'@id' => 'https://graffica.info/#/schema/person/e061170e01040cb6444c3edea24a464b'
],
'description' => 'El lenguaje, sea cual sea el idioma, siempre esconde entre los orígenes de sus palabras muchas curiosidades. Este es el caso del origen del ampersand.',
'inLanguage' => 'es',
'potentialAction' => [
[
'@type' => 'ReadAction',
'target' => [
'https://graffica.info/sabes-cual-es-el-origen-del-ampersand/'
]
]
]
],
[
'@type' => [
'Person'
],
'@id' => 'https://graffica.info/#/schema/person/e061170e01040cb6444c3edea24a464b',
'name' => 'Gràffica',
'image' => [
'@type' => 'ImageObject',
'@id' => 'https://graffica.info/#personlogo',
'inLanguage' => 'es',
'url' => 'https://secure.gravatar.com/avatar/3149311a3c04959ac810d7ff614188f1?s=96&d=mm&r=g',
'caption' => 'Gràffica'
]
]
]
],
'oEmbed' => []
];
@@ -0,0 +1,93 @@
<?php
declare(strict_types = 1);

return [
'authorName' => 'Acolono GmbH',
'authorUrl' => 'https://www.facebook.com/acolono/',
'cms' => null,
'code' => [
'html' => '<div id="fb-root"></div> <script async="1" defer="1" crossorigin="anonymous" src="https://connect.facebook.net/es_ES/sdk.js#xfbml=1&amp;version=v7.0"></script><div class="fb-video" data-href="https://www.facebook.com/acolono/videos/10154107990797381/"><blockquote cite="https://www.facebook.com/acolono/videos/10154107990797381/" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/acolono/videos/10154107990797381/"></a><p>Eindrücke vom gestrigen Drupal Austria Meetup bei uns im Büro :) Wir haben die beste Community!</p>Publicada por <a href="https://www.facebook.com/acolono/">Acolono GmbH</a> en Jueves, 12 de mayo de 2016</blockquote></div>',
'width' => 500,
'height' => 901
],
'description' => 'Eindrücke vom gestrigen Drupal Austria Meetup bei uns im Büro :) Wir haben die beste Community!',
'favicon' => 'https://static.xx.fbcdn.net/rsrc.php/yo/r/iRmz9lCMBD2.ico',
'feeds' => [],
'icon' => null,
'image' => 'https://scontent.fmad7-1.fna.fbcdn.net/v/t15.5256-10/p200x200/12672727_10154107996122381_1769309167_n.jpg?_nc_cat=110&_nc_sid=ad6a45&_nc_ohc=H5axAn5YdXsAX_e6Lzx&_nc_ht=scontent.fmad7-1.fna&_nc_tp=6&oh=2c06ee1e270f11ec4df87d1a55020804&oe=5EF1D1EE',
'keywords' => [],
'language' => 'es',
'languages' => [],
'license' => null,
'providerName' => 'Facebook',
'providerUrl' => 'https://www.facebook.com/',
'publishedTime' => null,
'redirect' => null,
'title' => 'Acolono GmbH - Eindrücke vom gestrigen Drupal Austria...',
'url' => 'https://www.facebook.com/acolono/videos/10154107990797381/',
'linkedData' => [
'@context' => 'https://schema.org',
'@type' => 'VideoObject',
'name' => 'Acolono GmbH - Eindrücke vom gestrigen Drupal Austria...',
'description' => 'Eindrücke vom gestrigen Drupal Austria Meetup bei uns im Büro :) Wir haben die beste Community!',
'thumbnailUrl' => 'https://scontent.fmad7-1.fna.fbcdn.net/v/t15.5256-10/12672727_10154107996122381_1769309167_n.jpg?_nc_cat=110&_nc_sid=08861d&_nc_ohc=H5axAn5YdXsAX_e6Lzx&_nc_ht=scontent.fmad7-1.fna&oh=408eec961f6799604dbf1faf96633eca&oe=5EF1FFC0',
'duration' => 'T1M1S',
'uploadDate' => '2016-05-12T06:52:59-07:00',
'contentUrl' => 'https://video.fmad7-1.fna.fbcdn.net/v/t42.1790-2/13223999_1021353087901725_2023377136_n.mp4?_nc_cat=109&_nc_sid=985c63&efg=eyJybHIiOjMwMCwicmxhIjo1MTIsInZlbmNvZGVfdGFnIjoic3ZlX3NkIn0%3D&_nc_ohc=ieZd8VLy45AAX9__EdF&rl=300&vabr=152&_nc_ht=video.fmad7-1.fna&oh=3a708437f011a6250a4113c8671e1079&oe=5ECBD9B6',
'interactionCount' => 112,
'publication' => [
[
'@type' => 'BroadcastEvent',
'isLiveBroadcast' => false
]
],
'@id' => 'https://video.fmad7-1.fna.fbcdn.net/v/t42.1790-2/13223999_1021353087901725_2023377136_n.mp4?_nc_cat=109&_nc_sid=985c63&efg=eyJybHIiOjMwMCwicmxhIjo1MTIsInZlbmNvZGVfdGFnIjoic3ZlX3NkIn0%3D&_nc_ohc=ieZd8VLy45AAX9__EdF&rl=300&vabr=152&_nc_ht=video.fmad7-1.fna&oh=3a708437f011a6250a4113c8671e1079&oe=5ECBD9B6',
'url' => 'https://video.fmad7-1.fna.fbcdn.net/v/t42.1790-2/13223999_1021353087901725_2023377136_n.mp4?_nc_cat=109&_nc_sid=985c63&efg=eyJybHIiOjMwMCwicmxhIjo1MTIsInZlbmNvZGVfdGFnIjoic3ZlX3NkIn0%3D&_nc_ohc=ieZd8VLy45AAX9__EdF&rl=300&vabr=152&_nc_ht=video.fmad7-1.fna&oh=3a708437f011a6250a4113c8671e1079&oe=5ECBD9B6',
'datePublished' => '2016-05-12T06:52:59-07:00',
'width' => 320,
'height' => 576,
'thumbnail' => [
'@type' => 'ImageObject',
'contentUrl' => 'https://scontent.fmad7-1.fna.fbcdn.net/v/t15.5256-10/12672727_10154107996122381_1769309167_n.jpg?_nc_cat=110&_nc_sid=08861d&_nc_ohc=H5axAn5YdXsAX_e6Lzx&_nc_ht=scontent.fmad7-1.fna&oh=408eec961f6799604dbf1faf96633eca&oe=5EF1FFC0',
'width' => 320,
'height' => 576
],
'headline' => 'Acolono GmbH - Eindrücke vom gestrigen Drupal Austria...',
'isFamilyFriendly' => true,
'keywords' => 'Acolono GmbH',
'commentCount' => 0,
'inLanguage' => 'de',
'contentSize' => '5261.361kB',
'videoQuality' => '270p',
'author' => [
'@type' => 'Organization',
'name' => 'Acolono GmbH',
'url' => 'https://www.facebook.com/acolono/'
],
'publisher' => [
'@type' => 'Organization',
'logo' => [
'@type' => 'ImageObject',
'url' => 'https://scontent.fmad7-1.fna.fbcdn.net/v/t1.0-1/p200x200/10440698_10152746215257381_1707589563651819460_n.png?_nc_cat=106&_nc_sid=dbb9e7&_nc_ohc=iki5GvdExDAAX9gpcHG&_nc_ht=scontent.fmad7-1.fna&oh=11cd9277a3a18cb0ec0bcc6987664a9c&oe=5EF20E9A'
],
'name' => 'Acolono GmbH',
'url' => 'https://www.facebook.com/acolono/'
],
'about' => 'Eindrücke vom gestrigen Drupal Austria Meetup bei uns im Büro :) Wir haben die beste Community!',
'transcript' => null
],
'oEmbed' => [
'author_name' => 'Acolono GmbH',
'author_url' => 'https://www.facebook.com/acolono/',
'provider_url' => 'https://www.facebook.com',
'provider_name' => 'Facebook',
'success' => true,
'height' => 901,
'html' => '<div id="fb-root"></div>
<script async="1" defer="1" crossorigin="anonymous" src="https://connect.facebook.net/es_ES/sdk.js#xfbml=1&amp;version=v7.0"></script><div class="fb-video" data-href="https://www.facebook.com/acolono/videos/10154107990797381/"><blockquote cite="https://www.facebook.com/acolono/videos/10154107990797381/" class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/acolono/videos/10154107990797381/"></a><p>Eindrücke vom gestrigen Drupal Austria Meetup bei uns im Büro :) Wir haben die beste Community!</p>Publicada por <a href="https://www.facebook.com/acolono/">Acolono GmbH</a> en Jueves, 12 de mayo de 2016</blockquote></div>',
'type' => 'video',
'version' => '1.0',
'url' => 'https://www.facebook.com/acolono/videos/10154107990797381/',
'width' => 500
]
];
@@ -0,0 +1,46 @@
<?php
declare(strict_types = 1);

return [
'authorName' => 'DAG, Asociación Galega de Deseño',
'authorUrl' => 'https://www.facebook.com/asociaciondag/',
'cms' => null,
'code' => [
'html' => '<div id="fb-root"></div> <script async="1" defer="1" crossorigin="anonymous" src="https://connect.facebook.net/es_ES/sdk.js#xfbml=1&amp;version=v7.0"></script><div class="fb-post" data-href="https://www.facebook.com/asociaciondag/posts/827163017327807" data-width="552"><blockquote cite="https://www.facebook.com/asociaciondag/posts/827163017327807" class="fb-xfbml-parse-ignore"><p>Aquí vos deixamos unhas imaxes da nosa visita do pasado sábado á Guarda. Moi agradecidos á Asociación Naturalista do Baixo Miño www.anabam.org e a Malde Arqueoloxía</p>Publicada por <a href="https://www.facebook.com/asociaciondag/">DAG, Asociación Galega de Deseño</a> en&nbsp;<a href="https://www.facebook.com/asociaciondag/posts/827163017327807">Martes, 21 de octubre de 2014</a></blockquote></div>',
'width' => 552,
'height' => null
],
'description' => 'Aquí vos deixamos unhas imaxes da nosa visita do pasado sábado á Guarda. Moi agradecidos á Asociación Naturalista do Baixo Miño www.anabam.org e a Malde Arqueoloxía',
'favicon' => 'https://static.xx.fbcdn.net/rsrc.php/yo/r/iRmz9lCMBD2.ico',
'feeds' => [],
'icon' => null,
'image' => 'https://scontent.fmad7-1.fna.fbcdn.net/v/t31.0-8/10704334_827161517327957_5105556928960502376_o.jpg?_nc_cat=111&_nc_sid=8024bb&_nc_ohc=1Tupk385RV8AX9dOJv1&_nc_ht=scontent.fmad7-1.fna&oh=e0e8f81989b1ade9c9e12c3a4a211cba&oe=5EF11523',
'keywords' => [],
'language' => 'es',
'languages' => [
'x-default' => 'https://www.facebook.com/149460691764713/posts/aqu%C3%AD-vos-deixamos-unhas-imaxes-da-nosa-visita-do-pasado-s%C3%A1bado-%C3%A1-guarda-moi-agra/827163017327807/',
'en' => 'https://www.facebook.com/149460691764713/posts/aqu%C3%AD-vos-deixamos-unhas-imaxes-da-nosa-visita-do-pasado-s%C3%A1bado-%C3%A1-guarda-moi-agra/827163017327807/'
],
'license' => null,
'providerName' => 'Facebook',
'providerUrl' => 'https://www.facebook.com/',
'publishedTime' => null,
'redirect' => null,
'title' => 'Aquí vos deixamos unhas imaxes da nosa... - DAG, Asociación Galega de Deseño | Facebook',
'url' => 'https://www.facebook.com/asociaciondag/posts/827163017327807',
'linkedData' => [],
'oEmbed' => [
'author_name' => 'DAG, Asociación Galega de Deseño',
'author_url' => 'https://www.facebook.com/asociaciondag/',
'provider_url' => 'https://www.facebook.com',
'provider_name' => 'Facebook',
'success' => true,
'height' => null,
'html' => '<div id="fb-root"></div>
<script async="1" defer="1" crossorigin="anonymous" src="https://connect.facebook.net/es_ES/sdk.js#xfbml=1&amp;version=v7.0"></script><div class="fb-post" data-href="https://www.facebook.com/asociaciondag/posts/827163017327807" data-width="552"><blockquote cite="https://www.facebook.com/asociaciondag/posts/827163017327807" class="fb-xfbml-parse-ignore"><p>Aquí vos deixamos unhas imaxes da nosa visita do pasado sábado á Guarda. Moi agradecidos á Asociación Naturalista do Baixo Miño www.anabam.org e a Malde Arqueoloxía</p>Publicada por <a href="https://www.facebook.com/asociaciondag/">DAG, Asociación Galega de Deseño</a> en&nbsp;<a href="https://www.facebook.com/asociaciondag/posts/827163017327807">Martes, 21 de octubre de 2014</a></blockquote></div>',
'type' => 'rich',
'version' => '1.0',
'url' => 'https://www.facebook.com/asociaciondag/posts/827163017327807',
'width' => 552
]
];

0 comments on commit 1640d64

Please sign in to comment.