3 * @file mod/nodeinfo.php
5 * Documentation: http://nodeinfo.diaspora.software/schema.html
9 use Friendica\Core\Config;
11 require_once 'include/plugin.php';
13 function nodeinfo_wellknown(App $a) {
14 $nodeinfo = array('links' => array(array('rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
15 'href' => App::get_baseurl().'/nodeinfo/1.0')));
17 header('Content-type: application/json; charset=utf-8');
18 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
22 function nodeinfo_init(App $a) {
23 if (!Config::get('system', 'nodeinfo')) {
24 http_status_exit(404);
28 if (($a->argc != 2) OR ($a->argv[1] != '1.0')) {
29 http_status_exit(404);
33 $smtp = (function_exists('imap_open') AND !Config::get('system', 'imap_disabled') AND !Config::get('system', 'dfrn_only'));
36 $nodeinfo['version'] = '1.0';
37 $nodeinfo['software'] = array('name' => 'friendica', 'version' => FRIENDICA_VERSION.'-'.DB_UPDATE_VERSION);
39 $nodeinfo['protocols'] = array();
40 $nodeinfo['protocols']['inbound'] = array();
41 $nodeinfo['protocols']['outbound'] = array();
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'] = array();
57 $nodeinfo['services']['inbound'] = array();
58 $nodeinfo['services']['outbound'] = array();
60 $nodeinfo['usage'] = array();
62 $nodeinfo['openRegistrations'] = ($a->config['register_policy'] != 0);
64 $nodeinfo['metadata'] = array('nodeName' => $a->config['sitename']);
66 if (Config::get('system', 'nodeinfo')) {
68 $nodeinfo['usage']['users'] = array('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 (plugin_enabled('appnet')) {
75 $nodeinfo['services']['inbound'][] = 'appnet';
77 if (plugin_enabled('appnet') OR plugin_enabled('buffer')) {
78 $nodeinfo['services']['outbound'][] = 'appnet';
80 if (plugin_enabled('blogger')) {
81 $nodeinfo['services']['outbound'][] = 'blogger';
83 if (plugin_enabled('dwpost')) {
84 $nodeinfo['services']['outbound'][] = 'dreamwidth';
86 if (plugin_enabled('fbpost') OR plugin_enabled('buffer')) {
87 $nodeinfo['services']['outbound'][] = 'facebook';
89 if (plugin_enabled('statusnet')) {
90 $nodeinfo['services']['inbound'][] = 'gnusocial';
91 $nodeinfo['services']['outbound'][] = 'gnusocial';
94 if (plugin_enabled('gpluspost') OR plugin_enabled('buffer')) {
95 $nodeinfo['services']['outbound'][] = 'google';
97 if (plugin_enabled('ijpost')) {
98 $nodeinfo['services']['outbound'][] = 'insanejournal';
100 if (plugin_enabled('libertree')) {
101 $nodeinfo['services']['outbound'][] = 'libertree';
103 if (plugin_enabled('buffer')) {
104 $nodeinfo['services']['outbound'][] = 'linkedin';
106 if (plugin_enabled('ljpost')) {
107 $nodeinfo['services']['outbound'][] = 'livejournal';
109 if (plugin_enabled('buffer')) {
110 $nodeinfo['services']['outbound'][] = 'pinterest';
112 if (plugin_enabled('posterous')) {
113 $nodeinfo['services']['outbound'][] = 'posterous';
115 if (plugin_enabled('pumpio')) {
116 $nodeinfo['services']['inbound'][] = 'pumpio';
117 $nodeinfo['services']['outbound'][] = 'pumpio';
121 $nodeinfo['services']['outbound'][] = 'smtp';
123 if (plugin_enabled('tumblr')) {
124 $nodeinfo['services']['outbound'][] = 'tumblr';
126 if (plugin_enabled('twitter') OR plugin_enabled('buffer')) {
127 $nodeinfo['services']['outbound'][] = 'twitter';
129 if (plugin_enabled('wppost')) {
130 $nodeinfo['services']['outbound'][] = 'wordpress';
132 $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
133 $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
134 $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
135 $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
137 $nodeinfo['metadata']['services'] = $nodeinfo['services'];
139 if (plugin_enabled('twitter')) {
140 $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
144 header('Content-type: application/json; charset=utf-8');
145 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
151 function nodeinfo_cron() {
155 // If the plugin 'statistics_json' is enabled then disable it and actrivate nodeinfo.
156 if (plugin_enabled('statistics_json')) {
157 Config::set('system', 'nodeinfo', true);
159 $plugin = 'statistics_json';
160 $plugins = Config::get('system', 'addon');
161 $plugins_arr = array();
164 $plugins_arr = explode(',',str_replace(' ', '',$plugins));
166 $idx = array_search($plugin, $plugins_arr);
167 if ($idx !== false) {
168 unset($plugins_arr[$idx]);
169 uninstall_plugin($plugin);
170 Config::set('system', 'addon', implode(', ',$plugins_arr));
175 if (!Config::get('system', 'nodeinfo')) {
178 $last = Config::get('nodeinfo', 'last_calucation');
181 // Calculate every 24 hours
182 $next = $last + (24 * 60 * 60);
183 if ($next > time()) {
184 logger('calculation intervall not reached');
188 logger('cron_start');
190 $users = qu("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
192 INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
193 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
194 WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
195 AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
196 AND NOT `user`.`account_expired`");
197 if (is_array($users)) {
198 $total_users = count($users);
199 $active_users_halfyear = 0;
200 $active_users_monthly = 0;
202 $halfyear = time() - (180 * 24 * 60 * 60);
203 $month = time() - (30 * 24 * 60 * 60);
205 foreach ($users AS $user) {
206 if ((strtotime($user['login_date']) > $halfyear) OR
207 (strtotime($user['last-item']) > $halfyear)) {
208 ++$active_users_halfyear;
210 if ((strtotime($user['login_date']) > $month) OR
211 (strtotime($user['last-item']) > $month)) {
212 ++$active_users_monthly;
215 Config::set('nodeinfo', 'total_users', $total_users);
216 logger('total_users: '.$total_users, LOGGER_DEBUG);
218 Config::set('nodeinfo', 'active_users_halfyear', $active_users_halfyear);
219 Config::set('nodeinfo', 'active_users_monthly', $active_users_monthly);
222 $posts = qu("SELECT COUNT(*) AS local_posts FROM `thread` WHERE `thread`.`wall` AND `thread`.`uid` != 0");
224 if (!is_array($posts)) {
227 $local_posts = $posts[0]['local_posts'];
229 Config::set('nodeinfo', 'local_posts', $local_posts);
231 logger('local_posts: '.$local_posts, LOGGER_DEBUG);
233 $posts = qu("SELECT COUNT(*) FROM `contact`
234 INNER JOIN `item` ON `item`.`contact-id` = `contact`.`id` AND `item`.`uid` = `contact`.`uid` AND
235 `item`.`id` != `item`.`parent` AND `item`.`network` IN ('%s', '%s', '%s')
236 WHERE `contact`.`self`",
237 dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
239 if (!is_array($posts)) {
240 $local_comments = -1;
242 $local_comments = $posts[0]['local_comments'];
244 Config::set('nodeinfo', 'local_comments', $local_comments);
246 // Now trying to register
247 $url = 'http://the-federation.info/register/'.$a->get_hostname();
248 logger('registering url: '.$url, LOGGER_DEBUG);
249 $ret = fetch_url($url);
250 logger('registering answer: '.$ret, LOGGER_DEBUG);
253 Config::set('nodeinfo', 'last_calucation', time());