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\Logger;
12 use Friendica\Core\System;
13 use Friendica\Database\DBA;
14 use Friendica\Util\Network;
15 require_once 'include/dba.php';
17 function nodeinfo_wellknown(App $a) {
18 $nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
19 'href' => System::baseUrl().'/nodeinfo/1.0']]];
21 header('Content-type: application/json; charset=utf-8');
22 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
26 function nodeinfo_init(App $a) {
27 if (!Config::get('system', 'nodeinfo')) {
28 System::httpExit(404);
32 if (($a->argc != 2) || ($a->argv[1] != '1.0')) {
33 System::httpExit(404);
37 $smtp = (function_exists('imap_open') && !Config::get('system', 'imap_disabled') && !Config::get('system', 'dfrn_only'));
40 $nodeinfo['version'] = '1.0';
41 $nodeinfo['software'] = ['name' => 'friendica', 'version' => FRIENDICA_VERSION.'-'.DB_UPDATE_VERSION];
43 $nodeinfo['protocols'] = [];
44 $nodeinfo['protocols']['inbound'] = [];
45 $nodeinfo['protocols']['outbound'] = [];
47 if (Config::get('system', 'diaspora_enabled')) {
48 $nodeinfo['protocols']['inbound'][] = 'diaspora';
49 $nodeinfo['protocols']['outbound'][] = 'diaspora';
52 $nodeinfo['protocols']['inbound'][] = 'friendica';
53 $nodeinfo['protocols']['outbound'][] = 'friendica';
55 if (!Config::get('system', 'ostatus_disabled')) {
56 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
57 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
60 $nodeinfo['services'] = [];
61 $nodeinfo['services']['inbound'] = [];
62 $nodeinfo['services']['outbound'] = [];
64 $nodeinfo['usage'] = [];
66 $nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED;
68 $nodeinfo['metadata'] = ['nodeName' => Config::get('config', 'sitename')];
70 if (Config::get('system', 'nodeinfo')) {
72 $nodeinfo['usage']['users'] = ['total' => (int)Config::get('nodeinfo', 'total_users'),
73 'activeHalfyear' => (int)Config::get('nodeinfo', 'active_users_halfyear'),
74 'activeMonth' => (int)Config::get('nodeinfo', 'active_users_monthly')];
75 $nodeinfo['usage']['localPosts'] = (int)Config::get('nodeinfo', 'local_posts');
76 $nodeinfo['usage']['localComments'] = (int)Config::get('nodeinfo', 'local_comments');
78 if (Addon::isEnabled('blogger')) {
79 $nodeinfo['services']['outbound'][] = 'blogger';
81 if (Addon::isEnabled('dwpost')) {
82 $nodeinfo['services']['outbound'][] = 'dreamwidth';
84 if (Addon::isEnabled('statusnet')) {
85 $nodeinfo['services']['inbound'][] = 'gnusocial';
86 $nodeinfo['services']['outbound'][] = 'gnusocial';
89 if (Addon::isEnabled('gpluspost') || Addon::isEnabled('buffer')) {
90 $nodeinfo['services']['outbound'][] = 'google';
92 if (Addon::isEnabled('ijpost')) {
93 $nodeinfo['services']['outbound'][] = 'insanejournal';
95 if (Addon::isEnabled('libertree')) {
96 $nodeinfo['services']['outbound'][] = 'libertree';
98 if (Addon::isEnabled('buffer')) {
99 $nodeinfo['services']['outbound'][] = 'linkedin';
101 if (Addon::isEnabled('ljpost')) {
102 $nodeinfo['services']['outbound'][] = 'livejournal';
104 if (Addon::isEnabled('buffer')) {
105 $nodeinfo['services']['outbound'][] = 'pinterest';
107 if (Addon::isEnabled('posterous')) {
108 $nodeinfo['services']['outbound'][] = 'posterous';
110 if (Addon::isEnabled('pumpio')) {
111 $nodeinfo['services']['inbound'][] = 'pumpio';
112 $nodeinfo['services']['outbound'][] = 'pumpio';
116 $nodeinfo['services']['outbound'][] = 'smtp';
118 if (Addon::isEnabled('tumblr')) {
119 $nodeinfo['services']['outbound'][] = 'tumblr';
121 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
122 $nodeinfo['services']['outbound'][] = 'twitter';
124 if (Addon::isEnabled('wppost')) {
125 $nodeinfo['services']['outbound'][] = 'wordpress';
127 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
128 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
129 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
130 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
132 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
134 if (Addon::isEnabled('twitter')) {
135 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
138 $nodeinfo['metadata']['explicitContent'] = Config::get('system', 'explicit_content', false) == true;
141 header('Content-type: application/json; charset=utf-8');
142 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
148 function nodeinfo_cron() {
152 // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
153 if (Addon::isEnabled('statistics_json')) {
154 Config::set('system', 'nodeinfo', true);
156 $addon = 'statistics_json';
157 $addons = Config::get('system', 'addon');
161 $addons_arr = explode(',',str_replace(' ', '',$addons));
163 $idx = array_search($addon, $addons_arr);
164 if ($idx !== false) {
165 unset($addons_arr[$idx]);
166 Addon::uninstall($addon);
167 Config::set('system', 'addon', implode(', ',$addons_arr));
172 if (!Config::get('system', 'nodeinfo')) {
176 Logger::log('cron_start');
178 $users = q("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
180 INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
181 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
182 WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
183 AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
184 AND NOT `user`.`account_expired`");
185 if (is_array($users)) {
186 $total_users = count($users);
187 $active_users_halfyear = 0;
188 $active_users_monthly = 0;
190 $halfyear = time() - (180 * 24 * 60 * 60);
191 $month = time() - (30 * 24 * 60 * 60);
193 foreach ($users AS $user) {
194 if ((strtotime($user['login_date']) > $halfyear) ||
195 (strtotime($user['last-item']) > $halfyear)) {
196 ++$active_users_halfyear;
198 if ((strtotime($user['login_date']) > $month) ||
199 (strtotime($user['last-item']) > $month)) {
200 ++$active_users_monthly;
203 Config::set('nodeinfo', 'total_users', $total_users);
204 Config::set('nodeinfo', 'active_users_halfyear', $active_users_halfyear);
205 Config::set('nodeinfo', 'active_users_monthly', $active_users_monthly);
207 Logger::log('total_users: ' . $total_users . '/' . $active_users_halfyear. '/' . $active_users_monthly, Logger::DEBUG);
210 $local_posts = DBA::count('thread', ["`wall` AND NOT `deleted` AND `uid` != 0"]);
211 Config::set('nodeinfo', 'local_posts', $local_posts);
212 Logger::log('local_posts: ' . $local_posts, Logger::DEBUG);
214 $local_comments = DBA::count('item', ["`origin` AND `id` != `parent` AND NOT `deleted` AND `uid` != 0"]);
215 Config::set('nodeinfo', 'local_comments', $local_comments);
216 Logger::log('local_comments: ' . $local_comments, Logger::DEBUG);
218 // Now trying to register
219 $url = 'http://the-federation.info/register/'.$a->getHostName();
220 Logger::log('registering url: '.$url, Logger::DEBUG);
221 $ret = Network::fetchUrl($url);
222 Logger::log('registering answer: '.$ret, Logger::DEBUG);
224 Logger::log('cron_end');