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;
16 function nodeinfo_wellknown(App $a) {
17 if (!Config::get('system', 'nodeinfo')) {
18 System::httpExit(404);
21 $nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
22 'href' => System::baseUrl().'/nodeinfo/1.0']]];
24 header('Content-type: application/json; charset=utf-8');
25 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
29 function nodeinfo_init(App $a) {
30 if (!Config::get('system', 'nodeinfo')) {
31 System::httpExit(404);
34 if (($a->argc != 2) || ($a->argv[1] != '1.0')) {
35 System::httpExit(404);
38 $smtp = (function_exists('imap_open') && !Config::get('system', 'imap_disabled') && !Config::get('system', 'dfrn_only'));
41 $nodeinfo['version'] = '1.0';
42 $nodeinfo['software'] = ['name' => 'friendica', 'version' => FRIENDICA_VERSION.'-'.DB_UPDATE_VERSION];
44 $nodeinfo['protocols'] = [];
45 $nodeinfo['protocols']['inbound'] = [];
46 $nodeinfo['protocols']['outbound'] = [];
48 if (Config::get('system', 'diaspora_enabled')) {
49 $nodeinfo['protocols']['inbound'][] = 'diaspora';
50 $nodeinfo['protocols']['outbound'][] = 'diaspora';
53 $nodeinfo['protocols']['inbound'][] = 'friendica';
54 $nodeinfo['protocols']['outbound'][] = 'friendica';
56 if (!Config::get('system', 'ostatus_disabled')) {
57 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
58 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
61 $nodeinfo['services'] = [];
62 $nodeinfo['services']['inbound'] = [];
63 $nodeinfo['services']['outbound'] = [];
65 $nodeinfo['usage'] = [];
67 $nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED;
69 $nodeinfo['metadata'] = ['nodeName' => Config::get('config', 'sitename')];
71 if (Config::get('system', 'nodeinfo')) {
73 $nodeinfo['usage']['users'] = ['total' => (int)Config::get('nodeinfo', 'total_users'),
74 'activeHalfyear' => (int)Config::get('nodeinfo', 'active_users_halfyear'),
75 'activeMonth' => (int)Config::get('nodeinfo', 'active_users_monthly')];
76 $nodeinfo['usage']['localPosts'] = (int)Config::get('nodeinfo', 'local_posts');
77 $nodeinfo['usage']['localComments'] = (int)Config::get('nodeinfo', 'local_comments');
79 if (Addon::isEnabled('blogger')) {
80 $nodeinfo['services']['outbound'][] = 'blogger';
82 if (Addon::isEnabled('dwpost')) {
83 $nodeinfo['services']['outbound'][] = 'dreamwidth';
85 if (Addon::isEnabled('statusnet')) {
86 $nodeinfo['services']['inbound'][] = 'gnusocial';
87 $nodeinfo['services']['outbound'][] = 'gnusocial';
89 if (Addon::isEnabled('ijpost')) {
90 $nodeinfo['services']['outbound'][] = 'insanejournal';
92 if (Addon::isEnabled('libertree')) {
93 $nodeinfo['services']['outbound'][] = 'libertree';
95 if (Addon::isEnabled('buffer')) {
96 $nodeinfo['services']['outbound'][] = 'linkedin';
98 if (Addon::isEnabled('ljpost')) {
99 $nodeinfo['services']['outbound'][] = 'livejournal';
101 if (Addon::isEnabled('buffer')) {
102 $nodeinfo['services']['outbound'][] = 'pinterest';
104 if (Addon::isEnabled('posterous')) {
105 $nodeinfo['services']['outbound'][] = 'posterous';
107 if (Addon::isEnabled('pumpio')) {
108 $nodeinfo['services']['inbound'][] = 'pumpio';
109 $nodeinfo['services']['outbound'][] = 'pumpio';
113 $nodeinfo['services']['outbound'][] = 'smtp';
115 if (Addon::isEnabled('tumblr')) {
116 $nodeinfo['services']['outbound'][] = 'tumblr';
118 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
119 $nodeinfo['services']['outbound'][] = 'twitter';
121 if (Addon::isEnabled('wppost')) {
122 $nodeinfo['services']['outbound'][] = 'wordpress';
124 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
125 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
126 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
127 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
129 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
131 if (Addon::isEnabled('twitter')) {
132 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
135 $nodeinfo['metadata']['explicitContent'] = Config::get('system', 'explicit_content', false) == true;
138 header('Content-type: application/json; charset=utf-8');
139 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
145 function nodeinfo_cron() {
149 // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
150 if (Addon::isEnabled('statistics_json')) {
151 Config::set('system', 'nodeinfo', true);
153 $addon = 'statistics_json';
154 $addons = Config::get('system', 'addon');
157 $addons_arr = explode(',',str_replace(' ', '',$addons));
159 $idx = array_search($addon, $addons_arr);
160 if ($idx !== false) {
161 unset($addons_arr[$idx]);
162 Addon::uninstall($addon);
163 Config::set('system', 'addon', implode(', ',$addons_arr));
168 if (!Config::get('system', 'nodeinfo')) {
172 Logger::log('cron_start');
174 $users = q("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
176 INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
177 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
178 WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
179 AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
180 AND NOT `user`.`account_expired`");
181 if (is_array($users)) {
182 $total_users = count($users);
183 $active_users_halfyear = 0;
184 $active_users_monthly = 0;
186 $halfyear = time() - (180 * 24 * 60 * 60);
187 $month = time() - (30 * 24 * 60 * 60);
189 foreach ($users AS $user) {
190 if ((strtotime($user['login_date']) > $halfyear) ||
191 (strtotime($user['last-item']) > $halfyear)) {
192 ++$active_users_halfyear;
194 if ((strtotime($user['login_date']) > $month) ||
195 (strtotime($user['last-item']) > $month)) {
196 ++$active_users_monthly;
199 Config::set('nodeinfo', 'total_users', $total_users);
200 Config::set('nodeinfo', 'active_users_halfyear', $active_users_halfyear);
201 Config::set('nodeinfo', 'active_users_monthly', $active_users_monthly);
203 Logger::log('total_users: ' . $total_users . '/' . $active_users_halfyear. '/' . $active_users_monthly, Logger::DEBUG);
206 $local_posts = DBA::count('thread', ["`wall` AND NOT `deleted` AND `uid` != 0"]);
207 Config::set('nodeinfo', 'local_posts', $local_posts);
208 Logger::log('local_posts: ' . $local_posts, Logger::DEBUG);
210 $local_comments = DBA::count('item', ["`origin` AND `id` != `parent` AND NOT `deleted` AND `uid` != 0"]);
211 Config::set('nodeinfo', 'local_comments', $local_comments);
212 Logger::log('local_comments: ' . $local_comments, Logger::DEBUG);
214 // Now trying to register
215 $url = 'http://the-federation.info/register/'.$a->getHostName();
216 Logger::log('registering url: '.$url, Logger::DEBUG);
217 $ret = Network::fetchUrl($url);
218 Logger::log('registering answer: '.$ret, Logger::DEBUG);
220 Logger::log('cron_end');