function display_fetchauthor($item)
{
- if (Diaspora::isReshare($item['body'], true)) {
- $shared = Item::getShareArray($item);
- if (!empty($shared['profile'])) {
- $contact = Contact::getByURLForUser($shared['profile'], Session::getLocalUser());
- }
+ $shared = Item::getShareArray($item);
+ if (empty($shared['comment']) && !empty($shared['guid']) && !empty($shared['profile'])) {
+ $contact = Contact::getByURLForUser($shared['profile'], Session::getLocalUser());
}
if (empty($contact)) {
System::exit();
}
- $shared = BBCode::fetchShareAttributes($item['body']);
+ $shared = Item::getShareArray($item);
if (empty($shared['comment']) && (!empty($shared['message_id']) || !empty($shared['link']))) {
$content = '[share]' . ($shared['message_id'] ?: $shared['link']) . '[/share]';
} else {
$shared_content .= '[h3]' . $item['title'] . "[/h3]\n";
}
- $shared = BBCode::fetchShareAttributes($item['body']);
+ $shared = ItemModel::getShareArray($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)) {
if (!empty($shared['guid']) && ($encaspulated_share = self::createSharedPostByGuid($shared['guid'], 0, '', $add_media))) {
$item['body'] = preg_replace("/\[share.*?\](.*)\[\/share\]/ism", $encaspulated_share, $item['body']);
}
{
DI::profiler()->startRecording('rendering');
if (preg_match('~(.*?)\[share](.*)\[/share]~ism', $text, $matches)) {
+ DI::profiler()->stopRecording();
return [
'author' => '',
'profile' => '',
*/
public static function removeSharedData(string $body): string
{
- return BBCode::convertShare(
- $body,
- function (array $attributes) {
- return '';
- }
- );
+ return preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
}
/**
$poll = null;
}
- $shared = BBCode::fetchShareAttributes($item['body']);
+ $shared = Item::getShareArray($item);
if (!empty($shared['guid'])) {
$shared_item = Post::selectFirst(['uri-id', 'plink'], ['guid' => $shared['guid']]);
$friendica_activities = $this->activities->createFromUriId($item['uri-id'], $uid);
- $shared = BBCode::fetchShareAttributes($item['body']);
+ $shared = Item::getShareArray($item);
if (!empty($shared['guid'])) {
$shared_item = Post::selectFirst(['uri-id', 'plink'], ['guid' => $shared['guid']]);
* Relationship types
* @{
*/
- const NOTHING = 0;
- const FOLLOWER = 1;
- const SHARING = 2;
- const FRIEND = 3;
- const SELF = 4;
+ const NOTHING = 0; // There is no relationship between the contact and the user
+ const FOLLOWER = 1; // The contact is following this user
+ const SHARING = 2; // The contact shares their content with this user
+ const FRIEND = 3; // There is a mutual relationship between the contact and the user
+ const SELF = 4; // This is the user theirself
/**
* @}
*/
'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app',
'inform', 'deleted', 'extid', 'post-type', 'post-reason', 'gravity',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
- 'author-id', 'author-link', 'author-name', 'author-avatar', 'owner-id', 'owner-link', 'contact-uid',
+ 'author-id', 'author-addr', 'author-link', 'author-name', 'author-avatar', 'owner-id', 'owner-link', 'contact-uid',
'signed_text', 'network', 'wall', 'contact-id', 'plink', 'origin',
'thr-parent-id', 'parent-uri-id', 'quote-uri', 'quote-uri-id', 'postopts', 'pubmail',
'event-created', 'event-edited', 'event-start', 'event-finish',
$item['mentions'] = $tags['mentions'];
$body = $item['body'] ?? '';
- $shared = BBCode::fetchShareAttributes($body);
+ $shared = self::getShareArray($item);
if (!empty($shared['guid'])) {
$shared_item = Post::selectFirst(['uri-id', 'guid', 'plink', 'has-media'], ['guid' => $shared['guid'], 'uid' => [$item['uid'], 0]]);
}
$s = self::addVisualAttachments($shared_attachments, $item, $s, true);
$s = self::addLinkAttachment($shared_uri_id ?: $item['uri-id'], $shared_attachments, $body, $s, true, []);
$s = self::addNonVisualAttachments($shared_attachments, $item, $s, true);
- $body = preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
+ $body = BBCode::removeSharedData($body);
}
$s = self::addVisualAttachments($attachments, $item, $s, false);
*/
public static function getShareArray(array $item): array
{
- return BBCode::fetchShareAttributes($item['body']);
+ $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 [];
}
/**
// Only remove the shared data from "real" reshares
$shared = BBCode::fetchShareAttributes($body);
if (!empty($shared['guid'])) {
- $unshared_body = preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
+ $unshared_body = BBCode::removeSharedData($body);
}
$attachments = [];
$shared = BBCode::fetchShareAttributes($body);
if (!empty($shared['guid'])) {
// Don't look at the shared content
- $body = preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
+ $body = BBCode::removeSharedData($body);
}
// Remove all hashtags and mentions
public static function insertFromAttachmentData(int $uriid, string $body)
{
// Don't look at the shared content
- $body = preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
+ $body = BBCode::removeSharedData($body);
$data = BBCode::getAttachmentData($body);
if (empty($data)) {
// Only remove the shared data from "real" reshares
$shared = BBCode::fetchShareAttributes($body);
if (!empty($shared['guid'])) {
- if (preg_match("/\s*\[share .*?\](.*?)\[\/share\]\s*/ism", $body, $matches)) {
- $share_body = $matches[1];
- }
- $body = preg_replace("/\s*\[share .*?\].*?\[\/share\]\s*/ism", '', $body);
+ $share_body = $shared['shared'];
+ $body = BBCode::removeSharedData($body);
}
foreach (self::getFromBody($body, $tags) as $tag) {
$body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body);
}
- $body = BBCode::setMentionsToNicknames($body);
+ $body = BBCode::setMentionsToNicknames($body);
+ $shared = BBCode::fetchShareAttributes($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)) {
+ if (!empty($shared['link'])) {
$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)) {
+ } elseif (!empty($item['quote-uri']) && empty($shared)) {
$body .= "\n" . DI::contentItem()->createSharedPostByUriId($item['quote-uri-id'], $item['uid'], true);
$item['body'] = Item::improveSharedDataInBody($item, true);
}
if ($real_quote) {
$shared = BBCode::fetchShareAttributes($richbody);
- if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
+ if (!empty($shared['link'])) {
$richbody = BBCode::replaceSharedData($richbody);
+ } elseif (strpos($richbody, $item['quote-uri']) === false) {
+ $richbody .= "\n♲ " . $item['quote-uri'];
}
}
return '';
}
- /**
- * get a handle (user@domain.tld) from a given contact id
- *
- * @param int $contact_id The id in the contact table
- * @param int $pcontact_id The id in the contact table (Used for the public contact)
- *
- * @return string the handle
- * @throws \Exception
- */
- private static function handleFromContact(int $contact_id, int $pcontact_id = 0): string
- {
- $handle = '';
-
- if ($pcontact_id != 0) {
- $contact = Contact::getById($pcontact_id, ['addr']);
- if (DBA::isResult($contact)) {
- $handle = $contact['addr'];
- }
- }
-
- if (empty($handle)) {
- $contact = Contact::getById($contact_id, ['addr']);
- if (DBA::isResult($contact)) {
- $handle = $contact['addr'];
- }
- }
-
- return strtolower($handle);
- }
-
/**
* Get a contact id for a given handle
*
/**
* Checks a message body if it is a reshare
*
- * @param string $body The message body that is to be check
- * @param bool $complete Should it be a complete check or a simple check?
+ * @param array $item The message body that is to be check
*
- * @return array|bool Reshare details or "false" if no reshare
+ * @return array Reshare details or "false" if no reshare
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function isReshare(string $body, bool $complete = true)
+ public static function isReshare(array $item): array
{
- $body = trim($body);
-
- $reshared = Item::getShareArray(['body' => $body]);
+ $reshared = Item::getShareArray($item);
if (empty($reshared)) {
- return false;
- }
-
- // Skip if it isn't a pure repeated messages
- // Does it start with a share?
- if (!empty($reshared['comment']) && $complete) {
- return false;
- }
-
- if (!empty($reshared['guid']) && $complete) {
- $condition = ['guid' => $reshared['guid'], 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
- $item = Post::selectFirst(['contact-id'], $condition);
- if (DBA::isResult($item)) {
- $ret = [];
- $ret['root_handle'] = self::handleFromContact($item['contact-id']);
- $ret['root_guid'] = $reshared['guid'];
- return $ret;
- } elseif ($complete) {
- // We are resharing something that isn't a DFRN or Diaspora post.
- // So we have to return "false" on "$complete" to not trigger a reshare.
- return false;
- }
- } elseif (empty($reshared['guid']) && $complete) {
- return false;
+ return [];
}
- $ret = [];
-
- if (!empty($reshared['profile']) && ($cid = Contact::getIdForURL($reshared['profile']))) {
- $contact = DBA::selectFirst('contact', ['addr'], ['id' => $cid]);
- if (!empty($contact['addr'])) {
- $ret['root_handle'] = $contact['addr'];
- }
+ // Skip if it isn't a pure repeated messages or not a real reshare
+ if (!empty($reshared['comment']) || empty($reshared['guid'])) {
+ return [];
}
- if (empty($ret) && !$complete) {
- return true;
+ $condition = ['guid' => $reshared['guid'], 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
+ $item = Post::selectFirst(['author-addr'], $condition);
+ if (DBA::isResult($item)) {
+ return [
+ 'root_handle' => strtolower($item['author-addr']),
+ 'root_guid' => $reshared['guid']
+ ];
}
- return $ret;
+ // We are resharing something that isn't a DFRN or Diaspora post.
+ return [];
}
/**
$edited = DateTimeFormat::utc($item['edited'] ?? $item['created'], DateTimeFormat::ATOM);
// Detect a share element and do a reshare
- if (($item['private'] != Item::PRIVATE) && ($ret = self::isReshare($item['body']))) {
+ if (($item['private'] != Item::PRIVATE) && ($ret = self::isReshare($item))) {
$message = [
'author' => $myaddr,
'guid' => $item['guid'],
*/
public static function sendRetraction(array $item, array $owner, array $contact, bool $public_batch = false, bool $relay = false): int
{
- $itemaddr = self::handleFromContact($item['contact-id'], $item['author-id']);
+ $itemaddr = strtolower($item['author-addr']);
$msg_type = 'retraction';
}
if (!empty($href)) {
- $attachment = ['type' => Post\Media::UNKNOWN, 'url' => $href, 'mimetype' => $type, 'size' => $length];
+ $attachment = ['uri-id' => -1, 'type' => Post\Media::UNKNOWN, 'url' => $href, 'mimetype' => $type, 'size' => $length];
$attachment = Post\Media::fetchAdditionalData($attachment);
private static function deliverDFRN(string $cmd, array $contact, array $owner, array $items, array $target_item, bool $public_message, bool $top_level, bool $followup, int $server_protocol = null)
{
// Transmit Diaspora reshares via Diaspora if the Friendica contact support Diaspora
- if (Diaspora::isReshare($target_item['body'] ?? '') && !empty(FContact::getByURL($contact['addr'], false))) {
+ if (Diaspora::isReshare($target_item ?? []) && !empty(FContact::getByURL($contact['addr'], false))) {
Logger::info('Reshare will be transmitted via Diaspora', ['url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
return;