mirror of
https://github.com/openvk/openvk
synced 2025-04-19 14:43:01 +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,
|
"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]));
|
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);
|
<?php declare(strict_types=1);
|
||||||
namespace openvk\Web\Models\Repositories;
|
namespace openvk\Web\Models\Repositories;
|
||||||
use openvk\Web\Models\Entities\User;
|
use openvk\Web\Models\Entities\User;
|
||||||
|
use openvk\Web\Models\Repositories\Posts;
|
||||||
|
use openvk\Web\Models\Repositories\Comments;
|
||||||
use Nette\Database\Table\ActiveRow;
|
use Nette\Database\Table\ActiveRow;
|
||||||
use Chandler\Database\DatabaseConnection;
|
use Chandler\Database\DatabaseConnection;
|
||||||
use Chandler\Security\User as ChandlerUser;
|
use Chandler\Security\User as ChandlerUser;
|
||||||
|
@ -50,6 +52,8 @@ class Users
|
||||||
"all" => sizeof(clone $this->users),
|
"all" => sizeof(clone $this->users),
|
||||||
"active" => sizeof((clone $this->users)->where("online > 0")),
|
"active" => sizeof((clone $this->users)->where("online > 0")),
|
||||||
"online" => sizeof((clone $this->users)->where("online >= ?", time() - 900)),
|
"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");
|
header("Content-Type: application/xrd+xml; charset=utf-8");
|
||||||
exit($data);
|
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:')) {
|
} else if ($this->startsWith($_SERVER["REQUEST_URI"], '/.well-known/webfinger') && $this->startsWith($this->requestParam("resource"), 'acct:')) {
|
||||||
$username = array();
|
$username = array();
|
||||||
$subject = substr($this->requestParam("resource"), 5, strlen($this->requestParam("resource")));
|
$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)
|
private function startsWith($string, $startString)
|
||||||
{
|
{
|
||||||
$len = strlen($startString);
|
$len = strlen($startString);
|
||||||
|
|
|
@ -269,6 +269,8 @@ routes:
|
||||||
handler: "ActivityPub->WellKnown"
|
handler: "ActivityPub->WellKnown"
|
||||||
placeholders:
|
placeholders:
|
||||||
uri: ".+"
|
uri: ".+"
|
||||||
|
- url: "/nodeinfo/2.0"
|
||||||
|
handler: "ActivityPub->nodeinfo"
|
||||||
- url: "/{?shortCode}"
|
- url: "/{?shortCode}"
|
||||||
handler: "UnknownTextRouteStrategy->delegate"
|
handler: "UnknownTextRouteStrategy->delegate"
|
||||||
placeholders:
|
placeholders:
|
||||||
|
|
Loading…
Reference in a new issue