*
* @param string $url
* @param integer $uid
+ * @param bool $add_media
* @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)) {
$id = ModelItem::searchByLink($url, $uid);
return '';
}
- return $this->createSharedBlockByArray($shared_item);
+ return $this->createSharedBlockByArray($shared_item, $add_media);
}
/**
* Add a share block for the given item array
*
* @param array $item
+ * @param bool $add_media
* @return string
*/
- public function createSharedBlockByArray(array $item): string
+ public function createSharedBlockByArray(array $item, bool $add_media = false): string
{
if ($item['network'] == Protocol::FEED) {
return PageInfo::getFooterFromUrl($item['plink']);
$item['guid'] = '';
$item['uri'] = '';
$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']);
);
}
+ /**
+ * 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:
*
);
DI::profiler()->stopRecording();
- return $return;
+ return trim($return);
}
/**
if (!empty($quote_id) && Post::exists(['uri-id' => $quote_id, 'network' => Protocol::FEDERATED])) {
$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])) {
* Improve the data in shared posts
*
* @param array $item
+ * @param bool $add_media
* @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']);
if (empty($shared['guid']) && empty($shared['message_id'])) {
$link = $shared['link'] ?: $shared['message_id'];
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)) {
use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\Diaspora;
use Friendica\Protocol\Relay;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPSignature;
$permission_block = self::createPermissionBlockForItem($item, false);
+ $real_quote = false;
+
$body = $item['body'];
if ($type == 'Note') {
$body = BBCode::setMentionsToNicknames($body);
- if (!empty($item['quote-uri'])) {
- $body = BBCode::replaceSharedData($body);
+ if (!empty($item['quote-uri']) && Post::exists(['uri-id' => $item['quote-uri-id'], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN]])) {
+ $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'];
+ } 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);
if (!empty($language)) {
$richbody = BBCode::setMentionsToNicknames($item['body'] ?? '');
- $shared = BBCode::fetchShareAttributes($richbody);
- if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
- $richbody = BBCode::replaceSharedData($richbody);
+ if ($real_quote) {
+ $shared = BBCode::fetchShareAttributes($richbody);
+ if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
+ $richbody = BBCode::replaceSharedData($richbody);
+ }
}
$richbody = BBCode::removeAttachment($richbody);