2015-08-10 21:33:57 +02:00
|
|
|
<?php
|
2015-11-11 22:41:44 +01:00
|
|
|
/**
|
2015-11-11 21:37:16 +01:00
|
|
|
* @file mod/nodeinfo.php
|
2017-01-09 13:14:25 +01:00
|
|
|
*
|
2015-11-11 21:37:16 +01:00
|
|
|
* Documentation: http://nodeinfo.diaspora.software/schema.html
|
2015-08-10 21:33:57 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-30 06:07:00 +02:00
|
|
|
use Friendica\App;
|
2018-01-17 19:42:40 +01:00
|
|
|
use Friendica\Core\Addon;
|
2017-08-26 08:04:21 +02:00
|
|
|
use Friendica\Core\System;
|
2017-04-30 06:01:26 +02:00
|
|
|
use Friendica\Core\Config;
|
2018-01-27 05:09:48 +01:00
|
|
|
use Friendica\Util\Network;
|
2018-05-22 22:10:18 +02:00
|
|
|
require_once 'include/dba.php';
|
2017-03-26 14:51:25 +02:00
|
|
|
|
2017-01-09 13:14:25 +01:00
|
|
|
function nodeinfo_wellknown(App $a) {
|
2018-01-15 14:05:12 +01:00
|
|
|
$nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
|
|
|
|
'href' => System::baseUrl().'/nodeinfo/1.0']]];
|
2015-08-10 21:33:57 +02:00
|
|
|
|
|
|
|
header('Content-type: application/json; charset=utf-8');
|
2015-08-10 21:54:57 +02:00
|
|
|
echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
2015-08-10 21:33:57 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2017-01-09 13:14:25 +01:00
|
|
|
function nodeinfo_init(App $a) {
|
2017-03-26 14:51:25 +02:00
|
|
|
if (!Config::get('system', 'nodeinfo')) {
|
2018-01-27 17:59:10 +01:00
|
|
|
System::httpExit(404);
|
2015-08-10 21:33:57 +02:00
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
2017-06-08 04:00:59 +02:00
|
|
|
if (($a->argc != 2) || ($a->argv[1] != '1.0')) {
|
2018-01-27 17:59:10 +01:00
|
|
|
System::httpExit(404);
|
2015-08-10 21:33:57 +02:00
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
2017-06-08 04:00:59 +02:00
|
|
|
$smtp = (function_exists('imap_open') && !Config::get('system', 'imap_disabled') && !Config::get('system', 'dfrn_only'));
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$nodeinfo = [];
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['version'] = '1.0';
|
2018-01-15 14:05:12 +01:00
|
|
|
$nodeinfo['software'] = ['name' => 'friendica', 'version' => FRIENDICA_VERSION.'-'.DB_UPDATE_VERSION];
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$nodeinfo['protocols'] = [];
|
|
|
|
$nodeinfo['protocols']['inbound'] = [];
|
|
|
|
$nodeinfo['protocols']['outbound'] = [];
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2017-03-26 14:51:25 +02:00
|
|
|
if (Config::get('system', 'diaspora_enabled')) {
|
|
|
|
$nodeinfo['protocols']['inbound'][] = 'diaspora';
|
|
|
|
$nodeinfo['protocols']['outbound'][] = 'diaspora';
|
2015-08-10 21:33:57 +02:00
|
|
|
}
|
|
|
|
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['protocols']['inbound'][] = 'friendica';
|
|
|
|
$nodeinfo['protocols']['outbound'][] = 'friendica';
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2017-03-26 14:51:25 +02:00
|
|
|
if (!Config::get('system', 'ostatus_disabled')) {
|
|
|
|
$nodeinfo['protocols']['inbound'][] = 'gnusocial';
|
|
|
|
$nodeinfo['protocols']['outbound'][] = 'gnusocial';
|
2015-08-10 21:33:57 +02:00
|
|
|
}
|
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$nodeinfo['services'] = [];
|
|
|
|
$nodeinfo['services']['inbound'] = [];
|
|
|
|
$nodeinfo['services']['outbound'] = [];
|
2015-08-24 07:47:42 +02:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$nodeinfo['usage'] = [];
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['openRegistrations'] = ($a->config['register_policy'] != 0);
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$nodeinfo['metadata'] = ['nodeName' => $a->config['sitename']];
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2017-03-26 14:51:25 +02:00
|
|
|
if (Config::get('system', 'nodeinfo')) {
|
2015-08-11 00:37:27 +02:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$nodeinfo['usage']['users'] = ['total' => (int)Config::get('nodeinfo', 'total_users'),
|
2017-03-26 14:51:25 +02:00
|
|
|
'activeHalfyear' => (int)Config::get('nodeinfo', 'active_users_halfyear'),
|
2018-01-15 14:05:12 +01:00
|
|
|
'activeMonth' => (int)Config::get('nodeinfo', 'active_users_monthly')];
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['usage']['localPosts'] = (int)Config::get('nodeinfo', 'local_posts');
|
|
|
|
$nodeinfo['usage']['localComments'] = (int)Config::get('nodeinfo', 'local_comments');
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('appnet')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['inbound'][] = 'appnet';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('appnet') || Addon::isEnabled('buffer')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'appnet';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('blogger')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'blogger';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('dwpost')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'dreamwidth';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('fbpost') || Addon::isEnabled('buffer')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'facebook';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('statusnet')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['inbound'][] = 'gnusocial';
|
|
|
|
$nodeinfo['services']['outbound'][] = 'gnusocial';
|
|
|
|
}
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('gpluspost') || Addon::isEnabled('buffer')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'google';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('ijpost')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'insanejournal';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('libertree')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'libertree';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('buffer')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'linkedin';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('ljpost')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'livejournal';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('buffer')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'pinterest';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('posterous')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'posterous';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('pumpio')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['inbound'][] = 'pumpio';
|
|
|
|
$nodeinfo['services']['outbound'][] = 'pumpio';
|
|
|
|
}
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2017-03-26 14:51:25 +02:00
|
|
|
if ($smtp) {
|
|
|
|
$nodeinfo['services']['outbound'][] = 'smtp';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('tumblr')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'tumblr';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'twitter';
|
|
|
|
}
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('wppost')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['services']['outbound'][] = 'wordpress';
|
|
|
|
}
|
|
|
|
$nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
|
|
|
|
$nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
|
|
|
|
$nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
|
|
|
|
$nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
|
2015-08-11 00:37:27 +02:00
|
|
|
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['metadata']['services'] = $nodeinfo['services'];
|
2015-08-11 00:37:27 +02:00
|
|
|
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('twitter')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
$nodeinfo['metadata']['services']['inbound'][] = 'twitter';
|
|
|
|
}
|
2018-07-14 18:08:06 +02:00
|
|
|
|
|
|
|
$nodeinfo['metadata']['explicitContent'] = Config::get('system', 'explicit_content', false) == true;
|
2015-08-24 07:47:42 +02:00
|
|
|
}
|
2015-08-10 21:33:57 +02:00
|
|
|
|
|
|
|
header('Content-type: application/json; charset=utf-8');
|
2015-08-10 21:54:57 +02:00
|
|
|
echo json_encode($nodeinfo, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
2015-08-10 21:33:57 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2016-02-07 15:11:34 +01:00
|
|
|
|
|
|
|
|
2015-08-10 21:33:57 +02:00
|
|
|
function nodeinfo_cron() {
|
2015-08-11 23:50:31 +02:00
|
|
|
|
|
|
|
$a = get_app();
|
|
|
|
|
2018-05-22 22:10:18 +02:00
|
|
|
// If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
|
2018-01-17 19:42:40 +01:00
|
|
|
if (Addon::isEnabled('statistics_json')) {
|
2017-03-26 14:51:25 +02:00
|
|
|
Config::set('system', 'nodeinfo', true);
|
2015-08-16 21:45:51 +02:00
|
|
|
|
2018-01-17 20:22:38 +01:00
|
|
|
$addon = 'statistics_json';
|
|
|
|
$addons = Config::get('system', 'addon');
|
|
|
|
$addons_arr = [];
|
2015-08-16 21:45:51 +02:00
|
|
|
|
2018-01-17 20:22:38 +01:00
|
|
|
if ($addons) {
|
|
|
|
$addons_arr = explode(',',str_replace(' ', '',$addons));
|
2015-08-16 21:45:51 +02:00
|
|
|
|
2018-01-17 20:22:38 +01:00
|
|
|
$idx = array_search($addon, $addons_arr);
|
2017-03-26 14:51:25 +02:00
|
|
|
if ($idx !== false) {
|
2018-01-17 20:22:38 +01:00
|
|
|
unset($addons_arr[$idx]);
|
|
|
|
Addon::uninstall($addon);
|
|
|
|
Config::set('system', 'addon', implode(', ',$addons_arr));
|
2015-08-16 21:45:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 14:51:25 +02:00
|
|
|
if (!Config::get('system', 'nodeinfo')) {
|
2015-08-10 21:33:57 +02:00
|
|
|
return;
|
2017-03-26 14:51:25 +02:00
|
|
|
}
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-05-22 22:10:18 +02:00
|
|
|
logger('cron_start');
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2017-09-15 23:00:39 +02:00
|
|
|
$users = q("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
|
2016-10-04 05:51:13 +02:00
|
|
|
FROM `user`
|
|
|
|
INNER JOIN `profile` ON `profile`.`uid` = `user`.`uid` AND `profile`.`is-default`
|
2016-10-14 07:45:32 +02:00
|
|
|
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
|
2016-10-04 05:51:13 +02:00
|
|
|
WHERE (`profile`.`publish` OR `profile`.`net-publish`) AND `user`.`verified`
|
|
|
|
AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
|
|
|
|
AND NOT `user`.`account_expired`");
|
2015-08-10 21:33:57 +02:00
|
|
|
if (is_array($users)) {
|
2018-05-22 22:10:18 +02:00
|
|
|
$total_users = count($users);
|
|
|
|
$active_users_halfyear = 0;
|
|
|
|
$active_users_monthly = 0;
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-05-22 22:10:18 +02:00
|
|
|
$halfyear = time() - (180 * 24 * 60 * 60);
|
|
|
|
$month = time() - (30 * 24 * 60 * 60);
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-05-22 22:10:18 +02:00
|
|
|
foreach ($users AS $user) {
|
|
|
|
if ((strtotime($user['login_date']) > $halfyear) ||
|
|
|
|
(strtotime($user['last-item']) > $halfyear)) {
|
|
|
|
++$active_users_halfyear;
|
|
|
|
}
|
|
|
|
if ((strtotime($user['login_date']) > $month) ||
|
|
|
|
(strtotime($user['last-item']) > $month)) {
|
|
|
|
++$active_users_monthly;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Config::set('nodeinfo', 'total_users', $total_users);
|
|
|
|
Config::set('nodeinfo', 'active_users_halfyear', $active_users_halfyear);
|
|
|
|
Config::set('nodeinfo', 'active_users_monthly', $active_users_monthly);
|
2016-12-10 13:28:49 +01:00
|
|
|
|
2018-05-22 22:10:18 +02:00
|
|
|
logger('total_users: ' . $total_users . '/' . $active_users_halfyear. '/' . $active_users_monthly, LOGGER_DEBUG);
|
2017-03-26 14:51:25 +02:00
|
|
|
}
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-05-22 22:10:18 +02:00
|
|
|
$local_posts = dba::count('thread', ["`wall` AND NOT `deleted` AND `uid` != 0"]);
|
|
|
|
Config::set('nodeinfo', 'local_posts', $local_posts);
|
|
|
|
logger('local_posts: ' . $local_posts, LOGGER_DEBUG);
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-05-22 22:10:18 +02:00
|
|
|
$local_comments = dba::count('item', ["`origin` AND `id` != `parent` AND NOT `deleted` AND `uid` != 0"]);
|
2017-03-26 14:51:25 +02:00
|
|
|
Config::set('nodeinfo', 'local_comments', $local_comments);
|
2018-05-22 22:10:18 +02:00
|
|
|
logger('local_comments: ' . $local_comments, LOGGER_DEBUG);
|
2015-08-10 21:33:57 +02:00
|
|
|
|
|
|
|
// Now trying to register
|
2017-03-26 14:51:25 +02:00
|
|
|
$url = 'http://the-federation.info/register/'.$a->get_hostname();
|
2018-05-22 22:10:18 +02:00
|
|
|
logger('registering url: '.$url, LOGGER_DEBUG);
|
2018-01-27 17:13:41 +01:00
|
|
|
$ret = Network::fetchUrl($url);
|
2018-05-22 22:10:18 +02:00
|
|
|
logger('registering answer: '.$ret, LOGGER_DEBUG);
|
2015-08-10 21:33:57 +02:00
|
|
|
|
2018-05-22 22:10:18 +02:00
|
|
|
logger('cron_end');
|
2015-08-10 21:33:57 +02:00
|
|
|
}
|