Avoid adding the same attachments in shared posts

This commit is contained in:
Michael 2021-04-29 05:45:35 +00:00
parent 8541e248bb
commit 94e36f7970
2 changed files with 28 additions and 18 deletions

View file

@ -447,11 +447,12 @@ class Media
/**
* Split the attachment media in the three segments "visual", "link" and "additional"
*
* @param int $uri_id
* @param int $uri_id
* @param string $guid
* @param array $links ist of links that shouldn't be added
* @return array attachments
*/
public static function splitAttachments(int $uri_id, string $guid = '')
public static function splitAttachments(int $uri_id, string $guid = '', array $links = [])
{
$attachments = ['visual' => [], 'link' => [], 'additional' => []];
@ -464,6 +465,11 @@ class Media
$selected = '';
foreach ($media as $medium) {
$medium['url'] = strtolower($medium['url']);
if (in_array($medium['url'], $links)) {
continue;
}
$type = explode('/', current(explode(';', $medium['mimetype'])));
if (count($type) < 2) {
Logger::info('Unknown MimeType', ['type' => $type, 'media' => $medium]);