3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module;
24 use Friendica\BaseModule;
25 use Friendica\Core\Addon;
30 * Standardized way of exposing metadata about a server running one of the distributed social networks.
31 * @see https://github.com/jhass/nodeinfo/blob/master/PROTOCOL.md
33 class NodeInfo extends BaseModule
35 public static function rawContent(array $parameters = [])
37 if ($parameters['version'] == '1.0') {
38 self::printNodeInfo1();
39 } elseif ($parameters['version'] == '2.0') {
40 self::printNodeInfo2();
42 throw new \Friendica\Network\HTTPException\NotFoundException();
47 * Return the supported services
49 * @return Object with supported services
51 private static function getUsage()
53 $config = DI::config();
55 $usage = new stdClass();
57 if (!empty($config->get('system', 'nodeinfo'))) {
59 'total' => intval($config->get('nodeinfo', 'total_users')),
60 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
61 'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly'))
63 $usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
64 $usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
71 * Return the supported services
73 * @return array with supported services
75 private static function getServices()
82 if (Addon::isEnabled('blogger')) {
83 $services['outbound'][] = 'blogger';
85 if (Addon::isEnabled('dwpost')) {
86 $services['outbound'][] = 'dreamwidth';
88 if (Addon::isEnabled('statusnet')) {
89 $services['inbound'][] = 'gnusocial';
90 $services['outbound'][] = 'gnusocial';
92 if (Addon::isEnabled('ijpost')) {
93 $services['outbound'][] = 'insanejournal';
95 if (Addon::isEnabled('libertree')) {
96 $services['outbound'][] = 'libertree';
98 if (Addon::isEnabled('buffer')) {
99 $services['outbound'][] = 'linkedin';
101 if (Addon::isEnabled('ljpost')) {
102 $services['outbound'][] = 'livejournal';
104 if (Addon::isEnabled('buffer')) {
105 $services['outbound'][] = 'pinterest';
107 if (Addon::isEnabled('posterous')) {
108 $services['outbound'][] = 'posterous';
110 if (Addon::isEnabled('pumpio')) {
111 $services['inbound'][] = 'pumpio';
112 $services['outbound'][] = 'pumpio';
115 $services['outbound'][] = 'smtp';
117 if (Addon::isEnabled('tumblr')) {
118 $services['outbound'][] = 'tumblr';
120 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
121 $services['outbound'][] = 'twitter';
123 if (Addon::isEnabled('wppost')) {
124 $services['outbound'][] = 'wordpress';
131 * Print the nodeinfo version 1
133 private static function printNodeInfo1()
135 $config = DI::config();
140 'name' => 'friendica',
141 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
153 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
155 'nodeName' => $config->get('config', 'sitename'),
159 if (!empty($config->get('system', 'diaspora_enabled'))) {
160 $nodeinfo['protocols']['inbound'][] = 'diaspora';
161 $nodeinfo['protocols']['outbound'][] = 'diaspora';
164 if (empty($config->get('system', 'ostatus_disabled'))) {
165 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
166 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
169 $nodeinfo['usage'] = self::getUsage();
171 $nodeinfo['services'] = self::getServices();
173 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
174 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
175 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
176 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
178 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
180 if (Addon::isEnabled('twitter')) {
181 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
184 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
186 header('Content-type: application/json; charset=utf-8');
187 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
192 * Print the nodeinfo version 2
194 private static function printNodeInfo2()
196 $config = DI::config();
198 $imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
203 'name' => 'friendica',
204 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
206 'protocols' => ['dfrn', 'activitypub'],
209 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
211 'nodeName' => $config->get('config', 'sitename'),
215 if (!empty($config->get('system', 'diaspora_enabled'))) {
216 $nodeinfo['protocols'][] = 'diaspora';
219 if (empty($config->get('system', 'ostatus_disabled'))) {
220 $nodeinfo['protocols'][] = 'ostatus';
223 $nodeinfo['usage'] = self::getUsage();
225 $nodeinfo['services'] = self::getServices();
227 if (Addon::isEnabled('twitter')) {
228 $nodeinfo['services']['inbound'][] = 'twitter';
231 $nodeinfo['services']['inbound'][] = 'atom1.0';
232 $nodeinfo['services']['inbound'][] = 'rss2.0';
233 $nodeinfo['services']['outbound'][] = 'atom1.0';
236 $nodeinfo['services']['inbound'][] = 'imap';
239 $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
241 header('Content-type: application/json; charset=utf-8');
242 echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);