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 if ($parameters['version'] == '1.0') {
21 self::printNodeInfo1($app);
22 } elseif ($parameters['version'] == '2.0') {
23 self::printNodeInfo2($app);
25 throw new \Friendica\Network\HTTPException\NotFoundException();
30 * Return the supported services
34 * @return array with supported services
36 private static function getUsage(App $app)
38 $config = $app->getConfig();
42 if (!empty($config->get('system', 'nodeinfo'))) {
44 'total' => intval($config->get('nodeinfo', 'total_users')),
45 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
46 'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly'))
48 $usage['localPosts'] = intval($config->get('nodeinfo', 'local_posts'));
49 $usage['localComments'] = intval($config->get('nodeinfo', 'local_comments'));
56 * Return the supported services
60 * @return array with supported services
62 private static function getServices(App $app)
69 if (Addon::isEnabled('blogger')) {
70 $services['outbound'][] = 'blogger';
72 if (Addon::isEnabled('dwpost')) {
73 $services['outbound'][] = 'dreamwidth';
75 if (Addon::isEnabled('statusnet')) {
76 $services['inbound'][] = 'gnusocial';
77 $services['outbound'][] = 'gnusocial';
79 if (Addon::isEnabled('ijpost')) {
80 $services['outbound'][] = 'insanejournal';
82 if (Addon::isEnabled('libertree')) {
83 $services['outbound'][] = 'libertree';
85 if (Addon::isEnabled('buffer')) {
86 $services['outbound'][] = 'linkedin';
88 if (Addon::isEnabled('ljpost')) {
89 $services['outbound'][] = 'livejournal';
91 if (Addon::isEnabled('buffer')) {
92 $services['outbound'][] = 'pinterest';
94 if (Addon::isEnabled('posterous')) {
95 $services['outbound'][] = 'posterous';
97 if (Addon::isEnabled('pumpio')) {
98 $services['inbound'][] = 'pumpio';
99 $services['outbound'][] = 'pumpio';
102 $services['outbound'][] = 'smtp';
104 if (Addon::isEnabled('tumblr')) {
105 $services['outbound'][] = 'tumblr';
107 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
108 $services['outbound'][] = 'twitter';
110 if (Addon::isEnabled('wppost')) {
111 $services['outbound'][] = 'wordpress';
118 * Print the nodeinfo version 1
122 private static function printNodeInfo1(App $app)
124 $config = $app->getConfig();
129 'name' => 'Friendica',
130 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
134 'friendica', 'activitypub'
137 'friendica', 'activitypub'
142 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
144 'nodeName' => $config->get('config', 'sitename'),
148 if (!empty($config->get('system', 'diaspora_enabled'))) {
149 $nodeinfo['protocols']['inbound'][] = 'diaspora';
150 $nodeinfo['protocols']['outbound'][] = 'diaspora';
153 if (empty($config->get('system', 'ostatus_disabled'))) {
154 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
155 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
158 $nodeinfo['usage'] = self::getUsage($app);
160 $nodeinfo['services'] = self::getServices($app);
162 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
163 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
164 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
165 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
167 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
169 if (Addon::isEnabled('twitter')) {
170 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
173 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
175 header('Content-type: application/json; charset=utf-8');
176 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
181 * Print the nodeinfo version 2
185 private static function printNodeInfo2(App $app)
187 $config = $app->getConfig();
189 $imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
194 'name' => 'Friendica',
195 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
197 'protocols' => ['dfrn', 'activitypub'],
200 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
202 'nodeName' => $config->get('config', 'sitename'),
206 if (!empty($config->get('system', 'diaspora_enabled'))) {
207 $nodeinfo['protocols'][] = 'diaspora';
210 if (empty($config->get('system', 'ostatus_disabled'))) {
211 $nodeinfo['protocols'][] = 'ostatus';
214 $nodeinfo['usage'] = self::getUsage($app);
216 $nodeinfo['services'] = self::getServices($app);
218 if (Addon::isEnabled('twitter')) {
219 $nodeinfo['services']['inbound'][] = 'twitter';
222 $nodeinfo['services']['inbound'][] = 'atom1.0';
223 $nodeinfo['services']['inbound'][] = 'rss2.0';
224 $nodeinfo['services']['outbound'][] = 'atom1.0';
227 $nodeinfo['services']['inbound'][] = 'imap';
230 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
232 header('Content-type: application/json; charset=utf-8');
233 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);