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 function nodeinfo_wellknown(App $a) {
16 $nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
17 'href' => System::baseUrl().'/nodeinfo/1.0']]];
19 header('Content-type: application/json; charset=utf-8');
20 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
24 function nodeinfo_init(App $a) {
25 if (!Config::get('system', 'nodeinfo')) {
26 System::httpExit(404);
29 if (($a->argc != 2) || ($a->argv[1] != '1.0')) {
30 System::httpExit(404);
33 $smtp = (function_exists('imap_open') && !Config::get('system', 'imap_disabled') && !Config::get('system', 'dfrn_only'));
36 $nodeinfo['version'] = '1.0';
37 $nodeinfo['software'] = ['name' => 'friendica', 'version' => FRIENDICA_VERSION.'-'.DB_UPDATE_VERSION];
39 $nodeinfo['protocols'] = [];
40 $nodeinfo['protocols']['inbound'] = [];
41 $nodeinfo['protocols']['outbound'] = [];
43 if (Config::get('system', 'diaspora_enabled')) {
44 $nodeinfo['protocols']['inbound'][] = 'diaspora';
45 $nodeinfo['protocols']['outbound'][] = 'diaspora';
48 $nodeinfo['protocols']['inbound'][] = 'friendica';
49 $nodeinfo['protocols']['outbound'][] = 'friendica';
51 if (!Config::get('system', 'ostatus_disabled')) {
52 $nodeinfo['protocols']['inbound'][] = 'gnusocial';
53 $nodeinfo['protocols']['outbound'][] = 'gnusocial';
56 $nodeinfo['services'] = [];
57 $nodeinfo['services']['inbound'] = [];
58 $nodeinfo['services']['outbound'] = [];
60 $nodeinfo['usage'] = [];
62 $nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED;
64 $nodeinfo['metadata'] = ['nodeName' => Config::get('config', 'sitename')];
66 if (Config::get('system', 'nodeinfo')) {
68 $nodeinfo['usage']['users'] = ['total' => (int)Config::get('nodeinfo', 'total_users'),
69 'activeHalfyear' => (int)Config::get('nodeinfo', 'active_users_halfyear'),
70 'activeMonth' => (int)Config::get('nodeinfo', 'active_users_monthly')];
71 $nodeinfo['usage']['localPosts'] = (int)Config::get('nodeinfo', 'local_posts');
72 $nodeinfo['usage']['localComments'] = (int)Config::get('nodeinfo', 'local_comments');
74 if (Addon::isEnabled('blogger')) {
75 $nodeinfo['services']['outbound'][] = 'blogger';
77 if (Addon::isEnabled('dwpost')) {
78 $nodeinfo['services']['outbound'][] = 'dreamwidth';
80 if (Addon::isEnabled('statusnet')) {
81 $nodeinfo['services']['inbound'][] = 'gnusocial';
82 $nodeinfo['services']['outbound'][] = 'gnusocial';
84 if (Addon::isEnabled('ijpost')) {
85 $nodeinfo['services']['outbound'][] = 'insanejournal';
87 if (Addon::isEnabled('libertree')) {
88 $nodeinfo['services']['outbound'][] = 'libertree';
90 if (Addon::isEnabled('buffer')) {
91 $nodeinfo['services']['outbound'][] = 'linkedin';
93 if (Addon::isEnabled('ljpost')) {
94 $nodeinfo['services']['outbound'][] = 'livejournal';
96 if (Addon::isEnabled('buffer')) {
97 $nodeinfo['services']['outbound'][] = 'pinterest';
99 if (Addon::isEnabled('posterous')) {
100 $nodeinfo['services']['outbound'][] = 'posterous';
102 if (Addon::isEnabled('pumpio')) {
103 $nodeinfo['services']['inbound'][] = 'pumpio';
104 $nodeinfo['services']['outbound'][] = 'pumpio';
108 $nodeinfo['services']['outbound'][] = 'smtp';
110 if (Addon::isEnabled('tumblr')) {
111 $nodeinfo['services']['outbound'][] = 'tumblr';
113 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
114 $nodeinfo['services']['outbound'][] = 'twitter';
116 if (Addon::isEnabled('wppost')) {
117 $nodeinfo['services']['outbound'][] = 'wordpress';
119 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
120 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
121 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
122 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
124 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
126 if (Addon::isEnabled('twitter')) {
127 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
130 $nodeinfo['metadata']['explicitContent'] = Config::get('system', 'explicit_content', false) == true;
133 header('Content-type: application/json; charset=utf-8');
134 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
140 function nodeinfo_cron() {
144 // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
145 if (Addon::isEnabled('statistics_json')) {
146 Config::set('system', 'nodeinfo', true);
148 $addon = 'statistics_json';
149 $addons = Config::get('system', 'addon');
152 $addons_arr = explode(',',str_replace(' ', '',$addons));
154 $idx = array_search($addon, $addons_arr);
155 if ($idx !== false) {
156 unset($addons_arr[$idx]);
157 Addon::uninstall($addon);
158 Config::set('system', 'addon', implode(', ',$addons_arr));
163 if (!Config::get('system', 'nodeinfo')) {
167 Logger::log('cron_start');
169 $users = q("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
171 INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
172 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
173 WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
174 AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
175 AND NOT `user`.`account_expired`");
176 if (is_array($users)) {
177 $total_users = count($users);
178 $active_users_halfyear = 0;
179 $active_users_monthly = 0;
181 $halfyear = time() - (180 * 24 * 60 * 60);
182 $month = time() - (30 * 24 * 60 * 60);
184 foreach ($users AS $user) {
185 if ((strtotime($user['login_date']) > $halfyear) ||
186 (strtotime($user['last-item']) > $halfyear)) {
187 ++$active_users_halfyear;
189 if ((strtotime($user['login_date']) > $month) ||
190 (strtotime($user['last-item']) > $month)) {
191 ++$active_users_monthly;
194 Config::set('nodeinfo', 'total_users', $total_users);
195 Config::set('nodeinfo', 'active_users_halfyear', $active_users_halfyear);
196 Config::set('nodeinfo', 'active_users_monthly', $active_users_monthly);
198 Logger::log('total_users: ' . $total_users . '/' . $active_users_halfyear. '/' . $active_users_monthly, Logger::DEBUG);
201 $local_posts = DBA::count('thread', ["`wall` AND NOT `deleted` AND `uid` != 0"]);
202 Config::set('nodeinfo', 'local_posts', $local_posts);
203 Logger::log('local_posts: ' . $local_posts, Logger::DEBUG);
205 $local_comments = DBA::count('item', ["`origin` AND `id` != `parent` AND NOT `deleted` AND `uid` != 0"]);
206 Config::set('nodeinfo', 'local_comments', $local_comments);
207 Logger::log('local_comments: ' . $local_comments, Logger::DEBUG);
209 // Now trying to register
210 $url = 'http://the-federation.info/register/'.$a->getHostName();
211 Logger::log('registering url: '.$url, Logger::DEBUG);
212 $ret = Network::fetchUrl($url);
213 Logger::log('registering answer: '.$ret, Logger::DEBUG);
215 Logger::log('cron_end');