mirror of
https://github.com/friendica/friendica
synced 2025-04-30 00:24:24 +02:00
Some more improvements for posts with shares
This commit is contained in:
parent
db82bdfc44
commit
c65fff6f93
10 changed files with 100 additions and 99 deletions
|
@ -680,11 +680,11 @@ class Item
|
|||
$shared_content .= '[h3]' . $item['title'] . "[/h3]\n";
|
||||
}
|
||||
|
||||
$shared = ItemModel::getShareArray($item);
|
||||
$shared = $this->getSharedPost($item, ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network']);
|
||||
|
||||
// If it is a reshared post then reformat it to avoid display problems with two share elements
|
||||
if (!empty($shared)) {
|
||||
if (!empty($shared['guid']) && ($encaspulated_share = self::createSharedPostByGuid($shared['guid'], 0, '', $add_media))) {
|
||||
if (($encaspulated_share = $this->createSharedBlockByArray($shared['post'], $add_media))) {
|
||||
$item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encaspulated_share, $item['body']);
|
||||
}
|
||||
|
||||
|
@ -695,4 +695,38 @@ class Item
|
|||
|
||||
return $shared_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the shared post from an item array (if the item is shared item)
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $fields
|
||||
*
|
||||
* @return array with the shared post
|
||||
*/
|
||||
public function getSharedPost(array $item, array $fields = []): array
|
||||
{
|
||||
if (!empty($item['quote-uri-id'])) {
|
||||
$shared = Post::selectFirst($fields, ['uri-id' => $item['quote-uri-id'], 'uid' => [0, $item['uid'] ?? 0]]);
|
||||
if (is_array($shared)) {
|
||||
return [
|
||||
'comment' => BBCode::removeSharedData($item['body'] ?? ''),
|
||||
'post' => $shared
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$attributes = BBCode::fetchShareAttributes($item['body'] ?? '');
|
||||
if (!empty($attributes)) {
|
||||
$shared = Post::selectFirst($fields, ['guid' => $attributes['guid'], 'uid' => [0, $item['uid'] ?? 0]]);
|
||||
if (is_array($shared)) {
|
||||
return [
|
||||
'comment' => $attributes['comment'],
|
||||
'post' => $shared
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1070,6 +1070,30 @@ class BBCode
|
|||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if the provided body contains a native reshare
|
||||
*
|
||||
* @param string $body
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isNativeReshare(string $body): bool
|
||||
{
|
||||
$shared = BBCode::fetchShareAttributes($body);
|
||||
return !empty($shared['guid'] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided body contains a "share" element
|
||||
*
|
||||
* @param string $body
|
||||
* @return boolean
|
||||
*/
|
||||
public static function existsShare(string $body): bool
|
||||
{
|
||||
$shared = BBCode::fetchShareAttributes($body);
|
||||
return !empty($shared['link'] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the share block with a link
|
||||
*
|
||||
|
@ -1094,7 +1118,7 @@ class BBCode
|
|||
*/
|
||||
public static function removeSharedData(string $body): string
|
||||
{
|
||||
return preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
|
||||
return trim(preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue