3 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Core\Addon;
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 if ($parameters['version'] == '1.0') {
19 self::printNodeInfo1();
20 } elseif ($parameters['version'] == '2.0') {
21 self::printNodeInfo2();
23 throw new \Friendica\Network\HTTPException\NotFoundException();
28 * Return the supported services
30 * @return Object with supported services
32 private static function getUsage()
34 $config = DI::config();
36 $usage = new stdClass();
38 if (!empty($config->get('system', 'nodeinfo'))) {
40 'total' => intval($config->get('nodeinfo', 'total_users')),
41 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
42 'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly'))
44 $usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
45 $usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
52 * Return the supported services
54 * @return array with supported services
56 private static function getServices()
63 if (Addon::isEnabled('blogger')) {
64 $services['outbound'][] = 'blogger';
66 if (Addon::isEnabled('dwpost')) {
67 $services['outbound'][] = 'dreamwidth';
69 if (Addon::isEnabled('statusnet')) {
70 $services['inbound'][] = 'gnusocial';
71 $services['outbound'][] = 'gnusocial';
73 if (Addon::isEnabled('ijpost')) {
74 $services['outbound'][] = 'insanejournal';
76 if (Addon::isEnabled('libertree')) {
77 $services['outbound'][] = 'libertree';
79 if (Addon::isEnabled('buffer')) {
80 $services['outbound'][] = 'linkedin';
82 if (Addon::isEnabled('ljpost')) {
83 $services['outbound'][] = 'livejournal';
85 if (Addon::isEnabled('buffer')) {
86 $services['outbound'][] = 'pinterest';
88 if (Addon::isEnabled('posterous')) {
89 $services['outbound'][] = 'posterous';
91 if (Addon::isEnabled('pumpio')) {
92 $services['inbound'][] = 'pumpio';
93 $services['outbound'][] = 'pumpio';
96 $services['outbound'][] = 'smtp';
98 if (Addon::isEnabled('tumblr')) {
99 $services['outbound'][] = 'tumblr';
101 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
102 $services['outbound'][] = 'twitter';
104 if (Addon::isEnabled('wppost')) {
105 $services['outbound'][] = 'wordpress';
112 * Print the nodeinfo version 1
114 private static function printNodeInfo1()
116 $config = DI::config();
121 'name' => 'Friendica',
122 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
126 'friendica', 'activitypub'
129 'friendica', 'activitypub'
134 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
136 'nodeName' => $config->get('config', 'sitename'),
140 if (!empty($config->get('system', 'diaspora_enabled'))) {
141 $nodeinfo['protocols']['inbound'][] = 'diaspora';
142 $nodeinfo['protocols']['outbound'][] = 'diaspora';
145 if (empty($config->get('system', 'ostatus_disabled'))) {
146 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
147 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
150 $nodeinfo['usage'] = self::getUsage();
152 $nodeinfo['services'] = self::getServices();
154 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
155 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
156 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
157 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
159 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
161 if (Addon::isEnabled('twitter')) {
162 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
165 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
167 header('Content-type: application/json; charset=utf-8');
168 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
173 * Print the nodeinfo version 2
175 private static function printNodeInfo2()
177 $config = DI::config();
179 $imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
184 'name' => 'Friendica',
185 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
187 'protocols' => ['dfrn', 'activitypub'],
190 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
192 'nodeName' => $config->get('config', 'sitename'),
196 if (!empty($config->get('system', 'diaspora_enabled'))) {
197 $nodeinfo['protocols'][] = 'diaspora';
200 if (empty($config->get('system', 'ostatus_disabled'))) {
201 $nodeinfo['protocols'][] = 'ostatus';
204 $nodeinfo['usage'] = self::getUsage();
206 $nodeinfo['services'] = self::getServices();
208 if (Addon::isEnabled('twitter')) {
209 $nodeinfo['services']['inbound'][] = 'twitter';
212 $nodeinfo['services']['inbound'][] = 'atom1.0';
213 $nodeinfo['services']['inbound'][] = 'rss2.0';
214 $nodeinfo['services']['outbound'][] = 'atom1.0';
217 $nodeinfo['services']['inbound'][] = 'imap';
220 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
222 header('Content-type: application/json; charset=utf-8');
223 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);