<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
return false;
}
- $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
- $conversation = DBA::selectFirst('conversation', ['source'], $condition);
- if (!$item['origin'] && DBA::isResult($conversation)) {
- $data = json_decode($conversation['source'], true);
- if (!empty($data['type'])) {
- if (in_array($data['type'], ['Create', 'Update'])) {
- if ($object_mode) {
- unset($data['@context']);
- unset($data['signature']);
- }
- Logger::info('Return stored conversation', ['item' => $item_id]);
- return $data;
- } elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
- if (!empty($data['@context'])) {
- $context = $data['@context'];
- unset($data['@context']);
+ if (!$item['deleted']) {
+ $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
+ $conversation = DBA::selectFirst('conversation', ['source'], $condition);
+ if (!$item['origin'] && DBA::isResult($conversation)) {
+ $data = json_decode($conversation['source'], true);
+ if (!empty($data['type'])) {
+ if (in_array($data['type'], ['Create', 'Update'])) {
+ if ($object_mode) {
+ unset($data['@context']);
+ unset($data['signature']);
+ }
+ Logger::info('Return stored conversation', ['item' => $item_id]);
+ return $data;
+ } elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
+ if (!empty($data['@context'])) {
+ $context = $data['@context'];
+ unset($data['@context']);
+ }
+ unset($data['actor']);
+ $object = $data;
}
- unset($data['actor']);
- $object = $data;
}
}
}
$data = [];
}
- if (($item['gravity'] == GRAVITY_ACTIVITY) && ($type != 'Undo')) {
+ if ($type == 'Delete') {
+ $data['id'] = Item::newURI($item['uid'], $item['guid']) . '/' . $type;;
+ } elseif (($item['gravity'] == GRAVITY_ACTIVITY) && ($type != 'Undo')) {
$data['id'] = $item['uri'];
} else {
$data['id'] = $item['uri'] . '/' . $type;
return $match[0];
}
- return '[url=' . ($data['alias'] ?: $data['url']) . ']@' . $data['nick'] . '[/url]';
+ return '[url=' . $data['url'] . ']@' . $data['nick'] . '[/url]';
+ }
+
+ /**
+ * Callback function to replace a Friendica style mention in a mention for a summary
+ *
+ * @param array $match Matching values for the callback
+ * @return string Replaced mention
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ private static function mentionAddrCallback($match)
+ {
+ if (empty($match[1])) {
+ return '';
+ }
+
+ $data = Contact::getByURL($match[1], false, ['addr']);
+ if (empty($data['addr'])) {
+ return $match[0];
+ }
+
+ return '@' . $data['addr'];
}
/**
* @return array with the event data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function createEvent($item)
+ private static function createEvent($item)
{
$event = [];
$event['name'] = $item['event-summary'];
$event['location'] = self::createLocation($item);
}
+ $event['dfrn:adjust'] = (bool)$item['event-adjust'];
+
return $event;
}
if ($type == 'Note') {
$body = $item['raw-body'] ?? self::removePictures($body);
} elseif (($type == 'Article') && empty($data['summary'])) {
- $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($body), 1000));
+ $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
+ $summary = preg_replace_callback($regexp, ['self', 'mentionAddrCallback'], $body);
+ $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($summary), 1000));
}
if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {