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)
97 if (Addon::isEnabled('blogger')) {
98 $services['outbound'][] = 'blogger';
100 if (Addon::isEnabled('dwpost')) {
101 $services['outbound'][] = 'dreamwidth';
103 if (Addon::isEnabled('statusnet')) {
104 $services['inbound'][] = 'gnusocial';
105 $services['outbound'][] = 'gnusocial';
107 if (Addon::isEnabled('ijpost')) {
108 $services['outbound'][] = 'insanejournal';
110 if (Addon::isEnabled('libertree')) {
111 $services['outbound'][] = 'libertree';
113 if (Addon::isEnabled('buffer')) {
114 $services['outbound'][] = 'linkedin';
116 if (Addon::isEnabled('ljpost')) {
117 $services['outbound'][] = 'livejournal';
119 if (Addon::isEnabled('buffer')) {
120 $services['outbound'][] = 'pinterest';
122 if (Addon::isEnabled('posterous')) {
123 $services['outbound'][] = 'posterous';
125 if (Addon::isEnabled('pumpio')) {
126 $services['inbound'][] = 'pumpio';
127 $services['outbound'][] = 'pumpio';
130 $services['outbound'][] = 'smtp';
132 if (Addon::isEnabled('tumblr')) {
133 $services['outbound'][] = 'tumblr';
135 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
136 $services['outbound'][] = 'twitter';
138 if (Addon::isEnabled('wppost')) {
139 $services['outbound'][] = 'wordpress';
146 * Print the nodeinfo version 1
150 private static function printNodeInfo1(App $app)
152 $config = $app->getConfig();
157 'name' => 'friendica',
158 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
162 'friendica', 'activitypub'
165 'friendica', 'activitypub'
170 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
172 'nodeName' => $config->get('config', 'sitename'),
176 if (!empty($config->get('system', 'diaspora_enabled'))) {
177 $nodeinfo['protocols']['inbound'][] = 'diaspora';
178 $nodeinfo['protocols']['outbound'][] = 'diaspora';
181 if (empty($config->get('system', 'ostatus_disabled'))) {
182 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
183 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
186 $nodeinfo['usage'] = self::getUsage($app);
188 $nodeinfo['services'] = self::getServices($app);
190 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
191 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
192 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
193 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
195 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
197 if (Addon::isEnabled('twitter')) {
198 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
201 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
203 header('Content-type: application/json; charset=utf-8');
204 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
209 * Print the nodeinfo version 2
213 private static function printNodeInfo2(App $app)
215 $config = $app->getConfig();
217 $imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
222 'name' => 'friendica',
223 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
225 'protocols' => ['dfrn', 'activitypub'],
228 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
230 'nodeName' => $config->get('config', 'sitename'),
234 if (!empty($config->get('system', 'diaspora_enabled'))) {
235 $nodeinfo['protocols'][] = 'diaspora';
238 if (empty($config->get('system', 'ostatus_disabled'))) {
239 $nodeinfo['protocols'][] = 'ostatus';
242 $nodeinfo['usage'] = self::getUsage($app);
244 $nodeinfo['services'] = self::getServices($app);
246 if (Addon::isEnabled('twitter')) {
247 $nodeinfo['services']['inbound'][] = 'twitter';
250 $nodeinfo['services']['inbound'][] = 'atom1.0';
251 $nodeinfo['services']['inbound'][] = 'rss2.0';
252 $nodeinfo['services']['outbound'][] = 'atom1.0';
255 $nodeinfo['services']['inbound'][] = 'imap';
258 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
260 header('Content-type: application/json; charset=utf-8');
261 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);