From ffb92e3355883e2ed2228057c3ad95c4f028912f Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 13 Mar 2021 07:03:26 +0000 Subject: [PATCH] Integrate fetching of the content type into "getSiteinfo" --- src/Content/Text/BBCode.php | 8 +++----- src/Module/ParseUrl.php | 8 +++----- src/Util/ParseUrl.php | 8 +++++++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 0b49e75a0e..9973705855 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -2257,10 +2257,10 @@ class BBCode return $result; } - $type = ParseUrl::getContentType($url); + $siteinfo = ParseUrl::getSiteinfoCached($url); - if (in_array($type, ['image', 'video', 'audio'])) { - switch ($type) { + if (in_array($siteinfo['type'], ['image', 'video', 'audio'])) { + switch ($siteinfo['type']) { case 'video': $bbcode = "\n" . '[video]' . $url . '[/video]' . "\n"; break; @@ -2275,8 +2275,6 @@ class BBCode return $bbcode; } - $siteinfo = ParseUrl::getSiteinfoCached($url); - unset($siteinfo['keywords']); // Bypass attachment if parse url for a comment diff --git a/src/Module/ParseUrl.php b/src/Module/ParseUrl.php index 7138238d85..ed48ea1b26 100644 --- a/src/Module/ParseUrl.php +++ b/src/Module/ParseUrl.php @@ -94,10 +94,10 @@ class ParseUrl extends BaseModule } if ($format == 'json') { - $type = Util\ParseUrl::getContentType($url); + $siteinfo = Util\ParseUrl::getSiteinfoCached($url); - if (in_array($type, ['image', 'video', 'audio'])) { - switch ($type) { + if (in_array($siteinfo['type'], ['image', 'video', 'audio'])) { + switch ($siteinfo['type']) { case 'video': $content_type = 'video'; break; @@ -113,8 +113,6 @@ class ParseUrl extends BaseModule $ret['data'] = ['url' => $url]; $ret['success'] = true; } else { - $siteinfo = Util\ParseUrl::getSiteinfoCached($url); - unset($siteinfo['keywords']); $ret['data'] = $siteinfo; diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index a634545cd7..83d0d84dc9 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -210,6 +210,12 @@ class ParseUrl return $siteinfo; } + $type = self::getContentType($url); + if (in_array($type, ['image', 'video', 'audio'])) { + $siteinfo['type'] = $type; + return $siteinfo; + } + $curlResult = DI::httpRequest()->get($url); if (!$curlResult->isSuccess()) { return $siteinfo; @@ -251,7 +257,7 @@ class ParseUrl $oembed_data = OEmbed::fetchURL($url); if (!empty($oembed_data->type)) { - if (!in_array($oembed_data->type, ['error', 'rich', ''])) { + if (!in_array($oembed_data->type, ['error', 'rich', 'image', 'video', 'audio', ''])) { $siteinfo['type'] = $oembed_data->type; }