X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FActivityPub.php;h=78496e2433de2e87fb8db7378f8251db9d536cf5;hb=47a3d8e6ce8461a457dee46d43d5ad14166f8013;hp=9d6223a748d4d090d060ef3c97a037c70635a4e3;hpb=669124e72f2adb9ae151bf78f48275b1858fbbbf;p=friendica.git diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 9d6223a748..78496e2433 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -1,6 +1,6 @@ 'http://purl.org/macgirvin/dfrn/1.0/', 'diaspora' => 'https://diasporafoundation.org/ns/', 'litepub' => 'http://litepub.social/ns#', + 'toot' => 'http://joinmastodon.org/ns#', + 'featured' => [ + "@id" => "toot:featured", + "@type" => "@id", + ], + 'schema' => 'http://schema.org#', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag', - 'directMessage' => 'litepub:directMessage']]; - const ACCOUNT_TYPES = ['Person', 'Organization', 'Service', 'Group', 'Application']; + 'directMessage' => 'litepub:directMessage', + 'discoverable' => 'toot:discoverable', + 'PropertyValue' => 'schema:PropertyValue', + 'value' => 'schema:value', + ]]; + const ACCOUNT_TYPES = ['Person', 'Organization', 'Service', 'Group', 'Application', 'Tombstone']; /** * Checks if the web request is done for the AP protocol * @@ -75,8 +85,15 @@ class ActivityPub */ public static function isRequest() { - return stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') || + $isrequest = stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') || + stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/json') || stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json'); + + if ($isrequest) { + Logger::debug('Is AP request', ['accept' => $_SERVER['HTTP_ACCEPT'], 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '']); + } + + return $isrequest; } /** @@ -87,24 +104,9 @@ class ActivityPub * @return array * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function fetchContent($url, $uid = 0) + public static function fetchContent(string $url, int $uid = 0) { - if (!empty($uid)) { - return HTTPSignature::fetch($url, $uid); - } - - $curlResult = Network::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']); - if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { - return false; - } - - $content = json_decode($curlResult->getBody(), true); - - if (empty($content) || !is_array($content)) { - return false; - } - - return $content; + return HTTPSignature::fetch($url, $uid); } private static function getAccountType($apcontact) @@ -127,6 +129,9 @@ class ActivityPub case 'Application': $accounttype = User::ACCOUNT_TYPE_RELAY; break; + case 'Tombstone': + $accounttype = User::ACCOUNT_TYPE_DELETED; + break; } return $accounttype; @@ -145,7 +150,7 @@ class ActivityPub { $apcontact = APContact::getByURL($url, $update); if (empty($apcontact)) { - return false; + return []; } $profile = ['network' => Protocol::ACTIVITYPUB]; @@ -161,18 +166,27 @@ class ActivityPub $profile['outbox'] = $apcontact['outbox']; $profile['sharedinbox'] = $apcontact['sharedinbox']; $profile['photo'] = $apcontact['photo']; + $profile['header'] = $apcontact['header']; $profile['account-type'] = self::getAccountType($apcontact); $profile['community'] = ($profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY); // $profile['keywords'] // $profile['location'] $profile['about'] = $apcontact['about']; + $profile['xmpp'] = $apcontact['xmpp']; + $profile['matrix'] = $apcontact['matrix']; $profile['batch'] = $apcontact['sharedinbox']; $profile['notify'] = $apcontact['inbox']; $profile['poll'] = $apcontact['outbox']; $profile['pubkey'] = $apcontact['pubkey']; + $profile['subscribe'] = $apcontact['subscribe']; + $profile['manually-approve'] = $apcontact['manually-approve']; $profile['baseurl'] = $apcontact['baseurl']; $profile['gsid'] = $apcontact['gsid']; + if (!is_null($apcontact['discoverable'])) { + $profile['hide'] = !$apcontact['discoverable']; + } + // Remove all "null" fields foreach ($profile as $field => $content) { if (is_null($content)) {