Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
7.4 KiB

  1. <?php
  2. /*
  3. Documentation: http://nodeinfo.diaspora.software/schema.html
  4. */
  5. function nodeinfo_wellknown(&$a) {
  6. if (!get_config("system", "nodeinfo")) {
  7. http_status_exit(404);
  8. killme();
  9. }
  10. $nodeinfo = array("links" => array("rel" => "http://nodeinfo.diaspora.software/ns/schema/1.0",
  11. "href" => $a->get_baseurl()."/nodeinfo/1.0"));
  12. header('Content-type: application/json; charset=utf-8');
  13. echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
  14. exit;
  15. }
  16. function nodeinfo_init(&$a){
  17. if (!get_config("system", "nodeinfo")) {
  18. http_status_exit(404);
  19. killme();
  20. }
  21. if (($a->argc != 2) OR ($a->argv[1] != "1.0")) {
  22. http_status_exit(404);
  23. killme();
  24. }
  25. $smtp = (function_exists("imap_open") AND !get_config("system","imap_disabled") AND !get_config("system","dfrn_only"));
  26. $nodeinfo = array();
  27. $nodeinfo["version"] = "1.0";
  28. $nodeinfo["software"] = array("name" => "friendica", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
  29. $nodeinfo["protocols"] = array();
  30. $nodeinfo["protocols"]["inbound"] = array();
  31. $nodeinfo["protocols"]["outbound"] = array();
  32. if (get_config("system","diaspora_enabled")) {
  33. $nodeinfo["protocols"]["inbound"][] = "diaspora";
  34. $nodeinfo["protocols"]["outbound"][] = "diaspora";
  35. }
  36. $nodeinfo["protocols"]["inbound"][] = "friendica";
  37. $nodeinfo["protocols"]["outbound"][] = "friendica";
  38. if (!get_config("system","ostatus_disabled")) {
  39. $nodeinfo["protocols"]["inbound"][] = "gnusocial";
  40. $nodeinfo["protocols"]["outbound"][] = "gnusocial";
  41. }
  42. //if ($smtp) {
  43. // $nodeinfo["protocols"]["inbound"][] = "smtp";
  44. // $nodeinfo["protocols"]["outbound"][] = "smtp";
  45. //}
  46. $nodeinfo["services"] = array();
  47. if (nodeinfo_plugin_enabled("appnet") OR nodeinfo_plugin_enabled("buffer"))
  48. $nodeinfo["services"][] = "appnet";
  49. if (nodeinfo_plugin_enabled("blogger"))
  50. $nodeinfo["services"][] = "blogger";
  51. //if (get_config("system","diaspora_enabled"))
  52. // $nodeinfo["services"][] = "diaspora";
  53. if (nodeinfo_plugin_enabled("dwpost"))
  54. $nodeinfo["services"][] = "dreamwidth";
  55. if (nodeinfo_plugin_enabled("fbpost") OR nodeinfo_plugin_enabled("buffer"))
  56. $nodeinfo["services"][] = "facebook";
  57. //$nodeinfo["services"][] = "friendica";
  58. //if (nodeinfo_plugin_enabled("statusnet") OR !get_config("system","ostatus_disabled"))
  59. if (nodeinfo_plugin_enabled("statusnet"))
  60. $nodeinfo["services"][] = "gnusocial";
  61. if (nodeinfo_plugin_enabled("gpluspost") OR nodeinfo_plugin_enabled("buffer"))
  62. $nodeinfo["services"][] = "google";
  63. if (nodeinfo_plugin_enabled("ijpost"))
  64. $nodeinfo["services"][] = "insanejournal";
  65. if (nodeinfo_plugin_enabled("libertree"))
  66. $nodeinfo["services"][] = "libertree";
  67. if (nodeinfo_plugin_enabled("buffer"))
  68. $nodeinfo["services"][] = "linkedin";
  69. if (nodeinfo_plugin_enabled("ljpost"))
  70. $nodeinfo["services"][] = "livejournal";
  71. if (nodeinfo_plugin_enabled("buffer"))
  72. $nodeinfo["services"][] = "pinterest";
  73. if (nodeinfo_plugin_enabled("posterous"))
  74. $nodeinfo["services"][] = "posterous";
  75. if (nodeinfo_plugin_enabled("pumpio"))
  76. $nodeinfo["services"][] = "pumpio";
  77. // redmatrix
  78. if ($smtp)
  79. $nodeinfo["services"][] = "smtp";
  80. if (nodeinfo_plugin_enabled("tumblr"))
  81. $nodeinfo["services"][] = "tumblr";
  82. if (nodeinfo_plugin_enabled("twitter"))
  83. $nodeinfo["services"][] = "twitter";
  84. if (nodeinfo_plugin_enabled("wppost"))
  85. $nodeinfo["services"][] = "wordpress";
  86. $nodeinfo["openRegistrations"] = ($a->config['register_policy'] != 0);
  87. $nodeinfo["usage"] = array();
  88. $nodeinfo["usage"]["users"] = array("total" => (int)get_config("nodeinfo","total_users"),
  89. "activeHalfyear" => (int)get_config("nodeinfo","active_users_halfyear"),
  90. "activeMonth" => (int)get_config("nodeinfo","active_users_monthly"));
  91. $nodeinfo["usage"]["localPosts"] = (int)get_config("nodeinfo","local_posts");
  92. $nodeinfo["usage"]["localComments"] = (int)get_config("nodeinfo","local_comments");
  93. $nodeinfo["metadata"] = new stdClass();
  94. header('Content-type: application/json; charset=utf-8');
  95. echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
  96. exit;
  97. }
  98. function nodeinfo_plugin_enabled($plugin) {
  99. $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = '%s'", $plugin);
  100. return((bool)(count($r) > 0));
  101. }
  102. function nodeinfo_cron() {
  103. if (!get_config("system", "nodeinfo"))
  104. return;
  105. $last = get_config('nodeinfo','last_calucation');
  106. if($last) {
  107. // Calculate every 24 hours
  108. $next = $last + (24 * 60 * 60);
  109. if($next > time()) {
  110. logger("calculation intervall not reached");
  111. return;
  112. }
  113. }
  114. logger("cron_start");
  115. $users = q("SELECT profile.*, `user`.`login_date`, `lastitem`.`lastitem_date`
  116. FROM (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
  117. FROM `item`
  118. WHERE `item`.`type` = 'wall'
  119. GROUP BY `item`.`uid`) AS `lastitem`
  120. RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, `contact`, `profile`
  121. WHERE
  122. `user`.`uid` = `contact`.`uid` AND `profile`.`uid` = `user`.`uid`
  123. AND `profile`.`is-default` AND (`profile`.`publish` OR `profile`.`net-publish`)
  124. AND `user`.`verified` AND `contact`.`self`
  125. AND NOT `user`.`blocked`
  126. AND NOT `user`.`account_removed`
  127. AND NOT `user`.`account_expired`");
  128. if (is_array($users)) {
  129. $total_users = count($users);
  130. $active_users_halfyear = 0;
  131. $active_users_monthly = 0;
  132. $halfyear = time() - (180 * 24 * 60 * 60);
  133. $month = time() - (30 * 24 * 60 * 60);
  134. foreach ($users AS $user) {
  135. if ((strtotime($user['login_date']) > $halfyear) OR
  136. (strtotime($user['lastitem_date']) > $halfyear))
  137. ++$active_users_halfyear;
  138. if ((strtotime($user['login_date']) > $month) OR
  139. (strtotime($user['lastitem_date']) > $month))
  140. ++$active_users_monthly;
  141. }
  142. set_config('nodeinfo','total_users', $total_users);
  143. logger("total_users: ".$total_users, LOGGER_DEBUG);
  144. set_config('nodeinfo','active_users_halfyear', $active_users_halfyear);
  145. set_config('nodeinfo','active_users_monthly', $active_users_monthly);
  146. }
  147. //$posts = q("SELECT COUNT(*) AS local_posts FROM `item` WHERE `wall` AND `uid` != 0 AND `id` = `parent` AND left(body, 6) != '[share'");
  148. $posts = q("SELECT COUNT(*) AS `local_posts` FROM `item`
  149. INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  150. WHERE `contact`.`self` and `item`.`id` = `item`.`parent` AND left(body, 6) != '[share' AND `item`.`network` IN ('%s', '%s', '%s')",
  151. dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
  152. if (!is_array($posts))
  153. $local_posts = -1;
  154. else
  155. $local_posts = $posts[0]["local_posts"];
  156. set_config('nodeinfo','local_posts', $local_posts);
  157. logger("local_posts: ".$local_posts, LOGGER_DEBUG);
  158. $posts = q("SELECT COUNT(*) AS `local_comments` FROM `item`
  159. INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
  160. WHERE `contact`.`self` and `item`.`id` != `item`.`parent` AND `item`.`network` IN ('%s', '%s', '%s')",
  161. dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DFRN));
  162. if (!is_array($posts))
  163. $local_comments = -1;
  164. else
  165. $local_comments = $posts[0]["local_comments"];
  166. set_config('nodeinfo','local_comments', $local_comments);
  167. // Now trying to register
  168. //$url = "http://the-federation.info/register/".$a->get_hostname();
  169. //logger('nodeinfo_cron: registering url: '.$url, LOGGER_DEBUG);
  170. //$ret = fetch_url($url);
  171. //logger('nodeinfo_cron: registering answer: '.$ret, LOGGER_DEBUG);
  172. logger("cron_end");
  173. set_config('nodeinfo','last_calucation', time());
  174. }
  175. ?>