]> git.mxchange.org Git - friendica.git/commitdiff
Add nodeinfo 2.1 and 2.2
authorMichael <heluecht@pirati.ca>
Sat, 15 Jun 2024 22:32:23 +0000 (22:32 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 16 Jun 2024 08:38:37 +0000 (08:38 +0000)
src/Module/NodeInfo120.php
src/Module/NodeInfo121.php [new file with mode: 0644]
src/Module/NodeInfo122.php [new file with mode: 0644]
src/Module/NodeInfo210.php
src/Module/WellKnown/NodeInfo.php
static/routes.config.php

index efd6943f7d46bfa107ef660248224e3a80de593e..237d0d6bc565781ff75dec63007d8d9aa22f2f29 100644 (file)
@@ -56,8 +56,8 @@ class NodeInfo120 extends BaseModule
                        ],
                        'protocols'         => ['dfrn', 'activitypub'],
                        'services'          => Nodeinfo::getServices(),
-                       'usage'             => Nodeinfo::getUsage(),
                        'openRegistrations' => Register::getPolicy() !== Register::CLOSED,
+                       'usage'             => Nodeinfo::getUsage(),
                        'metadata'          => [
                                'nodeName' => $this->config->get('config', 'sitename'),
                        ],
diff --git a/src/Module/NodeInfo121.php b/src/Module/NodeInfo121.php
new file mode 100644 (file)
index 0000000..731699e
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2024, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module;
+
+use Friendica\App;
+use Friendica\BaseModule;
+use Friendica\Capabilities\ICanCreateResponses;
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\L10n;
+use Friendica\Model\Nodeinfo;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Version 2.1 of Nodeinfo, a standardized way of exposing metadata about a server running one of the distributed social networks.
+ * @see https://github.com/jhass/nodeinfo/blob/master/PROTOCOL.md
+ */
+class NodeInfo121 extends BaseModule
+{
+       /** @var IManageConfigValues */
+       protected $config;
+
+       public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
+       {
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->config = $config;
+       }
+
+       protected function rawContent(array $request = [])
+       {
+               $nodeinfo = [
+                       'version'  => '2.1',
+                       'software' => [
+                               'name'       => 'friendica',
+                               'version'    => App::VERSION . '-' . DB_UPDATE_VERSION,
+                               'repository' => 'https://github.com/friendica/friendica',
+                               'homepage'   => 'https://friendi.ca',
+                       ],
+                       'protocols'         => ['dfrn', 'activitypub'],
+                       'services'          => Nodeinfo::getServices(),
+                       'openRegistrations' => Register::getPolicy() !== Register::CLOSED,
+                       'usage'             => Nodeinfo::getUsage(),
+                       'metadata'          => [],
+               ];
+
+               if (!empty($this->config->get('system', 'diaspora_enabled'))) {
+                       $nodeinfo['protocols'][] = 'diaspora';
+               }
+
+               if (empty($this->config->get('system', 'ostatus_disabled'))) {
+                       $nodeinfo['protocols'][] = 'ostatus';
+               }
+
+               $nodeinfo['services']['inbound'][]  = 'atom1.0';
+               $nodeinfo['services']['inbound'][]  = 'rss2.0';
+               $nodeinfo['services']['outbound'][] = 'atom1.0';
+
+               if (function_exists('imap_open') && !$this->config->get('system', 'imap_disabled')) {
+                       $nodeinfo['services']['inbound'][] = 'imap';
+               }
+
+               $nodeinfo['metadata']['explicitContent'] = $this->config->get('system', 'explicit_content', false) == true;
+
+               $this->response->setType(ICanCreateResponses::TYPE_JSON, 'application/json; charset=utf-8');
+               $this->response->addContent(json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
+       }
+}
diff --git a/src/Module/NodeInfo122.php b/src/Module/NodeInfo122.php
new file mode 100644 (file)
index 0000000..8ec45af
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2024, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module;
+
+use Friendica\App;
+use Friendica\BaseModule;
+use Friendica\Capabilities\ICanCreateResponses;
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\L10n;
+use Friendica\Model\Nodeinfo;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Version 2.2 of Nodeinfo, a standardized way of exposing metadata about a server running one of the distributed social networks.
+ * @see https://github.com/jhass/nodeinfo/blob/master/PROTOCOL.md
+ */
+class NodeInfo122 extends BaseModule
+{
+       /** @var IManageConfigValues */
+       protected $config;
+
+       public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
+       {
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->config = $config;
+       }
+
+       protected function rawContent(array $request = [])
+       {
+               $nodeinfo = [
+                       'version'   => '2.2',
+                       'instance'  => [
+                               'name'        => $this->config->get('config', 'sitename'),
+                               'description' => $this->config->get('config', 'info'),
+                       ],
+                       'software'  => [
+                               'name'       => 'friendica',
+                               'version'    => App::VERSION . '-' . DB_UPDATE_VERSION,
+                               'repository' => 'https://github.com/friendica/friendica',
+                               'homepage'   => 'https://friendi.ca',
+                       ],
+                       'protocols'         => ['dfrn', 'activitypub'],
+                       'services'          => Nodeinfo::getServices(),
+                       'openRegistrations' => Register::getPolicy() !== Register::CLOSED,
+                       'usage'             => Nodeinfo::getUsage(),
+                       'metadata'          => [],
+               ];
+
+               if (!empty($this->config->get('system', 'diaspora_enabled'))) {
+                       $nodeinfo['protocols'][] = 'diaspora';
+               }
+
+               if (empty($this->config->get('system', 'ostatus_disabled'))) {
+                       $nodeinfo['protocols'][] = 'ostatus';
+               }
+
+               $nodeinfo['services']['inbound'][]  = 'atom1.0';
+               $nodeinfo['services']['inbound'][]  = 'rss2.0';
+               $nodeinfo['services']['outbound'][] = 'atom1.0';
+
+               if (function_exists('imap_open') && !$this->config->get('system', 'imap_disabled')) {
+                       $nodeinfo['services']['inbound'][] = 'imap';
+               }
+
+               $nodeinfo['metadata']['explicitContent'] = $this->config->get('system', 'explicit_content', false) == true;
+
+               $this->response->setType(ICanCreateResponses::TYPE_JSON, 'application/json; charset=utf-8');
+               $this->response->addContent(json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
+       }
+}
index ff22adf398d8c27b0655e0e5b2a0ddf340eea614..fdfe4ed5cf0aa70461647889113484f348b08403 100644 (file)
@@ -32,7 +32,7 @@ use Psr\Log\LoggerInterface;
 
 /**
  * Version 1.0 of Nodeinfo 2, a sStandardized way of exposing metadata about a server running one of the distributed social networks.
- * @see https://github.com/jhass/nodeinfo/blob/master/PROTOCOL.md
+ * @see https://github.com/jaywink/nodeinfo2/blob/master/PROTOCOL.md
  */
 class NodeInfo210 extends BaseModule
 {
index 816aa9c20e5af349c79dbb2fc201f81eeb91bc54..129c8c77b496f93b43981a23f20827acca83e202 100644 (file)
@@ -22,7 +22,6 @@
 namespace Friendica\Module\WellKnown;
 
 use Friendica\BaseModule;
-use Friendica\Core\System;
 use Friendica\DI;
 
 /**
@@ -35,10 +34,22 @@ class NodeInfo extends BaseModule
        {
                $nodeinfo = [
                        'links' => [
-                               ['rel'  => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
-                                'href' => DI::baseUrl() . '/nodeinfo/1.0'],
-                               ['rel'  => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
-                                'href' => DI::baseUrl() . '/nodeinfo/2.0'],
+                               [
+                                       'rel'  => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
+                                       'href' => DI::baseUrl() . '/nodeinfo/1.0'
+                               ],
+                               [
+                                       'rel'  => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
+                                       'href' => DI::baseUrl() . '/nodeinfo/2.0'
+                               ],
+                               [
+                                       'rel'  => 'http://nodeinfo.diaspora.software/ns/schema/2.1',
+                                       'href' => DI::baseUrl() . '/nodeinfo/2.1'
+                               ],
+                               [
+                                       'rel'  => 'http://nodeinfo.diaspora.software/ns/schema/2.2',
+                                       'href' => DI::baseUrl() . '/nodeinfo/2.2'
+                               ],
                        ]
                ];
 
index dfd414c44410dbed1a79bcd8da5a762afda80e79..181ba4d77b44f30161ba35888d3c5eb9a3995861 100644 (file)
@@ -525,6 +525,9 @@ return [
        '/newmember'          => [Module\Welcome::class,         [R::GET]],
        '/nodeinfo/1.0'       => [Module\NodeInfo110::class,     [R::GET]],
        '/nodeinfo/2.0'       => [Module\NodeInfo120::class,     [R::GET]],
+       '/nodeinfo/2.0.json'  => [Module\NodeInfo120::class,     [R::GET]],
+       '/nodeinfo/2.1'       => [Module\NodeInfo121::class,     [R::GET]],
+       '/nodeinfo/2.2'       => [Module\NodeInfo122::class,     [R::GET]],
        '/nocircle'           => [Module\Circle::class,          [R::GET]],
 
        '/noscrape' => [