3 namespace Friendica\Module;
6 use Friendica\BaseModule;
7 use Friendica\Core\Addon;
8 use Friendica\Core\System;
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
14 class NodeInfo extends BaseModule
16 public static function rawContent(array $parameters = [])
18 $app = self::getApp();
20 // @TODO: Replace with parameter from router
21 // if the first argument is ".well-known", print the well-known text
22 if (($app->argc > 1) && ($app->argv[0] == '.well-known')) {
23 self::printWellKnown($app);
24 // otherwise print the nodeinfo
25 } elseif ($parameters['version'] == '1.0') {
26 self::printNodeInfo1($app);
27 } elseif ($parameters['version'] == '2.0') {
28 self::printNodeInfo2($app);
30 throw new \Friendica\Network\HTTPException\NotFoundException();
35 * Prints the well-known nodeinfo redirect
39 * @throws \Friendica\Network\HTTPException\NotFoundException
41 private static function printWellKnown(App $app)
45 ['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
46 'href' => $app->getBaseURL() . '/nodeinfo/1.0'],
47 ['rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
48 'href' => $app->getBaseURL() . '/nodeinfo/2.0'],
52 header('Content-type: application/json; charset=utf-8');
53 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
58 * Return the supported services
62 * @return array with supported services
64 private static function getUsage(App $app)
66 $config = $app->getConfig();
70 if (!empty($config->get('system', 'nodeinfo'))) {
72 'total' => intval($config->get('nodeinfo', 'total_users')),
73 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
74 'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly'))
76 $usage['localPosts'] = intval($config->get('nodeinfo', 'local_posts'));
77 $usage['localComments'] = intval($config->get('nodeinfo', 'local_comments'));
84 * Return the supported services
88 * @return array with supported services
90 private static function getServices(App $app)
92 $config = $app->getConfig();
99 $smtp = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
101 if (Addon::isEnabled('blogger')) {
102 $services['outbound'][] = 'blogger';
104 if (Addon::isEnabled('dwpost')) {
105 $services['outbound'][] = 'dreamwidth';
107 if (Addon::isEnabled('statusnet')) {
108 $services['inbound'][] = 'gnusocial';
109 $services['outbound'][] = 'gnusocial';
111 if (Addon::isEnabled('ijpost')) {
112 $services['outbound'][] = 'insanejournal';
114 if (Addon::isEnabled('libertree')) {
115 $services['outbound'][] = 'libertree';
117 if (Addon::isEnabled('buffer')) {
118 $services['outbound'][] = 'linkedin';
120 if (Addon::isEnabled('ljpost')) {
121 $services['outbound'][] = 'livejournal';
123 if (Addon::isEnabled('buffer')) {
124 $services['outbound'][] = 'pinterest';
126 if (Addon::isEnabled('posterous')) {
127 $services['outbound'][] = 'posterous';
129 if (Addon::isEnabled('pumpio')) {
130 $services['inbound'][] = 'pumpio';
131 $services['outbound'][] = 'pumpio';
134 $services['outbound'][] = 'smtp';
136 if (Addon::isEnabled('tumblr')) {
137 $services['outbound'][] = 'tumblr';
139 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
140 $services['outbound'][] = 'twitter';
142 if (Addon::isEnabled('wppost')) {
143 $services['outbound'][] = 'wordpress';
150 * Print the nodeinfo version 1
154 private static function printNodeInfo1(App $app)
156 $config = $app->getConfig();
161 'name' => 'friendica',
162 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
166 'friendica', 'activitypub'
169 'friendica', 'activitypub'
174 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
176 'nodeName' => $config->get('config', 'sitename'),
180 if (!empty($config->get('system', 'diaspora_enabled'))) {
181 $nodeinfo['protocols']['inbound'][] = 'diaspora';
182 $nodeinfo['protocols']['outbound'][] = 'diaspora';
185 if (empty($config->get('system', 'ostatus_disabled'))) {
186 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
187 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
190 $nodeinfo['usage'] = self::getUsage($app);
192 $nodeinfo['services'] = self::getServices($app);
194 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
195 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
196 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
197 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
199 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
201 if (Addon::isEnabled('twitter')) {
202 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
205 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
207 header('Content-type: application/json; charset=utf-8');
208 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
213 * Print the nodeinfo version 2
217 private static function printNodeInfo2(App $app)
219 $config = $app->getConfig();
224 'name' => 'friendica',
225 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
227 'protocols' => ['dfrn', 'activitypub'],
230 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
232 'nodeName' => $config->get('config', 'sitename'),
236 if (!empty($config->get('system', 'diaspora_enabled'))) {
237 $nodeinfo['protocols'][] = 'diaspora';
240 if (empty($config->get('system', 'ostatus_disabled'))) {
241 $nodeinfo['protocols'][] = 'ostatus';
244 $nodeinfo['usage'] = self::getUsage($app);
246 $nodeinfo['services'] = self::getServices($app);
248 if (Addon::isEnabled('twitter')) {
249 $nodeinfo['services']['inbound'][] = 'twitter';
252 $nodeinfo['services']['inbound'][] = 'atom1.0';
253 $nodeinfo['services']['inbound'][] = 'rss2.0';
254 $nodeinfo['services']['outbound'][] = 'atom1.0';
256 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
258 header('Content-type: application/json; charset=utf-8');
259 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);