3 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Core\Addon;
10 * Standardized way of exposing metadata about a server running one of the distributed social networks.
11 * @see https://github.com/jhass/nodeinfo/blob/master/PROTOCOL.md
13 class NodeInfo extends BaseModule
15 public static function rawContent(array $parameters = [])
17 if ($parameters['version'] == '1.0') {
18 self::printNodeInfo1();
19 } elseif ($parameters['version'] == '2.0') {
20 self::printNodeInfo2();
22 throw new \Friendica\Network\HTTPException\NotFoundException();
27 * Return the supported services
29 * @return array with supported services
31 private static function getUsage()
33 $config = DI::config();
37 if (!empty($config->get('system', 'nodeinfo'))) {
39 'total' => intval($config->get('nodeinfo', 'total_users')),
40 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
41 'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly'))
43 $usage['localPosts'] = intval($config->get('nodeinfo', 'local_posts'));
44 $usage['localComments'] = intval($config->get('nodeinfo', 'local_comments'));
51 * Return the supported services
53 * @return array with supported services
55 private static function getServices()
62 if (Addon::isEnabled('blogger')) {
63 $services['outbound'][] = 'blogger';
65 if (Addon::isEnabled('dwpost')) {
66 $services['outbound'][] = 'dreamwidth';
68 if (Addon::isEnabled('statusnet')) {
69 $services['inbound'][] = 'gnusocial';
70 $services['outbound'][] = 'gnusocial';
72 if (Addon::isEnabled('ijpost')) {
73 $services['outbound'][] = 'insanejournal';
75 if (Addon::isEnabled('libertree')) {
76 $services['outbound'][] = 'libertree';
78 if (Addon::isEnabled('buffer')) {
79 $services['outbound'][] = 'linkedin';
81 if (Addon::isEnabled('ljpost')) {
82 $services['outbound'][] = 'livejournal';
84 if (Addon::isEnabled('buffer')) {
85 $services['outbound'][] = 'pinterest';
87 if (Addon::isEnabled('posterous')) {
88 $services['outbound'][] = 'posterous';
90 if (Addon::isEnabled('pumpio')) {
91 $services['inbound'][] = 'pumpio';
92 $services['outbound'][] = 'pumpio';
95 $services['outbound'][] = 'smtp';
97 if (Addon::isEnabled('tumblr')) {
98 $services['outbound'][] = 'tumblr';
100 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
101 $services['outbound'][] = 'twitter';
103 if (Addon::isEnabled('wppost')) {
104 $services['outbound'][] = 'wordpress';
111 * Print the nodeinfo version 1
113 private static function printNodeInfo1()
115 $config = DI::config();
120 'name' => 'Friendica',
121 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
125 'friendica', 'activitypub'
128 'friendica', 'activitypub'
133 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
135 'nodeName' => $config->get('config', 'sitename'),
139 if (!empty($config->get('system', 'diaspora_enabled'))) {
140 $nodeinfo['protocols']['inbound'][] = 'diaspora';
141 $nodeinfo['protocols']['outbound'][] = 'diaspora';
144 if (empty($config->get('system', 'ostatus_disabled'))) {
145 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
146 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
149 $nodeinfo['usage'] = self::getUsage();
151 $nodeinfo['services'] = self::getServices();
153 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
154 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
155 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
156 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
158 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
160 if (Addon::isEnabled('twitter')) {
161 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
164 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
166 header('Content-type: application/json; charset=utf-8');
167 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
172 * Print the nodeinfo version 2
174 private static function printNodeInfo2()
176 $config = DI::config();
178 $imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
183 'name' => 'Friendica',
184 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
186 'protocols' => ['dfrn', 'activitypub'],
189 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
191 'nodeName' => $config->get('config', 'sitename'),
195 if (!empty($config->get('system', 'diaspora_enabled'))) {
196 $nodeinfo['protocols'][] = 'diaspora';
199 if (empty($config->get('system', 'ostatus_disabled'))) {
200 $nodeinfo['protocols'][] = 'ostatus';
203 $nodeinfo['usage'] = self::getUsage();
205 $nodeinfo['services'] = self::getServices();
207 if (Addon::isEnabled('twitter')) {
208 $nodeinfo['services']['inbound'][] = 'twitter';
211 $nodeinfo['services']['inbound'][] = 'atom1.0';
212 $nodeinfo['services']['inbound'][] = 'rss2.0';
213 $nodeinfo['services']['outbound'][] = 'atom1.0';
216 $nodeinfo['services']['inbound'][] = 'imap';
219 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
221 header('Content-type: application/json; charset=utf-8');
222 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);