]> git.mxchange.org Git - friendica.git/blob - src/Module/NodeInfo.php
Move .well-known, webfinger, xrd to src/Module/
[friendica.git] / src / Module / NodeInfo.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\App;
6 use Friendica\BaseModule;
7 use Friendica\Core\Addon;
8 use Friendica\Core\System;
9
10 /**
11  * Standardized way of exposing metadata about a server running one of the distributed social networks.
12  * @see https://github.com/jhass/nodeinfo/blob/master/PROTOCOL.md
13  */
14 class NodeInfo extends BaseModule
15 {
16         /**
17          * Prints the Nodeinfo for a well-known request
18          *
19          * @param App $app
20          *
21          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
22          */
23         public static function printWellKnown(App $app)
24         {
25                 $config = $app->getConfig();
26
27                 if (!$config->get('system', 'nodeinfo')) {
28                         System::httpExit(404);
29                 }
30
31                 $nodeinfo = [
32                         'links' => [[
33                                 'rel'  => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
34                                 'href' => $app->getBaseURL() . '/nodeinfo/1.0']]
35                 ];
36
37                 header('Content-type: application/json; charset=utf-8');
38                 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
39                 exit;
40         }
41
42         public static function init()
43         {
44                 $app = self::getApp();
45                 $config = $app->getConfig();
46
47                 if (!$config->get('system', 'nodeinfo')) {
48                         System::httpExit(404);
49                 }
50
51                 if (($app->argc != 2) || ($app->argv[1] != '1.0')) {
52                         self::printWellKnown($app);
53                 }
54         }
55
56         public static function rawContent()
57         {
58                 $config = self::getApp()->getConfig();
59
60                 $smtp = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
61
62                 $nodeinfo = [
63                         'version'           => 1.0,
64                         'software'          => [
65                                 'name'    => 'friendica',
66                                 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
67                         ],
68                         'protocols'         => [
69                                 'inbound'  => [
70                                         'friendica',
71                                 ],
72                                 'outbound' => [
73                                         'friendica',
74                                 ],
75                         ],
76                         'services'          => [
77                                 'inbound'  => [],
78                                 'outbound' => [],
79                         ],
80                         'usage'             => [],
81                         'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
82                         'metadata'          => [
83                                 'nodeName' => $config->get('config', 'sitename'),
84                         ],
85                 ];
86
87                 if (!empty($config->get('system', 'diaspora_enabled'))) {
88                         $nodeinfo['protocols']['inbound'][] = 'diaspora';
89                         $nodeinfo['protocols']['outbound'][] = 'diaspora';
90                 }
91
92                 if (empty($config->get('system', 'ostatus_disabled'))) {
93                         $nodeinfo['protocols']['inbound'][] = 'gnusocial';
94                         $nodeinfo['protocols']['outbound'][] = 'gnusocial';
95                 }
96
97                 if (!empty($config->get('system', 'nodeinfo'))) {
98
99                         $nodeinfo['usage']['users'] = [
100                                 'total'          => intval($config->get('nodeinfo', 'total_users')),
101                                 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
102                                 'activeMonth'    => intval($config->get('nodeinfo', 'active_users_monthly'))
103                         ];
104                         $nodeinfo['usage']['localPosts'] = intval($config->get('nodeinfo', 'local_posts'));
105                         $nodeinfo['usage']['localComments'] = intval($config->get('nodeinfo', 'local_comments'));
106
107                         if (Addon::isEnabled('blogger')) {
108                                 $nodeinfo['services']['outbound'][] = 'blogger';
109                         }
110                         if (Addon::isEnabled('dwpost')) {
111                                 $nodeinfo['services']['outbound'][] = 'dreamwidth';
112                         }
113                         if (Addon::isEnabled('statusnet')) {
114                                 $nodeinfo['services']['inbound'][] = 'gnusocial';
115                                 $nodeinfo['services']['outbound'][] = 'gnusocial';
116                         }
117                         if (Addon::isEnabled('ijpost')) {
118                                 $nodeinfo['services']['outbound'][] = 'insanejournal';
119                         }
120                         if (Addon::isEnabled('libertree')) {
121                                 $nodeinfo['services']['outbound'][] = 'libertree';
122                         }
123                         if (Addon::isEnabled('buffer')) {
124                                 $nodeinfo['services']['outbound'][] = 'linkedin';
125                         }
126                         if (Addon::isEnabled('ljpost')) {
127                                 $nodeinfo['services']['outbound'][] = 'livejournal';
128                         }
129                         if (Addon::isEnabled('buffer')) {
130                                 $nodeinfo['services']['outbound'][] = 'pinterest';
131                         }
132                         if (Addon::isEnabled('posterous')) {
133                                 $nodeinfo['services']['outbound'][] = 'posterous';
134                         }
135                         if (Addon::isEnabled('pumpio')) {
136                                 $nodeinfo['services']['inbound'][] = 'pumpio';
137                                 $nodeinfo['services']['outbound'][] = 'pumpio';
138                         }
139
140                         if ($smtp) {
141                                 $nodeinfo['services']['outbound'][] = 'smtp';
142                         }
143                         if (Addon::isEnabled('tumblr')) {
144                                 $nodeinfo['services']['outbound'][] = 'tumblr';
145                         }
146                         if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
147                                 $nodeinfo['services']['outbound'][] = 'twitter';
148                         }
149                         if (Addon::isEnabled('wppost')) {
150                                 $nodeinfo['services']['outbound'][] = 'wordpress';
151                         }
152                         $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
153                         $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
154                         $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
155                         $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
156
157                         $nodeinfo['metadata']['services'] = $nodeinfo['services'];
158
159                         if (Addon::isEnabled('twitter')) {
160                                 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
161                         }
162
163                         $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
164                 }
165
166                 header('Content-type: application/json; charset=utf-8');
167                 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
168                 exit;
169         }
170 }