mirror of
https://github.com/openvk/openvk
synced 2025-04-19 22:53:06 +03:00
ActivityPub: Reply with a user info if the Access header is application/activity+json
This commit is contained in:
parent
a0ccbc9af2
commit
12fc156113
3 changed files with 76 additions and 0 deletions
|
@ -101,6 +101,14 @@ class User extends RowModel
|
||||||
return "/id" . $this->getId();
|
return "/id" . $this->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFullURL(bool $numberic = false): string
|
||||||
|
{
|
||||||
|
if(!$numberic && !is_null($this->getShortCode()))
|
||||||
|
return ovk_scheme(true) . $_SERVER["SERVER_NAME"] . "/" . $this->getShortCode();
|
||||||
|
else
|
||||||
|
return ovk_scheme(true) . $_SERVER["SERVER_NAME"] . "/id" . $this->getId();
|
||||||
|
}
|
||||||
|
|
||||||
function getAvatarUrl(): string
|
function getAvatarUrl(): string
|
||||||
{
|
{
|
||||||
$serverUrl = ovk_scheme(true) . $_SERVER["SERVER_NAME"];
|
$serverUrl = ovk_scheme(true) . $_SERVER["SERVER_NAME"];
|
||||||
|
|
|
@ -262,4 +262,45 @@ abstract class OpenVKPresenter extends SimplePresenter
|
||||||
header("Content-Length: $size");
|
header("Content-Length: $size");
|
||||||
exit($payload);
|
exit($payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isActivityPubClient(): bool
|
||||||
|
{
|
||||||
|
return $_SERVER['HTTP_ACCEPT'] == 'application/activity+json';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPersonContext()
|
||||||
|
{
|
||||||
|
// Sometimes i being lazy...
|
||||||
|
return json_decode('[
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
{
|
||||||
|
"sm": "http://smithereen.software/ns#",
|
||||||
|
"wall": {
|
||||||
|
"@id": "sm:wall",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"sc": "http://schema.org#",
|
||||||
|
"firstName": "sc:givenName",
|
||||||
|
"lastName": "sc:familyName",
|
||||||
|
"middleName": "sc:additionalName",
|
||||||
|
"gender": {
|
||||||
|
"@id": "sc:gender",
|
||||||
|
"@type": "sc:GenderType"
|
||||||
|
},
|
||||||
|
"supportsFriendRequests": "sm:supportsFriendRequests",
|
||||||
|
"maidenName": "sm:maidenName",
|
||||||
|
"friends": {
|
||||||
|
"@id": "sm:friends",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"groups": {
|
||||||
|
"@id": "sm:groups",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"vcard": "http://www.w3.org/2006/vcard/ns#"
|
||||||
|
},
|
||||||
|
"https://w3id.org/security/v1"
|
||||||
|
]');
|
||||||
|
// Гришк)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,33 @@ final class UserPresenter extends OpenVKPresenter
|
||||||
if(!$user || $user->isDeleted())
|
if(!$user || $user->isDeleted())
|
||||||
$this->notFound();
|
$this->notFound();
|
||||||
else {
|
else {
|
||||||
|
/* ActivityPub quirks :DDDD */
|
||||||
|
if($this->isActivityPubClient()) {
|
||||||
|
$objUser = array(
|
||||||
|
"type" => "Person",
|
||||||
|
"id" => $user->getFullURL(true),
|
||||||
|
"name" => $user->getFullName(),
|
||||||
|
"summary" => $user->getDescription(),
|
||||||
|
"url" => $user->getFullURL(),
|
||||||
|
"prefferedUsername" => $user->getShortCode(),
|
||||||
|
"inbox" => $user->getFullURL() . "/inbox",
|
||||||
|
"outbox" => $user->getFullURL() . "/outbox",
|
||||||
|
"endpoints" => array("sharedInbox" => ovk_scheme(true) . $_SERVER['SERVER_NAME']),
|
||||||
|
"wall" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $user->getId(),
|
||||||
|
"firstName" => $user->getFirstName(),
|
||||||
|
"lastName" => $user->getLastName(),
|
||||||
|
"middleName" => $user->getPseudo(), // Unlike Smithereen, the Middle name in OpenVK is a Nickname
|
||||||
|
"vcard:bday" => $user->getBirthday()->format('%d-%m-%Y'),
|
||||||
|
"gender" => "http://schema.org#" . $user->isFemale() ? "Male" : "Female",
|
||||||
|
"supportsFriendRequests" => true,
|
||||||
|
"friends" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/friends" . $user->getId(),
|
||||||
|
"groups" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/groups" . $user->getId(),
|
||||||
|
"@context" => $this->getPersonContext()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->returnJson($objUser);
|
||||||
|
}
|
||||||
|
|
||||||
if($user->getShortCode())
|
if($user->getShortCode())
|
||||||
if(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH) !== "/" . $user->getShortCode())
|
if(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH) !== "/" . $user->getShortCode())
|
||||||
$this->redirect("/" . $user->getShortCode(), static::REDIRECT_TEMPORARY_PRESISTENT);
|
$this->redirect("/" . $user->getShortCode(), static::REDIRECT_TEMPORARY_PRESISTENT);
|
||||||
|
|
Loading…
Reference in a new issue