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.
 
 
 
 
 
 

260 lines
8.0 KiB

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