3 * @file src/Protocol/ActivityPub.php
5 namespace Friendica\Protocol;
7 use Friendica\Database\DBA;
8 use Friendica\Core\System;
9 use Friendica\BaseObject;
10 use Friendica\Util\Network;
11 use Friendica\Util\HTTPSignature;
12 use Friendica\Core\Protocol;
13 use Friendica\Model\Conversation;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Item;
16 use Friendica\Model\User;
17 use Friendica\Util\DateTimeFormat;
18 use Friendica\Util\Crypto;
19 use Friendica\Content\Text\BBCode;
20 use Friendica\Content\Text\HTML;
21 use Friendica\Network\Probe;
24 * @brief ActivityPub Protocol class
25 * The ActivityPub Protocol is a message exchange protocol defined by the W3C.
26 * https://www.w3.org/TR/activitypub/
27 * https://www.w3.org/TR/activitystreams-core/
28 * https://www.w3.org/TR/activitystreams-vocabulary/
30 * https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/
31 * https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/
33 * Digest: https://tools.ietf.org/html/rfc5843
34 * https://tools.ietf.org/html/draft-cavage-http-signatures-10#ref-15
38 const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public';
40 public static function transmit($data, $target, $uid)
42 $owner = User::getOwnerDataById($uid);
48 $content = json_encode($data);
50 $host = parse_url($target, PHP_URL_HOST);
51 $path = parse_url($target, PHP_URL_PATH);
54 $headers = ['Host: ' . $host, 'Date: ' . $date];
56 $signed_data = "(request-target): post " . $path . "\nhost: " . $host . "\ndate: " . $date;
58 $signature = base64_encode(Crypto::rsaSign($signed_data, $owner['uprvkey'], 'sha256'));
60 $headers[] = 'Signature: keyId="' . $owner['url'] . '#main-key' . '",headers="(request-target) host date",signature="' . $signature . '"';
61 $headers[] = 'Content-Type: application/activity+json';
63 Network::post($target, $content, $headers);
64 $return_code = BaseObject::getApp()->get_curl_code();
66 echo $return_code."\n";
70 * Return the ActivityPub profile of the given user
72 * @param integer $uid User ID
75 public static function profile($uid)
77 $accounttype = ['Person', 'Organization', 'Service', 'Group', 'Application'];
79 $condition = ['uid' => $uid, 'blocked' => false, 'account_expired' => false,
80 'account_removed' => false, 'verified' => true];
81 $fields = ['guid', 'nickname', 'pubkey', 'account-type'];
82 $user = DBA::selectFirst('user', $fields, $condition);
83 if (!DBA::isResult($user)) {
87 $fields = ['locality', 'region', 'country-name'];
88 $profile = DBA::selectFirst('profile', $fields, ['uid' => $uid, 'is-default' => true]);
89 if (!DBA::isResult($profile)) {
93 $fields = ['name', 'url', 'location', 'about', 'avatar'];
94 $contact = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
95 if (!DBA::isResult($contact)) {
99 $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1',
100 ['uuid' => 'http://schema.org/identifier', 'sensitive' => 'as:sensitive',
101 'vcard' => 'http://www.w3.org/2006/vcard/ns#']]];
103 $data['id'] = $contact['url'];
104 $data['uuid'] = $user['guid'];
105 $data['type'] = $accounttype[$user['account-type']];
106 $data['following'] = System::baseUrl() . '/following/' . $user['nickname'];
107 $data['followers'] = System::baseUrl() . '/followers/' . $user['nickname'];
108 $data['inbox'] = System::baseUrl() . '/inbox/' . $user['nickname'];
109 $data['outbox'] = System::baseUrl() . '/outbox/' . $user['nickname'];
110 $data['preferredUsername'] = $user['nickname'];
111 $data['name'] = $contact['name'];
112 $data['vcard:hasAddress'] = ['@type' => 'Home', 'vcard:country-name' => $profile['country-name'],
113 'vcard:region' => $profile['region'], 'vcard:locality' => $profile['locality']];
114 $data['summary'] = $contact['about'];
115 $data['url'] = $contact['url'];
116 $data['manuallyApprovesFollowers'] = false;
117 $data['publicKey'] = ['id' => $contact['url'] . '#main-key',
118 'owner' => $contact['url'],
119 'publicKeyPem' => $user['pubkey']];
120 $data['endpoints'] = ['sharedInbox' => System::baseUrl() . '/inbox'];
121 $data['icon'] = ['type' => 'Image',
122 'url' => $contact['avatar']];
124 // tags: https://kitty.town/@inmysocks/100656097926961126.json
128 public static function createActivityFromItem($item_id)
130 $item = Item::selectFirst([], ['id' => $item_id]);
132 $data = ['@context' => ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1',
133 ['Emoji' => 'toot:Emoji', 'Hashtag' => 'as:Hashtag', 'atomUri' => 'ostatus:atomUri',
134 'conversation' => 'ostatus:conversation', 'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
135 'ostatus' => 'http://ostatus.org#', 'sensitive' => 'as:sensitive',
136 'toot' => 'http://joinmastodon.org/ns#']]];
138 $data['type'] = 'Create';
139 $data['id'] = $item['plink'];
140 $data['actor'] = $item['author-link'];
141 $data['to'] = 'https://www.w3.org/ns/activitystreams#Public';
142 $data['object'] = self::createNote($item);
146 public static function createNote($item)
149 $data['type'] = 'Note';
150 $data['id'] = $item['plink'];
151 //$data['context'] = $data['conversation'] = $item['parent-uri'];
152 $data['actor'] = $item['author-link'];
154 if (!$item['private']) {
155 $data['to'][] = '"https://pleroma.soykaf.com/users/heluecht"';
157 $data['published'] = DateTimeFormat::utc($item["created"]."+00:00", DateTimeFormat::ATOM);
158 $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
159 $data['attributedTo'] = $item['author-link'];
160 $data['name'] = BBCode::convert($item['title'], false, 7);
161 $data['content'] = BBCode::convert($item['body'], false, 7);
162 //$data['summary'] = ''; // Ignore by now
163 //$data['sensitive'] = false; // - Query NSFW
164 //$data['emoji'] = []; // Ignore by now
165 //$data['tag'] = []; /// @ToDo
166 //$data['attachment'] = []; // @ToDo
170 public static function transmitActivity($activity, $target, $uid)
172 $profile = Probe::uri($target, Protocol::ACTIVITYPUB);
174 $owner = User::getOwnerDataById($uid);
176 $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
177 'id' => 'https://pirati.ca/' . strtolower($activity) . '/' . System::createGUID(),
179 'actor' => $owner['url'],
180 'object' => $profile['url']];
182 return self::transmit($data, $profile['notify'], $uid);
186 * Fetches ActivityPub content from the given url
188 * @param string $url content url
191 public static function fetchContent($url)
193 $ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json']);
195 if (!$ret['success'] || empty($ret['body'])) {
199 return json_decode($ret['body'], true);
203 * Resolves the profile url from the address by using webfinger
205 * @param string $addr profile address (user@domain.tld)
208 private static function addrToUrl($addr)
210 $addr_parts = explode('@', $addr);
211 if (count($addr_parts) != 2) {
215 $webfinger = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
217 $ret = Network::curl($webfinger, false, $redirects, ['accept_content' => 'application/jrd+json,application/json']);
218 if (!$ret['success'] || empty($ret['body'])) {
222 $data = json_decode($ret['body'], true);
224 if (empty($data['links'])) {
228 foreach ($data['links'] as $link) {
229 if (empty($link['href']) || empty($link['rel']) || empty($link['type'])) {
233 if (($link['rel'] == 'self') && ($link['type'] == 'application/activity+json')) {
234 return $link['href'];
241 public static function verifySignature($content, $http_headers)
243 $object = json_decode($content, true);
245 if (empty($object)) {
249 $actor = self::processElement($object, 'actor', 'id');
252 $headers['(request-target)'] = strtolower($http_headers['REQUEST_METHOD']) . ' ' . $http_headers['REQUEST_URI'];
254 // First take every header
255 foreach ($http_headers as $k => $v) {
256 $field = str_replace('_', '-', strtolower($k));
257 $headers[$field] = $v;
260 // Now add every http header
261 foreach ($http_headers as $k => $v) {
262 if (strpos($k, 'HTTP_') === 0) {
263 $field = str_replace('_', '-', strtolower(substr($k, 5)));
264 $headers[$field] = $v;
268 $sig_block = ActivityPub::parseSigHeader($http_headers['HTTP_SIGNATURE']);
270 if (empty($sig_block) || empty($sig_block['headers']) || empty($sig_block['keyId'])) {
275 foreach ($sig_block['headers'] as $h) {
276 if (array_key_exists($h, $headers)) {
277 $signed_data .= $h . ': ' . $headers[$h] . "\n";
280 $signed_data = rtrim($signed_data, "\n");
282 if (empty($signed_data)) {
288 if ($sig_block['algorithm'] === 'rsa-sha256') {
289 $algorithm = 'sha256';
292 if ($sig_block['algorithm'] === 'rsa-sha512') {
293 $algorithm = 'sha512';
296 if (empty($algorithm)) {
300 $key = self::fetchKey($sig_block['keyId'], $actor);
306 if (!Crypto::rsaVerify($signed_data, $sig_block['signature'], $key, $algorithm)) {
310 // Check the digest if it was part of the signed data
311 if (in_array('digest', $sig_block['headers'])) {
312 $digest = explode('=', $headers['digest'], 2);
313 if ($digest[0] === 'SHA-256') {
316 if ($digest[0] === 'SHA-512') {
320 /// @todo add all hashes from the rfc
322 if (!empty($hashalg) && base64_encode(hash($hashalg, $content, true)) != $digest[1]) {
327 // Check the content-length if it was part of the signed data
328 if (in_array('content-length', $sig_block['headers'])) {
329 if (strlen($content) != $headers['content-length']) {
338 private static function fetchKey($id, $actor)
340 $url = (strpos($id, '#') ? substr($id, 0, strpos($id, '#')) : $id);
342 $profile = Probe::uri($url, Protocol::ACTIVITYPUB);
343 if (!empty($profile)) {
344 return $profile['pubkey'];
345 } elseif ($url != $actor) {
346 $profile = Probe::uri($actor, Protocol::ACTIVITYPUB);
347 if (!empty($profile)) {
348 return $profile['pubkey'];
358 * @param string $header
359 * @return array associate array with
360 * - \e string \b keyID
361 * - \e string \b algorithm
362 * - \e array \b headers
363 * - \e string \b signature
365 private static function parseSigHeader($header)
370 if (preg_match('/keyId="(.*?)"/ism',$header,$matches)) {
371 $ret['keyId'] = $matches[1];
374 if (preg_match('/algorithm="(.*?)"/ism',$header,$matches)) {
375 $ret['algorithm'] = $matches[1];
378 if (preg_match('/headers="(.*?)"/ism',$header,$matches)) {
379 $ret['headers'] = explode(' ', $matches[1]);
382 if (preg_match('/signature="(.*?)"/ism',$header,$matches)) {
383 $ret['signature'] = base64_decode(preg_replace('/\s+/','',$matches[1]));
390 * Fetches a profile from the given url
392 * @param string $url profile url
395 public static function fetchProfile($url)
397 if (empty(parse_url($url, PHP_URL_SCHEME))) {
398 $url = self::addrToUrl($url);
404 $data = self::fetchContent($url);
406 if (empty($data) || empty($data['id']) || empty($data['inbox'])) {
410 $profile = ['network' => Protocol::ACTIVITYPUB];
411 $profile['nick'] = $data['preferredUsername'];
412 $profile['name'] = defaults($data, 'name', $profile['nick']);
413 $profile['guid'] = defaults($data, 'uuid', null);
414 $profile['url'] = $data['id'];
416 $parts = parse_url($profile['url']);
417 unset($parts['scheme']);
418 unset($parts['path']);
419 $profile['addr'] = $profile['nick'] . '@' . str_replace('//', '', Network::unparseURL($parts));
420 $profile['alias'] = self::processElement($data, 'url', 'href');
421 $profile['photo'] = self::processElement($data, 'icon', 'url');
422 // $profile['community']
423 // $profile['keywords']
424 // $profile['location']
425 $profile['about'] = defaults($data, 'summary', '');
426 $profile['batch'] = self::processElement($data, 'endpoints', 'sharedInbox');
427 $profile['notify'] = $data['inbox'];
428 $profile['poll'] = $data['outbox'];
429 $profile['pubkey'] = self::processElement($data, 'publicKey', 'publicKeyPem');
431 // Check if the address is resolvable
432 if (self::addrToUrl($profile['addr']) == $profile['url']) {
433 $parts = parse_url($profile['url']);
434 unset($parts['path']);
435 $profile['baseurl'] = Network::unparseURL($parts);
437 unset($profile['addr']);
440 if ($profile['url'] == $profile['alias']) {
441 unset($profile['alias']);
444 // Remove all "null" fields
445 foreach ($profile as $field => $content) {
446 if (is_null($content)) {
447 unset($profile[$field]);
453 unset($data['type']);
454 unset($data['manuallyApprovesFollowers']);
457 unset($data['@context']);
459 unset($data['attachment']);
460 unset($data['image']);
461 unset($data['nomadicLocations']);
462 unset($data['signature']);
463 unset($data['following']);
464 unset($data['followers']);
465 unset($data['featured']);
466 unset($data['movedTo']);
467 unset($data['liked']);
468 unset($data['sharedInbox']); // Misskey
469 unset($data['isCat']); // Misskey
470 unset($data['kroeg:blocks']); // Kroeg
471 unset($data['updated']); // Kroeg
476 public static function processInbox($body, $header)
478 logger('Incoming message', LOGGER_DEBUG);
480 if (!self::verifySignature($body, $header)) {
481 logger('Invalid signature, message will be discarded.', LOGGER_DEBUG);
485 $activity = json_decode($body, true);
487 if (!is_array($activity)) {
488 logger('Invalid body.', LOGGER_DEBUG);
492 self::processActivity($activity, $body);
495 public static function fetchOutbox($url)
497 $data = self::fetchContent($url);
502 if (!empty($data['orderedItems'])) {
503 $items = $data['orderedItems'];
504 } elseif (!empty($data['first']['orderedItems'])) {
505 $items = $data['first']['orderedItems'];
506 } elseif (!empty($data['first'])) {
507 self::fetchOutbox($data['first']);
513 foreach ($items as $activity) {
514 self::processActivity($activity);
518 function processActivity($activity, $body = '')
520 if (empty($activity['type'])) {
521 logger('Empty type', LOGGER_DEBUG);
525 if (empty($activity['object'])) {
526 logger('Empty object', LOGGER_DEBUG);
530 if (empty($activity['actor'])) {
531 logger('Empty actor', LOGGER_DEBUG);
536 $actor = self::processElement($activity, 'actor', 'id');
538 logger('Empty actor - 2', LOGGER_DEBUG);
542 if (is_string($activity['object'])) {
543 $object_url = $activity['object'];
544 } elseif (!empty($activity['object']['id'])) {
545 $object_url = $activity['object']['id'];
547 logger('No object found', LOGGER_DEBUG);
551 $receivers = self::getReceivers($activity);
552 if (empty($receivers)) {
553 logger('No receivers found', LOGGER_DEBUG);
557 // ----------------------------------
560 unset($activity['@context']);
561 unset($activity['id']);
564 unset($activity['title']);
565 unset($activity['atomUri']);
566 unset($activity['context_id']);
567 unset($activity['statusnetConversationId']);
570 unset($activity['context']);
571 unset($activity['location']);
572 unset($activity['signature']);
575 if (!in_array($activity['type'], ['Like', 'Dislike'])) {
576 $item = self::fetchObject($object_url, $activity['object']);
578 logger("Object data couldn't be processed", LOGGER_DEBUG);
582 $item['object'] = $object_url;
583 $item['receiver'] = [];
584 $item['type'] = $activity['type'];
587 $item = self::addActivityFields($item, $activity);
589 $item['owner'] = $actor;
591 $item['receiver'] = array_merge($item['receiver'], $receivers);
593 logger('Processing activity: ' . $activity['type'], LOGGER_DEBUG);
595 switch ($activity['type']) {
599 self::createItem($item, $body);
604 self::activityItem($item, $body);
611 logger('Unknown activity: ' . $activity['type'], LOGGER_DEBUG);
616 private static function getReceivers($activity)
620 $elements = ['to', 'cc', 'bto', 'bcc'];
621 foreach ($elements as $element) {
622 if (empty($activity[$element])) {
626 // The receiver can be an arror or a string
627 if (is_string($activity[$element])) {
628 $activity[$element] = [$activity[$element]];
631 foreach ($activity[$element] as $receiver) {
632 if ($receiver == self::PUBLIC) {
633 $receivers[$receiver] = 0;
636 $condition = ['self' => true, 'nurl' => normalise_link($receiver)];
637 $contact = DBA::selectFirst('contact', ['uid'], $condition);
638 if (!DBA::isResult($contact)) {
641 $receivers[$receiver] = $contact['uid'];
647 private static function addActivityFields($item, $activity)
649 if (!empty($activity['published']) && empty($item['published'])) {
650 $item['published'] = $activity['published'];
653 if (!empty($activity['updated']) && empty($item['updated'])) {
654 $item['updated'] = $activity['updated'];
657 if (!empty($activity['inReplyTo']) && empty($item['parent-uri'])) {
658 $item['parent-uri'] = self::processElement($activity, 'inReplyTo', 'id');
661 if (!empty($activity['instrument'])) {
662 $item['service'] = self::processElement($activity, 'instrument', 'name', 'Service');
667 private static function fetchObject($object_url, $object = [])
669 $data = self::fetchContent($object_url);
673 logger('Empty content');
676 logger('Using provided object');
680 if (empty($data['type'])) {
681 logger('Empty type');
684 $type = $data['type'];
685 logger('Type ' . $type);
688 if (in_array($type, ['Note', 'Article', 'Video'])) {
689 $common = self::processCommonData($data);
694 return array_merge($common, self::processNote($data));
696 return array_merge($common, self::processArticle($data));
698 return array_merge($common, self::processVideo($data));
701 if (empty($data['object'])) {
704 return self::fetchObject($data['object']);
711 logger('Unknown object type: ' . $data['type'], LOGGER_DEBUG);
716 private static function processCommonData(&$object)
718 if (empty($object['id']) || empty($object['attributedTo'])) {
723 $item['type'] = $object['type'];
724 $item['uri'] = $object['id'];
726 if (!empty($object['inReplyTo'])) {
727 $item['reply-to-uri'] = self::processElement($object, 'inReplyTo', 'id');
729 $item['reply-to-uri'] = $item['uri'];
732 $item['published'] = defaults($object, 'published', null);
733 $item['updated'] = defaults($object, 'updated', $item['published']);
735 if (empty($item['published']) && !empty($item['updated'])) {
736 $item['published'] = $item['updated'];
739 $item['uuid'] = defaults($object, 'uuid', null);
740 $item['owner'] = $item['author'] = self::processElement($object, 'attributedTo', 'id');
741 $item['context'] = defaults($object, 'context', null);
742 $item['conversation'] = defaults($object, 'conversation', null);
743 $item['sensitive'] = defaults($object, 'sensitive', null);
744 $item['name'] = defaults($object, 'title', null);
745 $item['name'] = defaults($object, 'name', $item['name']);
746 $item['summary'] = defaults($object, 'summary', null);
747 $item['content'] = defaults($object, 'content', null);
748 $item['location'] = self::processElement($object, 'location', 'name', 'Place');
749 $item['attachments'] = defaults($object, 'attachment', null);
750 $item['tags'] = defaults($object, 'tag', null);
751 $item['service'] = self::processElement($object, 'instrument', 'name', 'Service');
752 $item['alternate-url'] = self::processElement($object, 'url', 'href');
753 $item['receiver'] = self::getReceivers($object);
757 unset($object['source']);
760 unset($object['@context']);
761 unset($object['type']);
762 unset($object['actor']);
763 unset($object['signature']);
764 unset($object['mediaType']);
765 unset($object['duration']);
766 unset($object['replies']);
767 unset($object['icon']);
770 audience, preview, endTime, startTime, generator, image
775 private static function processNote($object)
781 unset($object['emoji']);
782 unset($object['atomUri']);
783 unset($object['inReplyToAtomUri']);
786 unset($object['contentMap']);
787 unset($object['announcement_count']);
788 unset($object['announcements']);
789 unset($object['context_id']);
790 unset($object['likes']);
791 unset($object['like_count']);
792 unset($object['inReplyToStatusId']);
793 unset($object['shares']);
794 unset($object['quoteUrl']);
795 unset($object['statusnetConversationId']);
800 private static function processArticle($object)
807 private static function processVideo($object)
812 unset($object['category']);
813 unset($object['licence']);
814 unset($object['language']);
815 unset($object['commentsEnabled']);
818 unset($object['views']);
819 unset($object['waitTranscoding']);
820 unset($object['state']);
821 unset($object['support']);
822 unset($object['subtitleLanguage']);
823 unset($object['likes']);
824 unset($object['dislikes']);
825 unset($object['shares']);
826 unset($object['comments']);
831 private static function processElement($array, $element, $key, $type = null)
837 if (empty($array[$element])) {
841 if (is_string($array[$element])) {
842 return $array[$element];
845 if (is_null($type)) {
846 if (!empty($array[$element][$key])) {
847 return $array[$element][$key];
850 if (!empty($array[$element][0][$key])) {
851 return $array[$element][0][$key];
857 if (!empty($array[$element][$key]) && !empty($array[$element]['type']) && ($array[$element]['type'] == $type)) {
858 return $array[$element][$key];
861 /// @todo Add array search
866 private static function convertMentions($body)
868 $URLSearchString = "^\[\]";
869 $body = preg_replace("/\[url\=([$URLSearchString]*)\]([#@!])(.*?)\[\/url\]/ism", '$2[url=$1]$3[/url]', $body);
874 private static function constructTagList($tags, $sensitive)
881 foreach ($tags as $tag) {
882 if (in_array($tag['type'], ['Mention', 'Hashtag'])) {
883 if (!empty($tag_text)) {
887 $tag_text .= substr($tag['name'], 0, 1) . '[url=' . $tag['href'] . ']' . substr($tag['name'], 1) . '[/url]';
891 /// @todo add nsfw for $sensitive
896 private static function constructAttachList($attachments, $item)
898 if (empty($attachments)) {
902 foreach ($attachments as $attach) {
903 $filetype = strtolower(substr($attach['mediaType'], 0, strpos($attach['mediaType'], '/')));
904 if ($filetype == 'image') {
905 $item['body'] .= "\n[img]".$attach['url'].'[/img]';
907 if (!empty($item["attach"])) {
908 $item["attach"] .= ',';
910 $item["attach"] = '';
912 if (!isset($attach['length'])) {
913 $attach['length'] = "0";
915 $item["attach"] .= '[attach]href="'.$attach['url'].'" length="'.$attach['length'].'" type="'.$attach['mediaType'].'" title="'.defaults($attach, 'name', '').'"[/attach]';
922 private static function createItem($activity, $body)
924 /// @todo What to do with $activity['context']?
927 $item['network'] = Protocol::ACTIVITYPUB;
928 $item['private'] = !in_array(0, $activity['receiver']);
929 $item['author-id'] = Contact::getIdForURL($activity['author'], 0, true);
930 $item['owner-id'] = Contact::getIdForURL($activity['owner'], 0, true);
931 $item['uri'] = $activity['uri'];
932 $item['parent-uri'] = $activity['reply-to-uri'];
933 $item['verb'] = ACTIVITY_POST;
934 $item['object-type'] = ACTIVITY_OBJ_NOTE; /// Todo?
935 $item['created'] = $activity['published'];
936 $item['edited'] = $activity['updated'];
937 $item['guid'] = $activity['uuid'];
938 $item['title'] = HTML::toBBCode($activity['name']);
939 $item['content-warning'] = HTML::toBBCode($activity['summary']);
940 $item['body'] = self::convertMentions(HTML::toBBCode($activity['content']));
941 $item['location'] = $activity['location'];
942 $item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']);
943 $item['app'] = $activity['service'];
944 $item['plink'] = defaults($activity, 'alternate-url', $item['uri']);
946 $item = self::constructAttachList($activity['attachments'], $item);
948 $item['protocol'] = Conversation::PARCEL_ACTIVITYPUB;
949 $item['source'] = $body;
950 $item['conversation-uri'] = $activity['conversation'];
952 foreach ($activity['receiver'] as $receiver) {
953 $item['uid'] = $receiver;
954 $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver, true);
956 if (($receiver != 0) && empty($item['contact-id'])) {
957 $item['contact-id'] = Contact::getIdForURL($activity['author'], 0, true);
960 $item_id = Item::insert($item);
961 logger('Storing for user ' . $item['uid'] . ': ' . $item_id);
962 if (!empty($item_id) && ($item['uid'] == 0)) {
963 Item::distribute($item_id);
968 private static function activityItem($data)
970 logger('Activity "' . $data['type'] . '" for ' . $data['object']);
971 $items = Item::select(['id'], ['uri' => $data['object']]);
972 while ($item = Item::fetch($items)) {
973 logger('Activity ' . $data['type'] . ' for item ' . $item['id'], LOGGER_DEBUG);
974 Item::performLike($item['id'], strtolower($data['type']));
977 logger('Activity done');