3 * @file mod/nodeinfo.php
5 * Documentation: http://nodeinfo.diaspora.software/schema.html
8 require_once("include/plugin.php");
10 function nodeinfo_wellknown(App &$a) {
11 if (!get_config("system", "nodeinfo")) {
12 http_status_exit(404);
15 $nodeinfo = array("links" => array(array("rel" => "http://nodeinfo.diaspora.software/ns/schema/1.0",
16 "href" => App::get_baseurl()."/nodeinfo/1.0")));
18 header('Content-type: application/json; charset=utf-8');
19 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
23 function nodeinfo_init(App &$a){
24 if (!get_config("system", "nodeinfo")) {
25 http_status_exit(404);
29 if (($a->argc != 2) OR ($a->argv[1] != "1.0")) {
30 http_status_exit(404);
34 $smtp = (function_exists("imap_open") AND !get_config("system","imap_disabled") AND !get_config("system","dfrn_only"));
37 $nodeinfo["version"] = "1.0";
38 $nodeinfo["software"] = array("name" => "friendica", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
40 $nodeinfo["protocols"] = array();
41 $nodeinfo["protocols"]["inbound"] = array();
42 $nodeinfo["protocols"]["outbound"] = array();
44 if (get_config("system","diaspora_enabled")) {
45 $nodeinfo["protocols"]["inbound"][] = "diaspora";
46 $nodeinfo["protocols"]["outbound"][] = "diaspora";
49 $nodeinfo["protocols"]["inbound"][] = "friendica";
50 $nodeinfo["protocols"]["outbound"][] = "friendica";
52 if (!get_config("system","ostatus_disabled")) {
53 $nodeinfo["protocols"]["inbound"][] = "gnusocial";
54 $nodeinfo["protocols"]["outbound"][] = "gnusocial";
57 $nodeinfo["services"] = array();
58 $nodeinfo["services"]["inbound"] = array();
59 $nodeinfo["services"]["outbound"] = array();
61 $nodeinfo["openRegistrations"] = ($a->config['register_policy'] != 0);
63 $nodeinfo["usage"] = array();
64 $nodeinfo["usage"]["users"] = array("total" => (int)get_config("nodeinfo","total_users"),
65 "activeHalfyear" => (int)get_config("nodeinfo","active_users_halfyear"),
66 "activeMonth" => (int)get_config("nodeinfo","active_users_monthly"));
67 $nodeinfo["usage"]["localPosts"] = (int)get_config("nodeinfo","local_posts");
68 $nodeinfo["usage"]["localComments"] = (int)get_config("nodeinfo","local_comments");
70 $nodeinfo["metadata"] = array("nodeName" => $a->config["sitename"]);
72 if (plugin_enabled("appnet"))
73 $nodeinfo["services"]["inbound"][] = "appnet";
75 if (plugin_enabled("appnet") OR plugin_enabled("buffer"))
76 $nodeinfo["services"]["outbound"][] = "appnet";
78 if (plugin_enabled("blogger"))
79 $nodeinfo["services"]["outbound"][] = "blogger";
81 if (plugin_enabled("dwpost"))
82 $nodeinfo["services"]["outbound"][] = "dreamwidth";
84 if (plugin_enabled("fbpost") OR plugin_enabled("buffer"))
85 $nodeinfo["services"]["outbound"][] = "facebook";
87 if (plugin_enabled("statusnet")) {
88 $nodeinfo["services"]["inbound"][] = "gnusocial";
89 $nodeinfo["services"]["outbound"][] = "gnusocial";
92 if (plugin_enabled("gpluspost") OR plugin_enabled("buffer"))
93 $nodeinfo["services"]["outbound"][] = "google";
95 if (plugin_enabled("ijpost"))
96 $nodeinfo["services"]["outbound"][] = "insanejournal";
98 if (plugin_enabled("libertree"))
99 $nodeinfo["services"]["outbound"][] = "libertree";
101 if (plugin_enabled("buffer"))
102 $nodeinfo["services"]["outbound"][] = "linkedin";
104 if (plugin_enabled("ljpost"))
105 $nodeinfo["services"]["outbound"][] = "livejournal";
107 if (plugin_enabled("buffer"))
108 $nodeinfo["services"]["outbound"][] = "pinterest";
110 if (plugin_enabled("posterous"))
111 $nodeinfo["services"]["outbound"][] = "posterous";
113 if (plugin_enabled("pumpio")) {
114 $nodeinfo["services"]["inbound"][] = "pumpio";
115 $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";
142 header('Content-type: application/json; charset=utf-8');
143 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
149 function nodeinfo_cron() {
153 // If the plugin "statistics_json" is enabled then disable it and actrivate nodeinfo.
154 if (plugin_enabled("statistics_json")) {
155 set_config("system", "nodeinfo", true);
157 $plugin = "statistics_json";
158 $plugins = get_config("system","addon");
159 $plugins_arr = array();
162 $plugins_arr = explode(",",str_replace(" ", "",$plugins));
164 $idx = array_search($plugin, $plugins_arr);
166 unset($plugins_arr[$idx]);
167 uninstall_plugin($plugin);
168 set_config("system","addon", implode(", ",$plugins_arr));
173 if (!get_config("system", "nodeinfo"))
176 $last = get_config('nodeinfo','last_calucation');
179 // Calculate every 24 hours
180 $next = $last + (24 * 60 * 60);
182 logger("calculation intervall not reached");
186 logger("cron_start");
188 $users = qu("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
190 INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
191 INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
192 WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
193 AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
194 AND NOT `user`.`account_expired`");
195 if (is_array($users)) {
196 $total_users = count($users);
197 $active_users_halfyear = 0;
198 $active_users_monthly = 0;
200 $halfyear = time() - (180 * 24 * 60 * 60);
201 $month = time() - (30 * 24 * 60 * 60);
203 foreach ($users AS $user) {
204 if ((strtotime($user['login_date']) > $halfyear) OR
205 (strtotime($user['last-item']) > $halfyear))
206 ++$active_users_halfyear;
208 if ((strtotime($user['login_date']) > $month) OR
209 (strtotime($user['last-item']) > $month))
210 ++$active_users_monthly;
213 set_config('nodeinfo','total_users', $total_users);
214 logger("total_users: ".$total_users, LOGGER_DEBUG);
216 set_config('nodeinfo','active_users_halfyear', $active_users_halfyear);
217 set_config('nodeinfo','active_users_monthly', $active_users_monthly);
220 $posts = qu("SELECT COUNT(*) AS local_posts FROM `thread` WHERE `thread`.`wall` AND `thread`.`uid` != 0");
222 if (!is_array($posts))
225 $local_posts = $posts[0]["local_posts"];
227 set_config('nodeinfo','local_posts', $local_posts);
229 logger("local_posts: ".$local_posts, LOGGER_DEBUG);
231 $posts = qu("SELECT COUNT(*) AS `local_comments` FROM `item`
232 INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
233 WHERE `contact`.`self` and `item`.`id` != `item`.`parent` AND `item`.`network` IN ('%s', '%s', '%s')",
234 dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
236 if (!is_array($posts))
237 $local_comments = -1;
239 $local_comments = $posts[0]["local_comments"];
241 set_config('nodeinfo','local_comments', $local_comments);
243 // Now trying to register
244 $url = "http://the-federation.info/register/".$a->get_hostname();
245 logger('registering url: '.$url, LOGGER_DEBUG);
246 $ret = fetch_url($url);
247 logger('registering answer: '.$ret, LOGGER_DEBUG);
250 set_config('nodeinfo','last_calucation', time());