From 2ed98bd04056a341fd71ac23ed28d5ab5dd6ac48 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 15 Apr 2021 21:13:20 +0000 Subject: [PATCH 1/3] Prevent false "photo" page detection --- src/Util/ParseUrl.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 70ae2310f9..683544f448 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -349,6 +349,9 @@ class ParseUrl $siteinfo['title'] = trim($list->item(0)->nodeValue); } + $twitter_card = false; + $twitter_image = false; + $list = $xpath->query('//meta[@name]'); foreach ($list as $node) { $meta_tag = []; @@ -376,6 +379,7 @@ class ParseUrl break; case 'twitter:image': $siteinfo['image'] = $meta_tag['content']; + $twitter_image = true; break; case 'twitter:image:src': $siteinfo['image'] = $meta_tag['content']; @@ -383,7 +387,7 @@ class ParseUrl case 'twitter:card': // Detect photo pages if ($meta_tag['content'] == 'summary_large_image') { - $siteinfo['type'] = 'photo'; + $twitter_card = true; } break; case 'twitter:description': @@ -458,6 +462,7 @@ class ParseUrl break; case 'twitter:image': $siteinfo['image'] = $meta_tag['content']; + $twitter_image = true; break; } } @@ -473,8 +478,8 @@ class ParseUrl } // Prevent to have a photo type without an image - if ((empty($siteinfo['image']) || !empty($siteinfo['text'])) && ($siteinfo['type'] == 'photo')) { - $siteinfo['type'] = 'link'; + if ($twitter_card && $twitter_image && !empty($siteinfo['image'])) { + $siteinfo['type'] = 'photo'; } if (!empty($siteinfo['image'])) { From 676f62c0126ea004a80b17d078dfd300d6517727 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 16 Apr 2021 05:33:52 +0000 Subject: [PATCH 2/3] Returning the correct data in oembed with photos --- src/Content/OEmbed.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index b0b018c1fb..37b8ec4290 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -33,6 +33,7 @@ use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Util\DateTimeFormat; +use Friendica\Util\Images; use Friendica\Util\Network; use Friendica\Util\ParseUrl; use Friendica\Util\Proxy as ProxyUtils; @@ -162,7 +163,13 @@ class OEmbed $oembed->type = $data['type']; if ($oembed->type == 'photo') { - $oembed->url = $data['url']; + if (!empty($data['images'])) { + $oembed->url = $data['images'][0]['src']; + $oembed->width = $data['images'][0]['width']; + $oembed->height = $data['images'][0]['height']; + } else { + $oembed->type = 'link'; + } } } @@ -190,7 +197,7 @@ class OEmbed $oembed->author_url = $data['author_url']; } - if (!empty($data['images'])) { + if (!empty($data['images']) && ($oembed->type != 'photo')) { $oembed->thumbnail_url = $data['images'][0]['src']; $oembed->thumbnail_width = $data['images'][0]['width']; $oembed->thumbnail_height = $data['images'][0]['height']; From 346714eb8809915c00c45225cff4421251f4b7cd Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 16 Apr 2021 14:30:08 +0000 Subject: [PATCH 3/3] Unneded class removed --- src/Content/OEmbed.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 37b8ec4290..65b450f51e 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -33,7 +33,6 @@ use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Images; use Friendica\Util\Network; use Friendica\Util\ParseUrl; use Friendica\Util\Proxy as ProxyUtils;