]> git.mxchange.org Git - friendica.git/blob - src/Module/NodeInfo110.php
Module classes splitted
[friendica.git] / src / Module / NodeInfo110.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, a standardized 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 NodeInfo110 extends BaseModule
34 {
35         public static function rawContent(array $parameters = [])
36         {
37                 $config = DI::config();
38
39                 $nodeinfo = [
40                         'version'           => '1.0',
41                         'software'          => [
42                                 'name'    => 'friendica',
43                                 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
44                         ],
45                         'protocols'         => [
46                                 'inbound'  => [
47                                         'friendica'
48                                 ],
49                                 'outbound' => [
50                                         'friendica'
51                                 ],
52                         ],
53                         'services'          => [],
54                         'usage'             => [],
55                         'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
56                         'metadata'          => [
57                                 'nodeName' => $config->get('config', 'sitename'),
58                         ],
59                 ];
60
61                 if (!empty($config->get('system', 'diaspora_enabled'))) {
62                         $nodeinfo['protocols']['inbound'][] = 'diaspora';
63                         $nodeinfo['protocols']['outbound'][] = 'diaspora';
64                 }
65
66                 if (empty($config->get('system', 'ostatus_disabled'))) {
67                         $nodeinfo['protocols']['inbound'][] = 'gnusocial';
68                         $nodeinfo['protocols']['outbound'][] = 'gnusocial';
69                 }
70
71                 $nodeinfo['usage'] = Nodeinfo::getUsage();
72
73                 $nodeinfo['services'] = Nodeinfo::getServices();
74
75                 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
76                 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
77                 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
78                 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
79
80                 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
81
82                 if (Addon::isEnabled('twitter')) {
83                         $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
84                 }
85
86                 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
87
88                 header('Content-type: application/json; charset=utf-8');
89                 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
90                 exit;
91         }
92 }