Integrate fetching of the content type into "getSiteinfo"

This commit is contained in:
Michael 2021-03-13 07:03:26 +00:00
parent 262ee2b0b1
commit ffb92e3355
3 changed files with 13 additions and 11 deletions

View File

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

View File

@ -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;

View File

@ -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;
}