Detect linked posts and add them as quote

This commit is contained in:
Michael 2022-10-16 21:37:05 +00:00
parent 1585f711ee
commit f8f0dfa91a
6 changed files with 115 additions and 23 deletions

View file

@ -608,9 +608,10 @@ class Item
*
* @param integer $UriId
* @param integer $uid
* @param bool $add_media
* @return string
*/
public function createSharedPostByUriId(int $UriId, int $uid = 0): string
public function createSharedPostByUriId(int $UriId, int $uid = 0, bool $add_media = false): string
{
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network'];
$shared_item = Post::selectFirst($fields, ['uri-id' => $UriId, 'uid' => [$uid, 0], 'private' => [ModelItem::PUBLIC, ModelItem::UNLISTED]]);
@ -619,7 +620,7 @@ class Item
return '';
}
return $this->createSharedBlockByArray($shared_item);
return $this->createSharedBlockByArray($shared_item, $add_media);
}
/**
@ -627,9 +628,10 @@ class Item
*
* @param string $guid
* @param integer $uid
* @param bool $add_media
* @return string
*/
public function createSharedPostByGuid(string $guid, int $uid = 0, string $host = ''): string
public function createSharedPostByGuid(string $guid, int $uid = 0, string $host = '', bool $add_media = false): string
{
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network'];
$shared_item = Post::selectFirst($fields, ['guid' => $guid, 'uid' => [$uid, 0], 'private' => [ModelItem::PUBLIC, ModelItem::UNLISTED]]);
@ -646,7 +648,7 @@ class Item
return '';
}
return $this->createSharedBlockByArray($shared_item);
return $this->createSharedBlockByArray($shared_item, $add_media);
}
/**
@ -678,7 +680,7 @@ class Item
// If it is a reshared post then reformat it to avoid display problems with two share elements
if (Diaspora::isReshare($item['body'], false)) {
if (!empty($shared['guid']) && ($encaspulated_share = self::createSharedPostByGuid($shared['guid']))) {
if (!empty($shared['guid']) && ($encaspulated_share = self::createSharedPostByGuid($shared['guid'], 0, '', $add_media))) {
$item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encaspulated_share, $item['body']);
}