mirror of
https://github.com/friendica/friendica
synced 2025-04-26 23:50:11 +00:00
Issue 11963: Set Permissions for attachments
This commit is contained in:
parent
ee9510e17d
commit
567292533e
5 changed files with 90 additions and 65 deletions
|
@ -28,6 +28,7 @@ use Friendica\Core\Protocol;
|
|||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Attach;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\ItemURI;
|
||||
|
@ -389,6 +390,16 @@ class Media
|
|||
*/
|
||||
private static function fetchLocalData(array $media): array
|
||||
{
|
||||
if (preg_match('|.*?/attach/(\d+)|', $media['url'] ?? '', $matches)) {
|
||||
$attachment = Attach::selectFirst(['filename', 'filetype', 'filesize'], ['id' => $matches[1]]);
|
||||
if (!empty($attachment)) {
|
||||
$media['name'] = $attachment['filename'];
|
||||
$media['mimetype'] = $attachment['filetype'];
|
||||
$media['size'] = $attachment['filesize'];
|
||||
}
|
||||
return $media;
|
||||
}
|
||||
|
||||
if (!preg_match('|.*?/photo/(.*[a-fA-F0-9])\-(.*[0-9])\..*[\w]|', $media['url'] ?? '', $matches)) {
|
||||
return $media;
|
||||
}
|
||||
|
@ -902,19 +913,7 @@ class Media
|
|||
$body = BBCode::removeAttachment($body);
|
||||
|
||||
foreach (self::getByURIId($uriid, $types) as $media) {
|
||||
if (Item::containsLink($body, $media['preview'] ?? $media['url'], $media['type'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($media['type'] == self::IMAGE) {
|
||||
$body .= "\n" . Images::getBBCodeByUrl($media['url'], $media['preview'], $media['description'] ?? '');
|
||||
} elseif ($media['type'] == self::AUDIO) {
|
||||
$body .= "\n[audio]" . $media['url'] . "[/audio]\n";
|
||||
} elseif ($media['type'] == self::VIDEO) {
|
||||
$body .= "\n[video]" . $media['url'] . "[/video]\n";
|
||||
} else {
|
||||
$body .= "\n[url]" . $media['url'] . "[/url]\n";
|
||||
}
|
||||
$body = self::addAttachmentToBody($media, $body);
|
||||
}
|
||||
|
||||
if (preg_match("/.*(\[attachment.*?\].*?\[\/attachment\]).*/ism", $original_body, $match)) {
|
||||
|
@ -924,6 +923,24 @@ class Media
|
|||
return $body;
|
||||
}
|
||||
|
||||
public static function addAttachmentToBody(array $media, string $body): string
|
||||
{
|
||||
if (Item::containsLink($body, $media['preview'] ?? $media['url'], $media['type'])) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
if ($media['type'] == self::IMAGE) {
|
||||
$body .= "\n" . Images::getBBCodeByUrl($media['url'], $media['preview'], $media['description'] ?? '');
|
||||
} elseif ($media['type'] == self::AUDIO) {
|
||||
$body .= "\n[audio]" . $media['url'] . "[/audio]\n";
|
||||
} elseif ($media['type'] == self::VIDEO) {
|
||||
$body .= "\n[video]" . $media['url'] . "[/video]\n";
|
||||
} else {
|
||||
$body .= "\n[url]" . $media['url'] . "[/url]\n";
|
||||
}
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an [attachment] element to the body for a given uri-id with a HTML media element
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue