mirror of
https://github.com/friendica/friendica
synced 2024-11-13 16:22:53 +00:00
Issue 10019: Fix embedding of media objects
This commit is contained in:
parent
60a74fd5dc
commit
262ee2b0b1
3 changed files with 34 additions and 7 deletions
|
@ -2257,10 +2257,10 @@ class BBCode
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
$siteinfo = ParseUrl::getSiteinfoCached($url);
|
$type = ParseUrl::getContentType($url);
|
||||||
|
|
||||||
if (in_array($siteinfo['type'], ['image', 'video', 'audio'])) {
|
if (in_array($type, ['image', 'video', 'audio'])) {
|
||||||
switch ($siteinfo['type']) {
|
switch ($type) {
|
||||||
case 'video':
|
case 'video':
|
||||||
$bbcode = "\n" . '[video]' . $url . '[/video]' . "\n";
|
$bbcode = "\n" . '[video]' . $url . '[/video]' . "\n";
|
||||||
break;
|
break;
|
||||||
|
@ -2275,6 +2275,8 @@ class BBCode
|
||||||
return $bbcode;
|
return $bbcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$siteinfo = ParseUrl::getSiteinfoCached($url);
|
||||||
|
|
||||||
unset($siteinfo['keywords']);
|
unset($siteinfo['keywords']);
|
||||||
|
|
||||||
// Bypass attachment if parse url for a comment
|
// Bypass attachment if parse url for a comment
|
||||||
|
|
|
@ -94,11 +94,10 @@ class ParseUrl extends BaseModule
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($format == 'json') {
|
if ($format == 'json') {
|
||||||
$siteinfo = Util\ParseUrl::getSiteinfoCached($url);
|
$type = Util\ParseUrl::getContentType($url);
|
||||||
|
|
||||||
if (empty($siteinfo['title']) && empty($siteinfo['text']) && empty($siteinfo['image'])
|
if (in_array($type, ['image', 'video', 'audio'])) {
|
||||||
&& in_array($siteinfo['type'], ['image', 'video', 'audio'])) {
|
switch ($type) {
|
||||||
switch ($siteinfo['type']) {
|
|
||||||
case 'video':
|
case 'video':
|
||||||
$content_type = 'video';
|
$content_type = 'video';
|
||||||
break;
|
break;
|
||||||
|
@ -114,6 +113,8 @@ class ParseUrl extends BaseModule
|
||||||
$ret['data'] = ['url' => $url];
|
$ret['data'] = ['url' => $url];
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
} else {
|
} else {
|
||||||
|
$siteinfo = Util\ParseUrl::getSiteinfoCached($url);
|
||||||
|
|
||||||
unset($siteinfo['keywords']);
|
unset($siteinfo['keywords']);
|
||||||
|
|
||||||
$ret['data'] = $siteinfo;
|
$ret['data'] = $siteinfo;
|
||||||
|
|
|
@ -51,6 +51,30 @@ class ParseUrl
|
||||||
*/
|
*/
|
||||||
const MIN_DESC_COUNT = 100;
|
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
|
* Search for chached embeddable data of an url otherwise fetch it
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue