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('blogger')) {
78 $nodeinfo['services']['outbound'][] = 'blogger';
80 if (Addon::isEnabled('dwpost')) {
81 $nodeinfo['services']['outbound'][] = 'dreamwidth';
83 if (Addon::isEnabled('statusnet')) {
84 $nodeinfo['services']['inbound'][] = 'gnusocial';
85 $nodeinfo['services']['outbound'][] = 'gnusocial';
88 if (Addon::isEnabled('gpluspost') || Addon::isEnabled('buffer')) {
89 $nodeinfo['services']['outbound'][] = 'google';
91 if (Addon::isEnabled('ijpost')) {
92 $nodeinfo['services']['outbound'][] = 'insanejournal';
94 if (Addon::isEnabled('libertree')) {
95 $nodeinfo['services']['outbound'][] = 'libertree';
97 if (Addon::isEnabled('buffer')) {
98 $nodeinfo['services']['outbound'][] = 'linkedin';
100 if (Addon::isEnabled('ljpost')) {
101 $nodeinfo['services']['outbound'][] = 'livejournal';
103 if (Addon::isEnabled('buffer')) {
104 $nodeinfo['services']['outbound'][] = 'pinterest';
106 if (Addon::isEnabled('posterous')) {
107 $nodeinfo['services']['outbound'][] = 'posterous';
109 if (Addon::isEnabled('pumpio')) {
110 $nodeinfo['services']['inbound'][] = 'pumpio';
111 $nodeinfo['services']['outbound'][] = 'pumpio';
115 $nodeinfo['services']['outbound'][] = 'smtp';
117 if (Addon::isEnabled('tumblr')) {
118 $nodeinfo['services']['outbound'][] = 'tumblr';
120 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
121 $nodeinfo['services']['outbound'][] = 'twitter';
123 if (Addon::isEnabled('wppost')) {
124 $nodeinfo['services']['outbound'][] = 'wordpress';
126 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
127 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
128 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
129 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
131 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
133 if (Addon::isEnabled('twitter')) {
134 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
137 $nodeinfo['metadata']['explicitContent'] = Config::get('system', 'explicit_content', false) == true;
140 header('Content-type: application/json; charset=utf-8');
141 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
147 function nodeinfo_cron() {
151 // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
152 if (Addon::isEnabled('statistics_json')) {
153 Config::set('system', 'nodeinfo', true);
155 $addon = 'statistics_json';
156 $addons = Config::get('system', 'addon');
160 $addons_arr = explode(',',str_replace(' ', '',$addons));
162 $idx = array_search($addon, $addons_arr);
163 if ($idx !== false) {
164 unset($addons_arr[$idx]);
165 Addon::uninstall($addon);
166 Config::set('system', 'addon', implode(', ',$addons_arr));
171 if (!Config::get('system', 'nodeinfo')) {
175 logger('cron_start');
177 $users = q("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
179 INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
180 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
181 WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
182 AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
183 AND NOT `user`.`account_expired`");
184 if (is_array($users)) {
185 $total_users = count($users);
186 $active_users_halfyear = 0;
187 $active_users_monthly = 0;
189 $halfyear = time() - (180 * 24 * 60 * 60);
190 $month = time() - (30 * 24 * 60 * 60);
192 foreach ($users AS $user) {
193 if ((strtotime($user['login_date']) > $halfyear) ||
194 (strtotime($user['last-item']) > $halfyear)) {
195 ++$active_users_halfyear;
197 if ((strtotime($user['login_date']) > $month) ||
198 (strtotime($user['last-item']) > $month)) {
199 ++$active_users_monthly;
202 Config::set('nodeinfo', 'total_users', $total_users);
203 Config::set('nodeinfo', 'active_users_halfyear', $active_users_halfyear);
204 Config::set('nodeinfo', 'active_users_monthly', $active_users_monthly);
206 logger('total_users: ' . $total_users . '/' . $active_users_halfyear. '/' . $active_users_monthly, LOGGER_DEBUG);
209 $local_posts = DBA::count('thread', ["`wall` AND NOT `deleted` AND `uid` != 0"]);
210 Config::set('nodeinfo', 'local_posts', $local_posts);
211 logger('local_posts: ' . $local_posts, LOGGER_DEBUG);
213 $local_comments = DBA::count('item', ["`origin` AND `id` != `parent` AND NOT `deleted` AND `uid` != 0"]);
214 Config::set('nodeinfo', 'local_comments', $local_comments);
215 logger('local_comments: ' . $local_comments, LOGGER_DEBUG);
217 // Now trying to register
218 $url = 'http://the-federation.info/register/'.$a->getHostName();
219 logger('registering url: '.$url, LOGGER_DEBUG);
220 $ret = Network::fetchUrl($url);
221 logger('registering answer: '.$ret, LOGGER_DEBUG);