]> git.mxchange.org Git - friendica.git/blob - src/Module/NodeInfo210.php
Module classes splitted
[friendica.git] / src / Module / NodeInfo210.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\Addon;
26 use Friendica\DI;
27 use Friendica\Model\Nodeinfo;
28
29 /**
30  * Version 1.0 of Nodeinfo 2, a sStandardized way of exposing metadata about a server running one of the distributed social networks.
31  * @see https://github.com/jhass/nodeinfo/blob/master/PROTOCOL.md
32  */
33 class NodeInfo210 extends BaseModule
34 {
35         public static function rawContent(array $parameters = [])
36         {
37                 $config = DI::config();
38
39                 $imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
40
41                 $nodeinfo = [
42                         'version'           => '1.0',
43                         'server'          => [
44                                 'baseUrl'  => DI::baseUrl()->get(),
45                                 'name'     => $config->get('config', 'sitename'),
46                                 'software' => 'friendica',
47                                 'version'  => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
48                         ],
49                         'organization'      => Nodeinfo::getOrganization($config),
50                         'protocols'         => ['dfrn', 'activitypub'],
51                         'services'          => [],
52                         'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
53                         'usage'             => [],
54                 ];
55
56                 if (!empty($config->get('system', 'diaspora_enabled'))) {
57                         $nodeinfo['protocols'][] = 'diaspora';
58                 }
59
60                 if (empty($config->get('system', 'ostatus_disabled'))) {
61                         $nodeinfo['protocols'][] = 'ostatus';
62                 }
63
64                 $nodeinfo['usage'] = Nodeinfo::getUsage(true);
65
66                 $nodeinfo['services'] = Nodeinfo::getServices();
67
68                 if (Addon::isEnabled('twitter')) {
69                         $nodeinfo['services']['inbound'][] = 'twitter';
70                 }
71
72                 $nodeinfo['services']['inbound'][]  = 'atom1.0';
73                 $nodeinfo['services']['inbound'][]  = 'rss2.0';
74                 $nodeinfo['services']['outbound'][] = 'atom1.0';
75
76                 if ($imap) {
77                         $nodeinfo['services']['inbound'][] = 'imap';
78                 }
79
80                 header('Content-type: application/json; charset=utf-8');
81                 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
82                 exit;
83         }
84 }