Avoid empty posts on Diaspora

This commit is contained in:
Michael 2021-04-30 22:35:16 +00:00
parent 3666742e7b
commit c840ee82af
4 changed files with 13 additions and 9 deletions

View file

@ -526,15 +526,19 @@ class Media
* Add media attachments to the body
*
* @param int $uriid
* @param string $body
* @return string body
*/
public static function addAttachmentsToBody(int $uriid)
public static function addAttachmentsToBody(int $uriid, string $body = '')
{
$item = Post::selectFirst(['body'], ['uri-id' => $uriid]);
if (!DBA::isResult($item)) {
return '';
if (empty($body)) {
$item = Post::selectFirst(['body'], ['uri-id' => $uriid]);
if (!DBA::isResult($item)) {
return '';
}
$body = $item['body'];
}
$body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $item['body']);
$body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body);
foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) {
if (Item::containsLink($body, $media['url'])) {