if ($format == 'json') {
$siteinfo = Util\ParseUrl::getSiteinfoCached($url);
- if (empty($siteinfo['title']) && empty($siteinfo['text']) && empty($siteinfo['image'])
- && in_array($siteinfo['type'], ['image', 'video', 'audio'])) {
+ if (in_array($siteinfo['type'], ['image', 'video', 'audio'])) {
switch ($siteinfo['type']) {
case 'video':
$content_type = 'video';
*/
const MIN_DESC_COUNT = 100;
+ /**
+ * Fetch the content type of the given url
+ * @param string $url URL of the page
+ * @return string content type
+ */
+ public static function getContentType(string $url)
+ {
+ $curlResult = DI::httpRequest()->head($url);
+ if (!$curlResult->isSuccess()) {
+ return '';
+ }
+
+ $contenttype = $curlResult->getHeader('Content-Type');
+ if (empty($contenttype)) {
+ return '';
+ }
+
+ if (!preg_match('#(image|video|audio)/#i', $contenttype, $matches)) {
+ return '';
+ }
+
+ return array_pop($matches);
+ }
+
/**
* Search for chached embeddable data of an url otherwise fetch it
*
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;
$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;
}