mirror of
https://github.com/friendica/friendica
synced 2025-04-26 22:30:18 +00:00
Improved link detection
This commit is contained in:
parent
af5fa6ce00
commit
77e1ec6df2
3 changed files with 36 additions and 7 deletions
|
@ -286,6 +286,8 @@ class Media
|
|||
// Simplify image codes
|
||||
$body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
|
||||
|
||||
$unshared_body = preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
|
||||
|
||||
$attachments = [];
|
||||
if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]\s*\[/url\]#ism", $body, $pictures, PREG_SET_ORDER)) {
|
||||
foreach ($pictures as $picture) {
|
||||
|
@ -346,7 +348,10 @@ class Media
|
|||
}
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
self::insert($attachment);
|
||||
// Only store attachments that are part of the unshared body
|
||||
if (strpos($unshared_body, $attachment['url']) !== false) {
|
||||
self::insert($attachment);
|
||||
}
|
||||
}
|
||||
|
||||
return trim($body);
|
||||
|
@ -360,6 +365,9 @@ class Media
|
|||
*/
|
||||
public static function insertFromAttachmentData(int $uriid, string $body)
|
||||
{
|
||||
// Don't look at the shared content
|
||||
$body = preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
|
||||
|
||||
$data = BBCode::getAttachmentData($body);
|
||||
if (empty($data)) {
|
||||
return;
|
||||
|
@ -548,10 +556,18 @@ class Media
|
|||
}
|
||||
|
||||
if ($media['type'] == self::IMAGE) {
|
||||
if (!empty($media['description'])) {
|
||||
$body .= "\n[img=" . $media['url'] . ']' . $media['description'] .'[/img]';
|
||||
if (!empty($media['preview'])) {
|
||||
if (!empty($media['description'])) {
|
||||
$body .= "\n[url=" . $media['url'] . "][img=" . $media['preview'] . ']' . $media['description'] .'[/img][/url]';
|
||||
} else {
|
||||
$body .= "\n[url=" . $media['url'] . "][img]" . $media['preview'] .'[/img][/url]';
|
||||
}
|
||||
} else {
|
||||
$body .= "\n[img]" . $media['url'] .'[/img]';
|
||||
if (!empty($media['description'])) {
|
||||
$body .= "\n[img=" . $media['url'] . ']' . $media['description'] .'[/img]';
|
||||
} else {
|
||||
$body .= "\n[img]" . $media['url'] .'[/img]';
|
||||
}
|
||||
}
|
||||
} elseif ($media['type'] == self::AUDIO) {
|
||||
$body .= "\n[audio]" . $media['url'] . "[/audio]\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue