mirror of
https://github.com/friendica/friendica
synced 2024-11-10 05:42:54 +00:00
Improve quite generation
This commit is contained in:
parent
34c3f189fc
commit
8e1af9277a
4 changed files with 51 additions and 12 deletions
|
@ -574,9 +574,10 @@ class Item
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param integer $uid
|
* @param integer $uid
|
||||||
|
* @param bool $add_media
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function createSharedPostByUrl(string $url, int $uid = 0): string
|
public function createSharedPostByUrl(string $url, int $uid = 0, bool $add_media = false): string
|
||||||
{
|
{
|
||||||
if (!empty($uid)) {
|
if (!empty($uid)) {
|
||||||
$id = ModelItem::searchByLink($url, $uid);
|
$id = ModelItem::searchByLink($url, $uid);
|
||||||
|
@ -599,7 +600,7 @@ class Item
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->createSharedBlockByArray($shared_item);
|
return $this->createSharedBlockByArray($shared_item, $add_media);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -652,9 +653,10 @@ class Item
|
||||||
* Add a share block for the given item array
|
* Add a share block for the given item array
|
||||||
*
|
*
|
||||||
* @param array $item
|
* @param array $item
|
||||||
|
* @param bool $add_media
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function createSharedBlockByArray(array $item): string
|
public function createSharedBlockByArray(array $item, bool $add_media = false): string
|
||||||
{
|
{
|
||||||
if ($item['network'] == Protocol::FEED) {
|
if ($item['network'] == Protocol::FEED) {
|
||||||
return PageInfo::getFooterFromUrl($item['plink']);
|
return PageInfo::getFooterFromUrl($item['plink']);
|
||||||
|
@ -662,6 +664,8 @@ class Item
|
||||||
$item['guid'] = '';
|
$item['guid'] = '';
|
||||||
$item['uri'] = '';
|
$item['uri'] = '';
|
||||||
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
||||||
|
} elseif ($add_media) {
|
||||||
|
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$shared_content = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid'], $item['uri']);
|
$shared_content = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'], $item['plink'], $item['created'], $item['guid'], $item['uri']);
|
||||||
|
|
|
@ -1085,6 +1085,22 @@ class BBCode
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the share block
|
||||||
|
*
|
||||||
|
* @param string $body
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function removeSharedData(string $body): string
|
||||||
|
{
|
||||||
|
return BBCode::convertShare(
|
||||||
|
$body,
|
||||||
|
function (array $attributes) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function converts a [share] block to text according to a provided callback function whose signature is:
|
* This function converts a [share] block to text according to a provided callback function whose signature is:
|
||||||
*
|
*
|
||||||
|
@ -1134,7 +1150,7 @@ class BBCode
|
||||||
);
|
);
|
||||||
|
|
||||||
DI::profiler()->stopRecording();
|
DI::profiler()->stopRecording();
|
||||||
return $return;
|
return trim($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1123,7 +1123,7 @@ class Item
|
||||||
|
|
||||||
if (!empty($quote_id) && Post::exists(['uri-id' => $quote_id, 'network' => Protocol::FEDERATED])) {
|
if (!empty($quote_id) && Post::exists(['uri-id' => $quote_id, 'network' => Protocol::FEDERATED])) {
|
||||||
$item['quote-uri-id'] = $quote_id;
|
$item['quote-uri-id'] = $quote_id;
|
||||||
$item['raw-body'] = BBCode::replaceSharedData($item['raw-body']);
|
$item['raw-body'] = BBCode::removeSharedData($item['raw-body']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DBA::exists('contact', ['id' => $item['author-id'], 'network' => Protocol::DFRN])) {
|
if (!DBA::exists('contact', ['id' => $item['author-id'], 'network' => Protocol::DFRN])) {
|
||||||
|
@ -3612,9 +3612,10 @@ class Item
|
||||||
* Improve the data in shared posts
|
* Improve the data in shared posts
|
||||||
*
|
*
|
||||||
* @param array $item
|
* @param array $item
|
||||||
|
* @param bool $add_media
|
||||||
* @return string body
|
* @return string body
|
||||||
*/
|
*/
|
||||||
public static function improveSharedDataInBody(array $item): string
|
public static function improveSharedDataInBody(array $item, bool $add_media = false): string
|
||||||
{
|
{
|
||||||
$shared = BBCode::fetchShareAttributes($item['body']);
|
$shared = BBCode::fetchShareAttributes($item['body']);
|
||||||
if (empty($shared['guid']) && empty($shared['message_id'])) {
|
if (empty($shared['guid']) && empty($shared['message_id'])) {
|
||||||
|
@ -3624,7 +3625,7 @@ class Item
|
||||||
$link = $shared['link'] ?: $shared['message_id'];
|
$link = $shared['link'] ?: $shared['message_id'];
|
||||||
|
|
||||||
if (empty($shared_content)) {
|
if (empty($shared_content)) {
|
||||||
$shared_content = DI::contentItem()->createSharedPostByUrl($link, $item['uid'] ?? 0);
|
$shared_content = DI::contentItem()->createSharedPostByUrl($link, $item['uid'] ?? 0, $add_media);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($shared_content)) {
|
if (empty($shared_content)) {
|
||||||
|
|
|
@ -40,6 +40,7 @@ use Friendica\Model\User;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
|
use Friendica\Protocol\Diaspora;
|
||||||
use Friendica\Protocol\Relay;
|
use Friendica\Protocol\Relay;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
|
@ -1621,6 +1622,8 @@ class Transmitter
|
||||||
|
|
||||||
$permission_block = self::createPermissionBlockForItem($item, false);
|
$permission_block = self::createPermissionBlockForItem($item, false);
|
||||||
|
|
||||||
|
$real_quote = false;
|
||||||
|
|
||||||
$body = $item['body'];
|
$body = $item['body'];
|
||||||
|
|
||||||
if ($type == 'Note') {
|
if ($type == 'Note') {
|
||||||
|
@ -1662,9 +1665,22 @@ class Transmitter
|
||||||
|
|
||||||
$body = BBCode::setMentionsToNicknames($body);
|
$body = BBCode::setMentionsToNicknames($body);
|
||||||
|
|
||||||
if (!empty($item['quote-uri'])) {
|
if (!empty($item['quote-uri']) && Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
|
||||||
$body = BBCode::replaceSharedData($body);
|
$real_quote = true;
|
||||||
|
if (Diaspora::isReshare($body, false)) {
|
||||||
|
$body = BBCode::replaceSharedData($body);
|
||||||
|
} elseif (strpos($body, $item['quote-uri']) === false) {
|
||||||
|
$body .= "\n♲ " . $item['quote-uri'];
|
||||||
|
}
|
||||||
$data['quoteUrl'] = $item['quote-uri'];
|
$data['quoteUrl'] = $item['quote-uri'];
|
||||||
|
} elseif (!empty($item['quote-uri']) && !Diaspora::isReshare($body, false)) {
|
||||||
|
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network'];
|
||||||
|
$shared_item = Post::selectFirst($fields, ['uri-id' => $item['quote-uri-id']]);
|
||||||
|
if (!empty($shared_item['uri-id'])) {
|
||||||
|
$shared_item['body'] = Post\Media::addAttachmentsToBody($shared_item['uri-id'], $shared_item['body']);
|
||||||
|
$body .= "\n" . DI::contentItem()->createSharedBlockByArray($shared_item);
|
||||||
|
$item['body'] = Item::improveSharedDataInBody($item, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['content'] = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
|
$data['content'] = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
|
||||||
|
@ -1677,9 +1693,11 @@ class Transmitter
|
||||||
if (!empty($language)) {
|
if (!empty($language)) {
|
||||||
$richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
|
$richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
|
||||||
|
|
||||||
$shared = BBCode::fetchShareAttributes($richbody);
|
if ($real_quote) {
|
||||||
if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
|
$shared = BBCode::fetchShareAttributes($richbody);
|
||||||
$richbody = BBCode::replaceSharedData($richbody);
|
if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
|
||||||
|
$richbody = BBCode::replaceSharedData($richbody);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$richbody = BBCode::removeAttachment($richbody);
|
$richbody = BBCode::removeAttachment($richbody);
|
||||||
|
|
Loading…
Reference in a new issue