Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

256 linhas
7.9KB

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