mirror of
https://github.com/openvk/openvk
synced 2024-11-15 03:31:18 +03:00
ActivityPub: Add a NodeInfo
This commit is contained in:
parent
0becdfdb28
commit
a0ccbc9af2
5 changed files with 45 additions and 3 deletions
|
@ -59,4 +59,9 @@ class Comments
|
|||
"deleted" => false,
|
||||
]));
|
||||
}
|
||||
|
||||
function getCountOfAllComments(): int
|
||||
{
|
||||
return sizeof($this->comments->where(["deleted" => false]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,4 +105,9 @@ class Posts
|
|||
{
|
||||
return sizeof($this->posts->where(["wall" => $user, "deleted" => 0]));
|
||||
}
|
||||
|
||||
function getCountOfAllPosts(): int
|
||||
{
|
||||
return sizeof($this->posts->where(["deleted" => 0]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Models\Repositories;
|
||||
use openvk\Web\Models\Entities\User;
|
||||
use openvk\Web\Models\Repositories\Posts;
|
||||
use openvk\Web\Models\Repositories\Comments;
|
||||
use Nette\Database\Table\ActiveRow;
|
||||
use Chandler\Database\DatabaseConnection;
|
||||
use Chandler\Security\User as ChandlerUser;
|
||||
|
@ -47,9 +49,11 @@ class Users
|
|||
function getStatistics(): object
|
||||
{
|
||||
return (object) [
|
||||
"all" => sizeof(clone $this->users),
|
||||
"active" => sizeof((clone $this->users)->where("online > 0")),
|
||||
"online" => sizeof((clone $this->users)->where("online >= ?", time() - 900)),
|
||||
"all" => sizeof(clone $this->users),
|
||||
"active" => sizeof((clone $this->users)->where("online > 0")),
|
||||
"online" => sizeof((clone $this->users)->where("online >= ?", time() - 900)),
|
||||
"posts" => (new Posts)->getCountOfAllPosts(),
|
||||
"comments" => (new Comments)->getCountOfAllComments()
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,13 @@ final class ActivityPubPresenter extends OpenVKPresenter
|
|||
|
||||
header("Content-Type: application/xrd+xml; charset=utf-8");
|
||||
exit($data);
|
||||
} else if ($_SERVER['REQUEST_URI'] == "/.well-known/nodeinfo") {
|
||||
$response->links = array(array(
|
||||
"href" => ovk_scheme(true) . $_SERVER["SERVER_NAME"] . '/nodeinfo/2.0',
|
||||
'rel' => "http://nodeinfo.diaspora.software/ns/schema/2.0"
|
||||
));
|
||||
|
||||
$this->returnJson((array) $response);
|
||||
} 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")));
|
||||
|
@ -43,6 +50,25 @@ final class ActivityPubPresenter extends OpenVKPresenter
|
|||
}
|
||||
}
|
||||
|
||||
function renderNodeinfo()
|
||||
{
|
||||
$stats = (new Users)->getStatistics();
|
||||
|
||||
$response->version = '2.0';
|
||||
$response->protocols = array('activitypub');
|
||||
$response->openRegistrations = OPENVK_ROOT_CONF['openvk']['preferences']['registration']['enable'];
|
||||
$response->software = array('name' => 'openvk',
|
||||
'version' => OPENVK_VERSION);
|
||||
$response->usage = array('localPosts' => $stats->posts,
|
||||
'localComments' => $stats->comments,
|
||||
'users' => array(
|
||||
'total' => $stats->all
|
||||
));
|
||||
$response->metadata = (object)array();
|
||||
|
||||
$this->returnJson((array) $response);
|
||||
}
|
||||
|
||||
private function startsWith($string, $startString)
|
||||
{
|
||||
$len = strlen($startString);
|
||||
|
|
|
@ -269,6 +269,8 @@ routes:
|
|||
handler: "ActivityPub->WellKnown"
|
||||
placeholders:
|
||||
uri: ".+"
|
||||
- url: "/nodeinfo/2.0"
|
||||
handler: "ActivityPub->nodeinfo"
|
||||
- url: "/{?shortCode}"
|
||||
handler: "UnknownTextRouteStrategy->delegate"
|
||||
placeholders:
|
||||
|
|
Loading…
Reference in a new issue