3 Documentation: http://nodeinfo.diaspora.software/schema.html
6 require_once("include/plugin.php");
8 function nodeinfo_wellknown(&$a) {
9 if (!get_config("system", "nodeinfo")) {
10 http_status_exit(404);
13 $nodeinfo = array("links" => array("rel" => "http://nodeinfo.diaspora.software/ns/schema/1.0",
14 "href" => $a->get_baseurl()."/nodeinfo/1.0"));
16 header('Content-type: application/json; charset=utf-8');
17 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
21 function nodeinfo_init(&$a){
22 if (!get_config("system", "nodeinfo")) {
23 http_status_exit(404);
27 if (($a->argc != 2) OR ($a->argv[1] != "1.0")) {
28 http_status_exit(404);
32 $smtp = (function_exists("imap_open") AND !get_config("system","imap_disabled") AND !get_config("system","dfrn_only"));
35 $nodeinfo["version"] = "1.0";
36 $nodeinfo["software"] = array("name" => "friendica", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
38 $nodeinfo["protocols"] = array();
39 $nodeinfo["protocols"]["inbound"] = array();
40 $nodeinfo["protocols"]["outbound"] = array();
42 if (get_config("system","diaspora_enabled")) {
43 $nodeinfo["protocols"]["inbound"][] = "diaspora";
44 $nodeinfo["protocols"]["outbound"][] = "diaspora";
47 $nodeinfo["protocols"]["inbound"][] = "friendica";
48 $nodeinfo["protocols"]["outbound"][] = "friendica";
50 if (!get_config("system","ostatus_disabled")) {
51 $nodeinfo["protocols"]["inbound"][] = "gnusocial";
52 $nodeinfo["protocols"]["outbound"][] = "gnusocial";
55 $nodeinfo["services"] = array();
56 $nodeinfo["services"]["inbound"] = array();
57 $nodeinfo["services"]["outbound"] = array();
59 $nodeinfo["openRegistrations"] = ($a->config['register_policy'] != 0);
61 $nodeinfo["usage"] = array();
62 $nodeinfo["usage"]["users"] = array("total" => (int)get_config("nodeinfo","total_users"),
63 "activeHalfyear" => (int)get_config("nodeinfo","active_users_halfyear"),
64 "activeMonth" => (int)get_config("nodeinfo","active_users_monthly"));
65 $nodeinfo["usage"]["localPosts"] = (int)get_config("nodeinfo","local_posts");
66 $nodeinfo["usage"]["localComments"] = (int)get_config("nodeinfo","local_comments");
68 $nodeinfo["metadata"] = array("nodeName" => $a->config["sitename"]);
70 if (nodeinfo_plugin_enabled("appnet") OR nodeinfo_plugin_enabled("buffer")) {
71 $nodeinfo["services"]["inbound"][] = "appnet";
72 $nodeinfo["services"]["outbound"][] = "appnet";
75 if (nodeinfo_plugin_enabled("blogger"))
76 $nodeinfo["services"]["outbound"][] = "blogger";
78 if (nodeinfo_plugin_enabled("dwpost"))
79 $nodeinfo["services"]["outbound"][] = "dreamwidth";
81 if (nodeinfo_plugin_enabled("fbpost") OR nodeinfo_plugin_enabled("buffer"))
82 $nodeinfo["services"]["outbound"][] = "facebook";
84 if (nodeinfo_plugin_enabled("statusnet")) {
85 $nodeinfo["services"]["inbound"][] = "gnusocial";
86 $nodeinfo["services"]["outbound"][] = "gnusocial";
89 if (nodeinfo_plugin_enabled("gpluspost") OR nodeinfo_plugin_enabled("buffer"))
90 $nodeinfo["services"]["outbound"][] = "google";
92 if (nodeinfo_plugin_enabled("ijpost"))
93 $nodeinfo["services"]["outbound"][] = "insanejournal";
95 if (nodeinfo_plugin_enabled("libertree"))
96 $nodeinfo["services"]["outbound"][] = "libertree";
98 if (nodeinfo_plugin_enabled("buffer"))
99 $nodeinfo["services"]["outbound"][] = "linkedin";
101 if (nodeinfo_plugin_enabled("ljpost"))
102 $nodeinfo["services"]["outbound"][] = "livejournal";
104 if (nodeinfo_plugin_enabled("buffer"))
105 $nodeinfo["services"]["outbound"][] = "pinterest";
107 if (nodeinfo_plugin_enabled("posterous"))
108 $nodeinfo["services"]["outbound"][] = "posterous";
110 if (nodeinfo_plugin_enabled("pumpio")) {
111 $nodeinfo["services"]["inbound"][] = "pumpio";
112 $nodeinfo["services"]["outbound"][] = "pumpio";
118 $nodeinfo["services"]["outbound"][] = "smtp";
120 if (nodeinfo_plugin_enabled("tumblr"))
121 $nodeinfo["services"]["outbound"][] = "tumblr";
123 if (nodeinfo_plugin_enabled("twitter"))
124 $nodeinfo["services"]["outbound"][] = "twitter";
126 if (nodeinfo_plugin_enabled("wppost"))
127 $nodeinfo["services"]["outbound"][] = "wordpress";
129 $nodeinfo["metadata"]["services"] = $nodeinfo["services"];
130 $nodeinfo["metadata"]["services"]["inbound"][] = "feed";
132 if (nodeinfo_plugin_enabled("twitter"))
133 $nodeinfo["metadata"]["services"]["inbound"][] = "twitter";
135 header('Content-type: application/json; charset=utf-8');
136 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
140 function nodeinfo_plugin_enabled($plugin) {
141 $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = '%s'", $plugin);
142 return((bool)(count($r) > 0));
145 function nodeinfo_cron() {
149 // If the plugin "statistics_json" is enabled then disable it and actrivate nodeinfo.
150 if (nodeinfo_plugin_enabled("statistics_json")) {
151 set_config("system", "nodeinfo", true);
153 $plugin = "statistics_json";
154 $plugins = get_config("system","addon");
155 $plugins_arr = array();
158 $plugins_arr = explode(",",str_replace(" ", "",$plugins));
160 $idx = array_search($plugin, $plugins_arr);
162 unset($plugins_arr[$idx]);
163 uninstall_plugin($plugin);
164 set_config("system","addon", implode(", ",$plugins_arr));
169 if (!get_config("system", "nodeinfo"))
172 $last = get_config('nodeinfo','last_calucation');
175 // Calculate every 24 hours
176 $next = $last + (24 * 60 * 60);
178 logger("calculation intervall not reached");
182 logger("cron_start");
184 $users = q("SELECT profile.*, `user`.`login_date`, `lastitem`.`lastitem_date`
185 FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
187 WHERE `item`.`type` = 'wall'
188 GROUP BY `item`.`uid`) AS `lastitem`
189 RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact`, `profile`
191 `user`.`uid` = `contact`.`uid` AND `profile`.`uid` = `user`.`uid`
192 AND `profile`.`is-default` AND (`profile`.`publish` OR `profile`.`net-publish`)
193 AND `user`.`verified` AND `contact`.`self`
194 AND NOT `user`.`blocked`
195 AND NOT `user`.`account_removed`
196 AND NOT `user`.`account_expired`");
198 if (is_array($users)) {
199 $total_users = count($users);
200 $active_users_halfyear = 0;
201 $active_users_monthly = 0;
203 $halfyear = time() - (180 * 24 * 60 * 60);
204 $month = time() - (30 * 24 * 60 * 60);
206 foreach ($users AS $user) {
207 if ((strtotime($user['login_date']) > $halfyear) OR
208 (strtotime($user['lastitem_date']) > $halfyear))
209 ++$active_users_halfyear;
211 if ((strtotime($user['login_date']) > $month) OR
212 (strtotime($user['lastitem_date']) > $month))
213 ++$active_users_monthly;
216 set_config('nodeinfo','total_users', $total_users);
217 logger("total_users: ".$total_users, LOGGER_DEBUG);
219 set_config('nodeinfo','active_users_halfyear', $active_users_halfyear);
220 set_config('nodeinfo','active_users_monthly', $active_users_monthly);
223 //$posts = q("SELECT COUNT(*) AS local_posts FROM `item` WHERE `wall` AND `uid` != 0 AND `id` = `parent` AND left(body, 6) != '[share'");
224 $posts = q("SELECT COUNT(*) AS `local_posts` FROM `item`
225 INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
226 WHERE `contact`.`self` and `item`.`id` = `item`.`parent` AND left(body, 6) != '[share' AND `item`.`network` IN ('%s', '%s', '%s')",
227 dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
229 if (!is_array($posts))
232 $local_posts = $posts[0]["local_posts"];
234 set_config('nodeinfo','local_posts', $local_posts);
236 logger("local_posts: ".$local_posts, LOGGER_DEBUG);
238 $posts = q("SELECT COUNT(*) AS `local_comments` FROM `item`
239 INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
240 WHERE `contact`.`self` and `item`.`id` != `item`.`parent` AND `item`.`network` IN ('%s', '%s', '%s')",
241 dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
243 if (!is_array($posts))
244 $local_comments = -1;
246 $local_comments = $posts[0]["local_comments"];
248 set_config('nodeinfo','local_comments', $local_comments);
250 // Now trying to register
251 $url = "http://the-federation.info/register/".$a->get_hostname();
252 logger('registering url: '.$url, LOGGER_DEBUG);
253 $ret = fetch_url($url);
254 logger('registering answer: '.$ret, LOGGER_DEBUG);
257 set_config('nodeinfo','last_calucation', time());