Proper ActivityPub profiles
This commit is contained in:
parent
e0d5b2ebd7
commit
01c16fcef0
@ -302,9 +302,11 @@ class ActivityPubPlugin extends Plugin
|
||||
public function onEndWebFingerProfileLinks(XML_XRD &$xrd, Managed_DataObject $object)
|
||||
{
|
||||
if ($object->isPerson()) {
|
||||
$link = new XML_XRD_Element_Link ('self',
|
||||
$link = new XML_XRD_Element_Link(
|
||||
'self',
|
||||
ActivityPubPlugin::actor_uri($object->getProfile()),
|
||||
'application/activity+json');
|
||||
'application/activity+json'
|
||||
);
|
||||
$xrd->links[] = clone ($link);
|
||||
}
|
||||
}
|
||||
|
@ -84,39 +84,49 @@ class Activitypub_profile extends Profile
|
||||
$uri = ActivityPubPlugin::actor_uri($profile);
|
||||
$id = $profile->getID();
|
||||
$res = [
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
[
|
||||
"@language" => "en"
|
||||
]
|
||||
],
|
||||
'id' => $uri,
|
||||
'type' => 'Person',
|
||||
'preferredUsername' => $profile->getNickname(),
|
||||
'is_local' => $profile->isLocal(),
|
||||
'inbox' => common_local_url("apActorInbox", array("id" => $id)),
|
||||
'name' => $profile->getFullname(),
|
||||
'followers' => common_local_url("apActorFollowers", array("id" => $id)),
|
||||
'followers_count' => $profile->subscriberCount(),
|
||||
'following' => common_local_url("apActorFollowing", array("id" => $id)),
|
||||
'following_count' => $profile->subscriptionCount(),
|
||||
'liked' => common_local_url("apActorLiked", array("id" => $id)),
|
||||
'liked_count' => Fave::countByProfile($profile),
|
||||
'summary' => ($desc = $profile->getDescription()) == null ? "" : $desc,
|
||||
'icon' => [
|
||||
'type' => 'Image',
|
||||
'width' => AVATAR_PROFILE_SIZE,
|
||||
'height' => AVATAR_PROFILE_SIZE,
|
||||
'url' => $profile->avatarUrl(AVATAR_PROFILE_SIZE)
|
||||
]
|
||||
];
|
||||
'@context' => [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
[
|
||||
'manuallyApprovesFollowers' => 'as=>manuallyApprovesFollowers',
|
||||
'sensitive' => 'as=>sensitive',
|
||||
'movedTo' => 'as=>movedTo',
|
||||
'Hashtag' => 'as=>Hashtag',
|
||||
'ostatus' => 'http=>//ostatus.org#',
|
||||
'atomUri' => 'ostatus=>atomUri',
|
||||
'inReplyToAtomUri' => 'ostatus=>inReplyToAtomUri',
|
||||
'conversation' => 'ostatus=>conversation',
|
||||
'schema' => 'http=>//schema.org#',
|
||||
'PropertyValue' => 'schema=>PropertyValue',
|
||||
'value' => 'schema=>value'
|
||||
]
|
||||
],
|
||||
'id' => $uri,
|
||||
'type' => 'Person',
|
||||
'following' => common_local_url("apActorFollowing", array("id" => $id)),
|
||||
'followers' => common_local_url("apActorFollowers", array("id" => $id)),
|
||||
'liked' => common_local_url("apActorLiked", array("id" => $id)),
|
||||
'inbox' => common_local_url("apActorInbox", array("id" => $id)),
|
||||
'preferredUsername' => $profile->getNickname(),
|
||||
'name' => $profile->getFullname(),
|
||||
'summary' => ($desc = $profile->getDescription()) == null ? "" : $desc,
|
||||
'url' => $profile->getUrl(),
|
||||
'manuallyApprovesFollowers' => false,
|
||||
'tag' => [],
|
||||
'attachment' => [],
|
||||
'icon' => [
|
||||
'type' => 'Image',
|
||||
'mediaType' => 'image/jpeg',
|
||||
'url' => $profile->avatarUrl()
|
||||
]
|
||||
];
|
||||
|
||||
if ($profile->isLocal()) {
|
||||
$res["sharedInbox"] = common_local_url("apSharedInbox", array("id" => $id));
|
||||
$res['endpoints']['sharedInbox'] = common_local_url("apSharedInbox", array("id" => $id));
|
||||
} else {
|
||||
$aprofile = new Activitypub_profile();
|
||||
$aprofile = $aprofile->from_profile($profile);
|
||||
$res["sharedInbox"] = $aprofile->sharedInboxuri;
|
||||
$res['endpoints']['sharedInbox'] = $aprofile->sharedInboxuri;
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
@ -203,12 +203,12 @@ class Activitypub_explorer
|
||||
private function store_profile($res)
|
||||
{
|
||||
$aprofile = new Activitypub_profile;
|
||||
$aprofile->uri = $res["id"];
|
||||
$aprofile->nickname = $res["preferredUsername"];
|
||||
$aprofile->fullname = $res["name"];
|
||||
$aprofile->bio = substr($res["summary"], 0, 1000);
|
||||
$aprofile->inboxuri = $res["inbox"];
|
||||
$aprofile->sharedInboxuri = isset($res["sharedInbox"]) ? $res["sharedInbox"] : $res["inbox"];
|
||||
$aprofile->uri = $res['id'];
|
||||
$aprofile->nickname = $res['preferredUsername'];
|
||||
$aprofile->fullname = $res['name'];
|
||||
$aprofile->bio = substr($res['summary'], 0, 1000);
|
||||
$aprofile->inboxuri = $res['inbox'];
|
||||
$aprofile->sharedInboxuri = isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : $res['inbox'];
|
||||
|
||||
$aprofile->do_insert();
|
||||
|
||||
@ -225,7 +225,7 @@ class Activitypub_explorer
|
||||
*/
|
||||
private static function validate_remote_response($res)
|
||||
{
|
||||
if (!isset($res["id"], $res["preferredUsername"], $res["name"], $res["summary"], $res["inbox"])) {
|
||||
if (!isset($res['id'], $res['preferredUsername'], $res['name'], $res['summary'], $res['inbox'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -247,12 +247,14 @@ class Activitypub_explorer
|
||||
$headers[] = 'User-Agent: GNUSocialBot v0.1 - https://gnu.io/social';
|
||||
$response = $client->get($url, $headers);
|
||||
if (!$response->isOk()) {
|
||||
throw new Exception("Invalid Actor URL.");
|
||||
throw new Exception('Invalid Actor URL.');
|
||||
}
|
||||
$res = json_decode($response->getBody(), JSON_UNESCAPED_SLASHES);
|
||||
if (self::validate_remote_response($res)) {
|
||||
return array("inbox" => $res["inbox"],
|
||||
"sharedInbox" => isset($res["sharedInbox"]) ? $res["sharedInbox"] : $res["inbox"]);
|
||||
return [
|
||||
'inbox' => $res['inbox'],
|
||||
'sharedInbox' => isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : $res['inbox']
|
||||
];
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user