friendica-github/src/Module/NodeInfo210.php

69 lines
2.3 KiB
PHP
Raw Normal View History

2020-07-13 09:45:45 +00:00
<?php
2024-08-24 13:27:00 +00:00
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
2020-07-13 09:45:45 +00:00
namespace Friendica\Module;
2021-11-21 20:52:36 +00:00
use Friendica\App;
use Friendica\App\Arguments;
use Friendica\App\BaseURL;
2020-07-13 09:45:45 +00:00
use Friendica\BaseModule;
use Friendica\Capabilities\ICanCreateResponses;
2021-11-21 20:52:36 +00:00
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
2020-07-13 09:45:45 +00:00
use Friendica\Model\Nodeinfo;
2021-11-21 20:52:36 +00:00
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
2020-07-13 09:45:45 +00:00
/**
* Version 1.0 of Nodeinfo 2, a sStandardized way of exposing metadata about a server running one of the distributed social networks.
2024-06-15 22:32:23 +00:00
* @see https://github.com/jaywink/nodeinfo2/blob/master/PROTOCOL.md
2020-07-13 09:45:45 +00:00
*/
class NodeInfo210 extends BaseModule
{
2021-11-21 20:52:36 +00:00
/** @var IManageConfigValues */
protected $config;
public function __construct(L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
2020-07-13 09:45:45 +00:00
{
2021-11-21 20:52:36 +00:00
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->config = $config;
}
2020-07-13 09:45:45 +00:00
2021-11-21 20:52:36 +00:00
protected function rawContent(array $request = [])
{
2020-07-13 09:45:45 +00:00
$nodeinfo = [
2021-11-21 20:52:36 +00:00
'version' => '1.0',
'server' => [
'name' => $this->config->get('config', 'sitename'),
2020-07-13 09:45:45 +00:00
'software' => 'friendica',
'version' => App::VERSION . '-' . DB_UPDATE_VERSION,
2020-07-13 09:45:45 +00:00
],
2021-11-21 20:52:36 +00:00
'organization' => Nodeinfo::getOrganization($this->config),
2020-07-13 09:45:45 +00:00
'protocols' => ['dfrn', 'activitypub'],
'services' => Nodeinfo::getServices(),
'openRegistrations' => Register::getPolicy() !== Register::CLOSED,
'usage' => Nodeinfo::getUsage(true),
2020-07-13 09:45:45 +00:00
];
2021-11-21 20:52:36 +00:00
if (!empty($this->config->get('system', 'diaspora_enabled'))) {
2020-07-13 09:45:45 +00:00
$nodeinfo['protocols'][] = 'diaspora';
}
$nodeinfo['services']['inbound'][] = 'atom1.0';
$nodeinfo['services']['inbound'][] = 'rss2.0';
$nodeinfo['services']['outbound'][] = 'atom1.0';
2021-11-21 20:52:36 +00:00
if (function_exists('imap_open') && !$this->config->get('system', 'imap_disabled')) {
2020-07-13 09:45:45 +00:00
$nodeinfo['services']['inbound'][] = 'imap';
}
$this->response->setType(ICanCreateResponses::TYPE_JSON, 'application/json; charset=utf-8');
2021-11-21 21:07:23 +00:00
$this->response->addContent(json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
2020-07-13 09:45:45 +00:00
}
}