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.
 
 
 
 
 
 

258 lines
8.0 KiB

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