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