mirror of
https://github.com/friendica/friendica
synced 2025-04-27 20:30:13 +00:00
More functions moved to content class
This commit is contained in:
parent
c65fff6f93
commit
deccea0228
10 changed files with 113 additions and 59 deletions
|
@ -680,11 +680,11 @@ class Item
|
|||
$shared_content .= '[h3]' . $item['title'] . "[/h3]\n";
|
||||
}
|
||||
|
||||
$shared = $this->getSharedPost($item, ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network']);
|
||||
$shared = $this->getShareArray($item);
|
||||
|
||||
// If it is a reshared post then reformat it to avoid display problems with two share elements
|
||||
if (!empty($shared)) {
|
||||
if (($encaspulated_share = $this->createSharedBlockByArray($shared['post'], $add_media))) {
|
||||
if (!empty($shared['guid']) && ($encaspulated_share = $this->createSharedPostByGuid($shared['guid'], 0, '', $add_media))) {
|
||||
$item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encaspulated_share, $item['body']);
|
||||
}
|
||||
|
||||
|
@ -729,4 +729,71 @@ class Item
|
|||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Improve the data in shared posts
|
||||
*
|
||||
* @param array $item
|
||||
* @param bool $add_media
|
||||
* @return string body
|
||||
*/
|
||||
public function improveSharedDataInBody(array $item, bool $add_media = false): string
|
||||
{
|
||||
$shared = BBCode::fetchShareAttributes($item['body']);
|
||||
if (empty($shared['guid']) && empty($shared['message_id'])) {
|
||||
return $item['body'];
|
||||
}
|
||||
|
||||
$link = $shared['link'] ?: $shared['message_id'];
|
||||
|
||||
if (empty($shared_content)) {
|
||||
$shared_content = $this->createSharedPostByUrl($link, $item['uid'] ?? 0, $add_media);
|
||||
}
|
||||
|
||||
if (empty($shared_content)) {
|
||||
return $item['body'];
|
||||
}
|
||||
|
||||
$item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $shared_content, $item['body']);
|
||||
|
||||
Logger::debug('New shared data', ['uri-id' => $item['uri-id'], 'link' => $link, 'guid' => $item['guid']]);
|
||||
return $item['body'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return share data from an item array (if the item is shared item)
|
||||
* We are providing the complete Item array, because at some time in the future
|
||||
* we hopefully will define these values not in the body anymore but in some item fields.
|
||||
* This function is meant to replace all similar functions in the system.
|
||||
*
|
||||
* @param array $item
|
||||
*
|
||||
* @return array with share information
|
||||
*/
|
||||
private function getShareArray(array $item): array
|
||||
{
|
||||
$attributes = BBCode::fetchShareAttributes($item['body'] ?? '');
|
||||
if (!empty($attributes)) {
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
if (!empty($item['quote-uri-id'])) {
|
||||
$shared = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'uri', 'body'], ['uri-id' => $item['quote-uri-id']]);
|
||||
if (!empty($shared)) {
|
||||
return [
|
||||
'author' => $shared['author-name'],
|
||||
'profile' => $shared['author-link'],
|
||||
'avatar' => $shared['author-avatar'],
|
||||
'link' => $shared['plink'],
|
||||
'posted' => $shared['created'],
|
||||
'guid' => $shared['guid'],
|
||||
'message_id' => $shared['uri'],
|
||||
'comment' => $item['body'],
|
||||
'shared' => $shared['body'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue