Integrate fetching of the content type into "getSiteinfo"
authorMichael <heluecht@pirati.ca>
Sat, 13 Mar 2021 07:03:26 +0000 (07:03 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 13 Mar 2021 07:03:26 +0000 (07:03 +0000)
src/Content/Text/BBCode.php
src/Module/ParseUrl.php
src/Util/ParseUrl.php

index 0b49e75..9973705 100644 (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
index 7138238..ed48ea1 100644 (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;
index a634545..83d0d84 100644 (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;
                                }