3 * @file mod/nodeinfo.php
5 * Documentation: http://nodeinfo.diaspora.software/schema.html
9 use Friendica\Core\Addon;
10 use Friendica\Core\Config;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
13 use Friendica\Util\Network;
14 require_once 'include/dba.php';
16 function nodeinfo_wellknown(App $a) {
17 $nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
18 'href' => System::baseUrl().'/nodeinfo/1.0']]];
20 header('Content-type: application/json; charset=utf-8');
21 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
25 function nodeinfo_init(App $a) {
26 if (!Config::get('system', 'nodeinfo')) {
27 System::httpExit(404);
31 if (($a->argc != 2) || ($a->argv[1] != '1.0')) {
32 System::httpExit(404);
36 $smtp = (function_exists('imap_open') && !Config::get('system', 'imap_disabled') && !Config::get('system', 'dfrn_only'));
39 $nodeinfo['version'] = '1.0';
40 $nodeinfo['software'] = ['name' => 'friendica', 'version' => FRIENDICA_VERSION.'-'.DB_UPDATE_VERSION];
42 $nodeinfo['protocols'] = [];
43 $nodeinfo['protocols']['inbound'] = [];
44 $nodeinfo['protocols']['outbound'] = [];
46 if (Config::get('system', 'diaspora_enabled')) {
47 $nodeinfo['protocols']['inbound'][] = 'diaspora';
48 $nodeinfo['protocols']['outbound'][] = 'diaspora';
51 $nodeinfo['protocols']['inbound'][] = 'friendica';
52 $nodeinfo['protocols']['outbound'][] = 'friendica';
54 if (!Config::get('system', 'ostatus_disabled')) {
55 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
56 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
59 $nodeinfo['services'] = [];
60 $nodeinfo['services']['inbound'] = [];
61 $nodeinfo['services']['outbound'] = [];
63 $nodeinfo['usage'] = [];
65 $nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED;
67 $nodeinfo['metadata'] = ['nodeName' => Config::get('config', 'sitename')];
69 if (Config::get('system', 'nodeinfo')) {
71 $nodeinfo['usage']['users'] = ['total' => (int)Config::get('nodeinfo', 'total_users'),
72 'activeHalfyear' => (int)Config::get('nodeinfo', 'active_users_halfyear'),
73 'activeMonth' => (int)Config::get('nodeinfo', 'active_users_monthly')];
74 $nodeinfo['usage']['localPosts'] = (int)Config::get('nodeinfo', 'local_posts');
75 $nodeinfo['usage']['localComments'] = (int)Config::get('nodeinfo', 'local_comments');
77 if (Addon::isEnabled('appnet')) {
78 $nodeinfo['services']['inbound'][] = 'appnet';
80 if (Addon::isEnabled('appnet') || Addon::isEnabled('buffer')) {
81 $nodeinfo['services']['outbound'][] = 'appnet';
83 if (Addon::isEnabled('blogger')) {
84 $nodeinfo['services']['outbound'][] = 'blogger';
86 if (Addon::isEnabled('dwpost')) {
87 $nodeinfo['services']['outbound'][] = 'dreamwidth';
89 if (Addon::isEnabled('fbpost') || Addon::isEnabled('buffer')) {
90 $nodeinfo['services']['outbound'][] = 'facebook';
92 if (Addon::isEnabled('statusnet')) {
93 $nodeinfo['services']['inbound'][] = 'gnusocial';
94 $nodeinfo['services']['outbound'][] = 'gnusocial';
97 if (Addon::isEnabled('gpluspost') || Addon::isEnabled('buffer')) {
98 $nodeinfo['services']['outbound'][] = 'google';
100 if (Addon::isEnabled('ijpost')) {
101 $nodeinfo['services']['outbound'][] = 'insanejournal';
103 if (Addon::isEnabled('libertree')) {
104 $nodeinfo['services']['outbound'][] = 'libertree';
106 if (Addon::isEnabled('buffer')) {
107 $nodeinfo['services']['outbound'][] = 'linkedin';
109 if (Addon::isEnabled('ljpost')) {
110 $nodeinfo['services']['outbound'][] = 'livejournal';
112 if (Addon::isEnabled('buffer')) {
113 $nodeinfo['services']['outbound'][] = 'pinterest';
115 if (Addon::isEnabled('posterous')) {
116 $nodeinfo['services']['outbound'][] = 'posterous';
118 if (Addon::isEnabled('pumpio')) {
119 $nodeinfo['services']['inbound'][] = 'pumpio';
120 $nodeinfo['services']['outbound'][] = 'pumpio';
124 $nodeinfo['services']['outbound'][] = 'smtp';
126 if (Addon::isEnabled('tumblr')) {
127 $nodeinfo['services']['outbound'][] = 'tumblr';
129 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
130 $nodeinfo['services']['outbound'][] = 'twitter';
132 if (Addon::isEnabled('wppost')) {
133 $nodeinfo['services']['outbound'][] = 'wordpress';
135 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
136 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
137 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
138 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
140 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
142 if (Addon::isEnabled('twitter')) {
143 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
146 $nodeinfo['metadata']['explicitContent'] = Config::get('system', 'explicit_content', false) == true;
149 header('Content-type: application/json; charset=utf-8');
150 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
156 function nodeinfo_cron() {
160 // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
161 if (Addon::isEnabled('statistics_json')) {
162 Config::set('system', 'nodeinfo', true);
164 $addon = 'statistics_json';
165 $addons = Config::get('system', 'addon');
169 $addons_arr = explode(',',str_replace(' ', '',$addons));
171 $idx = array_search($addon, $addons_arr);
172 if ($idx !== false) {
173 unset($addons_arr[$idx]);
174 Addon::uninstall($addon);
175 Config::set('system', 'addon', implode(', ',$addons_arr));
180 if (!Config::get('system', 'nodeinfo')) {
184 logger('cron_start');
186 $users = q("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
188 INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
189 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
190 WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
191 AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
192 AND NOT `user`.`account_expired`");
193 if (is_array($users)) {
194 $total_users = count($users);
195 $active_users_halfyear = 0;
196 $active_users_monthly = 0;
198 $halfyear = time() - (180 * 24 * 60 * 60);
199 $month = time() - (30 * 24 * 60 * 60);
201 foreach ($users AS $user) {
202 if ((strtotime($user['login_date']) > $halfyear) ||
203 (strtotime($user['last-item']) > $halfyear)) {
204 ++$active_users_halfyear;
206 if ((strtotime($user['login_date']) > $month) ||
207 (strtotime($user['last-item']) > $month)) {
208 ++$active_users_monthly;
211 Config::set('nodeinfo', 'total_users', $total_users);
212 Config::set('nodeinfo', 'active_users_halfyear', $active_users_halfyear);
213 Config::set('nodeinfo', 'active_users_monthly', $active_users_monthly);
215 logger('total_users: ' . $total_users . '/' . $active_users_halfyear. '/' . $active_users_monthly, LOGGER_DEBUG);
218 $local_posts = DBA::count('thread', ["`wall` AND NOT `deleted` AND `uid` != 0"]);
219 Config::set('nodeinfo', 'local_posts', $local_posts);
220 logger('local_posts: ' . $local_posts, LOGGER_DEBUG);
222 $local_comments = DBA::count('item', ["`origin` AND `id` != `parent` AND NOT `deleted` AND `uid` != 0"]);
223 Config::set('nodeinfo', 'local_comments', $local_comments);
224 logger('local_comments: ' . $local_comments, LOGGER_DEBUG);
226 // Now trying to register
227 $url = 'http://the-federation.info/register/'.$a->get_hostname();
228 logger('registering url: '.$url, LOGGER_DEBUG);
229 $ret = Network::fetchUrl($url);
230 logger('registering answer: '.$ret, LOGGER_DEBUG);