mirror of
https://github.com/openvk/openvk
synced 2024-11-15 11:39:13 +03:00
ActivityPub: Very-very early implementation of ActivityPub protocol
Webfinger and host-meta works at least Related to #61 issue
This commit is contained in:
parent
68b822a808
commit
0becdfdb28
3 changed files with 56 additions and 0 deletions
51
Web/Presenters/ActivityPubPresenter.php
Executable file
51
Web/Presenters/ActivityPubPresenter.php
Executable file
|
@ -0,0 +1,51 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
namespace openvk\Web\Presenters;
|
||||||
|
use openvk\Web\Models\Repositories\Users;
|
||||||
|
|
||||||
|
final class ActivityPubPresenter extends OpenVKPresenter
|
||||||
|
{
|
||||||
|
function renderWellKnown(): void
|
||||||
|
{
|
||||||
|
if ($_SERVER['REQUEST_URI'] == "/.well-known/host-meta") {
|
||||||
|
$data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||||
|
. "<XRD xmlns=\"http://docs.oasis-open.org/ns/xri/xrd-1.0\">\n"
|
||||||
|
. " <Link rel=\"lrdd\" template=\"" . ovk_scheme(true) . $_SERVER["SERVER_NAME"] . "/.well-known/webfinger?resource={uri}\">\n"
|
||||||
|
. "</XRD>\n";
|
||||||
|
|
||||||
|
header("Content-Type: application/xrd+xml; charset=utf-8");
|
||||||
|
exit($data);
|
||||||
|
} else if ($this->startsWith($_SERVER["REQUEST_URI"], '/.well-known/webfinger') && $this->startsWith($this->requestParam("resource"), 'acct:')) {
|
||||||
|
$username = array();
|
||||||
|
$subject = substr($this->requestParam("resource"), 5, strlen($this->requestParam("resource")));
|
||||||
|
preg_match('/([a-zA-Z0-9-_]+)@([a-zA-Z0-9-_\.]+)/', $subject, $username);
|
||||||
|
$username = $username[1];
|
||||||
|
|
||||||
|
$user = (new Users)->getByShortURL($username);
|
||||||
|
|
||||||
|
if($user !== null) {
|
||||||
|
$response->subject = $this->requestParam("resource");
|
||||||
|
|
||||||
|
$response->links[] = array(
|
||||||
|
'rel' => 'self',
|
||||||
|
'href' => ovk_scheme(true) . $_SERVER["SERVER_NAME"] . '/id' . $user->getId(),
|
||||||
|
'type' => 'application/activity+json'
|
||||||
|
);
|
||||||
|
|
||||||
|
header("Access-Control-Allow-Origin: *");
|
||||||
|
$this->returnJson((array) $response);
|
||||||
|
} else {
|
||||||
|
header("HTTP/2 404 Not Found");
|
||||||
|
exit();
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
header("HTTP/2 404 Not Found");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function startsWith($string, $startString)
|
||||||
|
{
|
||||||
|
$len = strlen($startString);
|
||||||
|
return (substr($string, 0, $len) === $startString);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ services:
|
||||||
- openvk\Web\Presenters\TopicsPresenter
|
- openvk\Web\Presenters\TopicsPresenter
|
||||||
- openvk\Web\Presenters\ThemepacksPresenter
|
- openvk\Web\Presenters\ThemepacksPresenter
|
||||||
- openvk\Web\Presenters\VKAPIPresenter
|
- openvk\Web\Presenters\VKAPIPresenter
|
||||||
|
- openvk\Web\Presenters\ActivityPubPresenter
|
||||||
- openvk\Web\Models\Repositories\Users
|
- openvk\Web\Models\Repositories\Users
|
||||||
- openvk\Web\Models\Repositories\Posts
|
- openvk\Web\Models\Repositories\Posts
|
||||||
- openvk\Web\Models\Repositories\Photos
|
- openvk\Web\Models\Repositories\Photos
|
||||||
|
|
|
@ -265,6 +265,10 @@ routes:
|
||||||
handler: "About->sandbox"
|
handler: "About->sandbox"
|
||||||
- url: "/internal/wall{num}"
|
- url: "/internal/wall{num}"
|
||||||
handler: "Wall->wallEmbedded"
|
handler: "Wall->wallEmbedded"
|
||||||
|
- url: "/.well-known/{?uri}"
|
||||||
|
handler: "ActivityPub->WellKnown"
|
||||||
|
placeholders:
|
||||||
|
uri: ".+"
|
||||||
- url: "/{?shortCode}"
|
- url: "/{?shortCode}"
|
||||||
handler: "UnknownTextRouteStrategy->delegate"
|
handler: "UnknownTextRouteStrategy->delegate"
|
||||||
placeholders:
|
placeholders:
|
||||||
|
|
Loading…
Reference in a new issue