+ $data['attachment'] = []; // @ToDo
+ $data['tag'] = self::createTagList($item);
+ $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item));
+
+ return $data;
+ }
+
+ /**
+ * @brief Transmits a profile deletion to a given inbox
+ *
+ * @param integer $uid User ID
+ * @param string $inbox Target inbox
+ */
+ public static function transmitProfileDeletion($uid, $inbox)
+ {
+ $owner = User::getOwnerDataById($uid);
+ $profile = APContact::getByURL($owner['url']);
+
+ $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+ 'type' => 'Delete',
+ 'actor' => $owner['url'],
+ 'object' => self::profile($uid),
+ 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+ 'to' => [self::PUBLIC_COLLECTION],
+ 'cc' => []];
+
+ $signed = LDSignature::sign($data, $owner);
+
+ logger('Deliver profile deletion for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
+ HTTPSignature::transmit($signed, $inbox, $uid);
+ }
+
+ /**
+ * @brief Transmits a profile change to a given inbox
+ *
+ * @param integer $uid User ID
+ * @param string $inbox Target inbox
+ */
+ public static function transmitProfileUpdate($uid, $inbox)
+ {
+ $owner = User::getOwnerDataById($uid);
+ $profile = APContact::getByURL($owner['url']);
+
+ $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+ 'type' => 'Update',
+ 'actor' => $owner['url'],
+ 'object' => self::profile($uid),
+ 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+ 'to' => [$profile['followers']],
+ 'cc' => []];
+
+ $signed = LDSignature::sign($data, $owner);
+
+ logger('Deliver profile update for user ' . $uid . ' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);
+ HTTPSignature::transmit($signed, $inbox, $uid);
+ }
+
+ /**
+ * @brief Transmits a given activity to a target
+ *
+ * @param array $activity
+ * @param string $target Target profile
+ * @param integer $uid User ID
+ */
+ public static function transmitActivity($activity, $target, $uid)
+ {
+ $profile = APContact::getByURL($target);
+
+ $owner = User::getOwnerDataById($uid);
+
+ $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+ 'type' => $activity,
+ 'actor' => $owner['url'],
+ 'object' => $profile['url'],
+ 'to' => $profile['url']];
+
+ logger('Sending activity ' . $activity . ' to ' . $target . ' for user ' . $uid, LOGGER_DEBUG);
+
+ $signed = LDSignature::sign($data, $owner);
+ HTTPSignature::transmit($signed, $profile['inbox'], $uid);
+ }
+
+ /**
+ * @brief Transmit a message that the contact request had been accepted
+ *
+ * @param string $target Target profile
+ * @param $id
+ * @param integer $uid User ID
+ */
+ public static function transmitContactAccept($target, $id, $uid)
+ {
+ $profile = APContact::getByURL($target);
+
+ $owner = User::getOwnerDataById($uid);
+ $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+ 'type' => 'Accept',
+ 'actor' => $owner['url'],
+ 'object' => ['id' => $id, 'type' => 'Follow',
+ 'actor' => $profile['url'],
+ 'object' => $owner['url']],
+ 'to' => $profile['url']];
+
+ logger('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
+
+ $signed = LDSignature::sign($data, $owner);
+ HTTPSignature::transmit($signed, $profile['inbox'], $uid);
+ }
+
+ /**
+ * @brief
+ *
+ * @param string $target Target profile
+ * @param $id
+ * @param integer $uid User ID
+ */
+ public static function transmitContactReject($target, $id, $uid)
+ {
+ $profile = APContact::getByURL($target);
+
+ $owner = User::getOwnerDataById($uid);
+ $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+ 'type' => 'Reject',
+ 'actor' => $owner['url'],
+ 'object' => ['id' => $id, 'type' => 'Follow',
+ 'actor' => $profile['url'],
+ 'object' => $owner['url']],
+ 'to' => $profile['url']];
+
+ logger('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
+
+ $signed = LDSignature::sign($data, $owner);
+ HTTPSignature::transmit($signed, $profile['inbox'], $uid);
+ }
+
+ /**
+ * @brief
+ *
+ * @param string $target Target profile
+ * @param integer $uid User ID
+ */
+ public static function transmitContactUndo($target, $uid)
+ {
+ $profile = APContact::getByURL($target);
+
+ $id = System::baseUrl() . '/activity/' . System::createGUID();
+
+ $owner = User::getOwnerDataById($uid);
+ $data = ['@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => $id,
+ 'type' => 'Undo',
+ 'actor' => $owner['url'],
+ 'object' => ['id' => $id, 'type' => 'Follow',
+ 'actor' => $owner['url'],
+ 'object' => $profile['url']],
+ 'to' => $profile['url']];
+
+ logger('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id, LOGGER_DEBUG);
+
+ $signed = LDSignature::sign($data, $owner);
+ HTTPSignature::transmit($signed, $profile['inbox'], $uid);
+ }
+
+ /**
+ * Fetches ActivityPub content from the given url
+ *
+ * @param string $url content url
+ * @return array
+ */
+ public static function fetchContent($url)
+ {
+ $ret = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json, application/ld+json']);
+ if (!$ret['success'] || empty($ret['body'])) {
+ return false;
+ }
+
+ return json_decode($ret['body'], true);
+ }
+
+ /**
+ * Fetches a profile from the given url into an array that is compatible to Probe::uri
+ *
+ * @param string $url profile url
+ * @return array
+ */
+ public static function probeProfile($url)
+ {
+ $apcontact = APContact::getByURL($url, true);
+ if (empty($apcontact)) {
+ return false;
+ }
+
+ $profile = ['network' => Protocol::ACTIVITYPUB];
+ $profile['nick'] = $apcontact['nick'];
+ $profile['name'] = $apcontact['name'];
+ $profile['guid'] = $apcontact['uuid'];
+ $profile['url'] = $apcontact['url'];
+ $profile['addr'] = $apcontact['addr'];
+ $profile['alias'] = $apcontact['alias'];
+ $profile['photo'] = $apcontact['photo'];
+ // $profile['community']
+ // $profile['keywords']
+ // $profile['location']
+ $profile['about'] = $apcontact['about'];
+ $profile['batch'] = $apcontact['sharedinbox'];
+ $profile['notify'] = $apcontact['inbox'];
+ $profile['poll'] = $apcontact['outbox'];
+ $profile['pubkey'] = $apcontact['pubkey'];
+ $profile['baseurl'] = $apcontact['baseurl'];
+
+ // Remove all "null" fields