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";
56 // $nodeinfo["protocols"]["inbound"][] = "smtp";
57 // $nodeinfo["protocols"]["outbound"][] = "smtp";
61 $nodeinfo["services"] = array();
63 if (nodeinfo_plugin_enabled("appnet") OR nodeinfo_plugin_enabled("buffer"))
64 $nodeinfo["services"][] = "appnet";
66 if (nodeinfo_plugin_enabled("blogger"))
67 $nodeinfo["services"][] = "blogger";
69 //if (get_config("system","diaspora_enabled"))
70 // $nodeinfo["services"][] = "diaspora";
72 if (nodeinfo_plugin_enabled("dwpost"))
73 $nodeinfo["services"][] = "dreamwidth";
75 if (nodeinfo_plugin_enabled("fbpost") OR nodeinfo_plugin_enabled("buffer"))
76 $nodeinfo["services"][] = "facebook";
78 //$nodeinfo["services"][] = "friendica";
80 //if (nodeinfo_plugin_enabled("statusnet") OR !get_config("system","ostatus_disabled"))
81 if (nodeinfo_plugin_enabled("statusnet"))
82 $nodeinfo["services"][] = "gnusocial";
84 if (nodeinfo_plugin_enabled("gpluspost") OR nodeinfo_plugin_enabled("buffer"))
85 $nodeinfo["services"][] = "google";
87 if (nodeinfo_plugin_enabled("ijpost"))
88 $nodeinfo["services"][] = "insanejournal";
90 if (nodeinfo_plugin_enabled("libertree"))
91 $nodeinfo["services"][] = "libertree";
93 if (nodeinfo_plugin_enabled("buffer"))
94 $nodeinfo["services"][] = "linkedin";
96 if (nodeinfo_plugin_enabled("ljpost"))
97 $nodeinfo["services"][] = "livejournal";
99 if (nodeinfo_plugin_enabled("buffer"))
100 $nodeinfo["services"][] = "pinterest";
102 if (nodeinfo_plugin_enabled("posterous"))
103 $nodeinfo["services"][] = "posterous";
105 if (nodeinfo_plugin_enabled("pumpio"))
106 $nodeinfo["services"][] = "pumpio";
111 $nodeinfo["services"][] = "smtp";
113 if (nodeinfo_plugin_enabled("tumblr"))
114 $nodeinfo["services"][] = "tumblr";
116 if (nodeinfo_plugin_enabled("twitter"))
117 $nodeinfo["services"][] = "twitter";
119 if (nodeinfo_plugin_enabled("wppost"))
120 $nodeinfo["services"][] = "wordpress";
122 $nodeinfo["openRegistrations"] = ($a->config['register_policy'] != 0);
124 $nodeinfo["usage"] = array();
125 $nodeinfo["usage"]["users"] = array("total" => (int)get_config("nodeinfo","total_users"),
126 "activeHalfyear" => (int)get_config("nodeinfo","active_users_halfyear"),
127 "activeMonth" => (int)get_config("nodeinfo","active_users_monthly"));
128 $nodeinfo["usage"]["localPosts"] = (int)get_config("nodeinfo","local_posts");
129 $nodeinfo["usage"]["localComments"] = (int)get_config("nodeinfo","local_comments");
131 //$nodeinfo["metadata"] = new stdClass();
132 $nodeinfo["metadata"] = array("nodeName" => $a->config["sitename"]);
134 header('Content-type: application/json; charset=utf-8');
135 echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
139 function nodeinfo_plugin_enabled($plugin) {
140 $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = '%s'", $plugin);
141 return((bool)(count($r) > 0));
144 function nodeinfo_cron() {
148 // If the plugin "statistics_json" is enabled then disable it and actrivate nodeinfo.
149 if (nodeinfo_plugin_enabled("statistics_json")) {
150 set_config("system", "nodeinfo", true);
152 $plugin = "statistics_json";
153 $plugins = get_config("system","addon");
154 $plugins_arr = array();
157 $plugins_arr = explode(",",str_replace(" ", "",$plugins));
159 $idx = array_search($plugin, $plugins_arr);
161 unset($plugins_arr[$idx]);
162 uninstall_plugin($plugin);
163 set_config("system","addon", implode(", ",$plugins_arr));
168 if (!get_config("system", "nodeinfo"))
171 $last = get_config('nodeinfo','last_calucation');
174 // Calculate every 24 hours
175 $next = $last + (24 * 60 * 60);
177 logger("calculation intervall not reached");
181 logger("cron_start");
183 $users = q("SELECT profile.*, `user`.`login_date`, `lastitem`.`lastitem_date`
184 FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
186 WHERE `item`.`type` = 'wall'
187 GROUP BY `item`.`uid`) AS `lastitem`
188 RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact`, `profile`
190 `user`.`uid` = `contact`.`uid` AND `profile`.`uid` = `user`.`uid`
191 AND `profile`.`is-default` AND (`profile`.`publish` OR `profile`.`net-publish`)
192 AND `user`.`verified` AND `contact`.`self`
193 AND NOT `user`.`blocked`
194 AND NOT `user`.`account_removed`
195 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['lastitem_date']) > $halfyear))
208 ++$active_users_halfyear;
210 if ((strtotime($user['login_date']) > $month) OR
211 (strtotime($user['lastitem_date']) > $month))
212 ++$active_users_monthly;
215 set_config('nodeinfo','total_users', $total_users);
216 logger("total_users: ".$total_users, LOGGER_DEBUG);
218 set_config('nodeinfo','active_users_halfyear', $active_users_halfyear);
219 set_config('nodeinfo','active_users_monthly', $active_users_monthly);
222 //$posts = q("SELECT COUNT(*) AS local_posts FROM `item` WHERE `wall` AND `uid` != 0 AND `id` = `parent` AND left(body, 6) != '[share'");
223 $posts = q("SELECT COUNT(*) AS `local_posts` FROM `item`
224 INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
225 WHERE `contact`.`self` and `item`.`id` = `item`.`parent` AND left(body, 6) != '[share' AND `item`.`network` IN ('%s', '%s', '%s')",
226 dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
228 if (!is_array($posts))
231 $local_posts = $posts[0]["local_posts"];
233 set_config('nodeinfo','local_posts', $local_posts);
235 logger("local_posts: ".$local_posts, LOGGER_DEBUG);
237 $posts = q("SELECT COUNT(*) AS `local_comments` FROM `item`
238 INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
239 WHERE `contact`.`self` and `item`.`id` != `item`.`parent` AND `item`.`network` IN ('%s', '%s', '%s')",
240 dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
242 if (!is_array($posts))
243 $local_comments = -1;
245 $local_comments = $posts[0]["local_comments"];
247 set_config('nodeinfo','local_comments', $local_comments);
249 // Now trying to register
250 $url = "http://the-federation.info/register/".$a->get_hostname();
251 logger('registering url: '.$url, LOGGER_DEBUG);
252 $ret = fetch_url($url);
253 logger('registering answer: '.$ret, LOGGER_DEBUG);
256 set_config('nodeinfo','last_calucation', time());