2019-04-22 08:00:17 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Module;
|
|
|
|
|
|
|
|
use Friendica\BaseModule;
|
|
|
|
use Friendica\Core\Addon;
|
2019-12-15 16:34:11 -05:00
|
|
|
use Friendica\DI;
|
2020-01-09 04:55:33 -05:00
|
|
|
use stdClass;
|
2019-04-22 08:00:17 -04:00
|
|
|
|
|
|
|
/**
|
2019-04-30 18:14:06 -04:00
|
|
|
* Standardized way of exposing metadata about a server running one of the distributed social networks.
|
|
|
|
* @see https://github.com/jhass/nodeinfo/blob/master/PROTOCOL.md
|
2019-04-22 08:00:17 -04:00
|
|
|
*/
|
2019-04-30 18:14:06 -04:00
|
|
|
class NodeInfo extends BaseModule
|
2019-04-22 08:00:17 -04:00
|
|
|
{
|
2019-11-05 16:48:54 -05:00
|
|
|
public static function rawContent(array $parameters = [])
|
2019-05-01 12:42:44 -04:00
|
|
|
{
|
2019-11-28 02:07:34 -05:00
|
|
|
if ($parameters['version'] == '1.0') {
|
2019-12-15 17:44:33 -05:00
|
|
|
self::printNodeInfo1();
|
2019-11-27 02:25:54 -05:00
|
|
|
} elseif ($parameters['version'] == '2.0') {
|
2019-12-15 17:44:33 -05:00
|
|
|
self::printNodeInfo2();
|
2019-05-01 12:42:44 -04:00
|
|
|
} else {
|
2019-11-27 02:25:54 -05:00
|
|
|
throw new \Friendica\Network\HTTPException\NotFoundException();
|
2019-05-01 12:42:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-27 02:25:54 -05:00
|
|
|
* Return the supported services
|
2019-05-01 12:42:44 -04:00
|
|
|
*
|
2020-01-09 04:55:33 -05:00
|
|
|
* @return Object with supported services
|
2019-11-27 02:25:54 -05:00
|
|
|
*/
|
2019-12-15 17:44:33 -05:00
|
|
|
private static function getUsage()
|
2019-11-27 02:25:54 -05:00
|
|
|
{
|
2019-12-15 17:44:33 -05:00
|
|
|
$config = DI::config();
|
2019-11-27 02:25:54 -05:00
|
|
|
|
2020-01-09 04:55:33 -05:00
|
|
|
$usage = new stdClass();
|
2019-11-27 02:25:54 -05:00
|
|
|
|
|
|
|
if (!empty($config->get('system', 'nodeinfo'))) {
|
2020-01-09 04:55:33 -05:00
|
|
|
$usage->users = [
|
2019-11-27 02:25:54 -05:00
|
|
|
'total' => intval($config->get('nodeinfo', 'total_users')),
|
|
|
|
'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
|
|
|
|
'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly'))
|
|
|
|
];
|
2020-01-09 04:55:33 -05:00
|
|
|
$usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
|
|
|
|
$usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
|
2019-11-27 02:25:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return $usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the supported services
|
|
|
|
*
|
|
|
|
* @return array with supported services
|
|
|
|
*/
|
2019-12-15 17:44:33 -05:00
|
|
|
private static function getServices()
|
2019-04-22 08:00:17 -04:00
|
|
|
{
|
2019-11-27 02:25:54 -05:00
|
|
|
$services = [
|
|
|
|
'inbound' => [],
|
|
|
|
'outbound' => [],
|
|
|
|
];
|
|
|
|
|
|
|
|
if (Addon::isEnabled('blogger')) {
|
|
|
|
$services['outbound'][] = 'blogger';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('dwpost')) {
|
|
|
|
$services['outbound'][] = 'dreamwidth';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('statusnet')) {
|
|
|
|
$services['inbound'][] = 'gnusocial';
|
|
|
|
$services['outbound'][] = 'gnusocial';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('ijpost')) {
|
|
|
|
$services['outbound'][] = 'insanejournal';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('libertree')) {
|
|
|
|
$services['outbound'][] = 'libertree';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('buffer')) {
|
|
|
|
$services['outbound'][] = 'linkedin';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('ljpost')) {
|
|
|
|
$services['outbound'][] = 'livejournal';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('buffer')) {
|
|
|
|
$services['outbound'][] = 'pinterest';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('posterous')) {
|
|
|
|
$services['outbound'][] = 'posterous';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('pumpio')) {
|
|
|
|
$services['inbound'][] = 'pumpio';
|
|
|
|
$services['outbound'][] = 'pumpio';
|
|
|
|
}
|
2019-11-27 02:44:59 -05:00
|
|
|
|
|
|
|
$services['outbound'][] = 'smtp';
|
|
|
|
|
2019-11-27 02:25:54 -05:00
|
|
|
if (Addon::isEnabled('tumblr')) {
|
|
|
|
$services['outbound'][] = 'tumblr';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
|
|
|
|
$services['outbound'][] = 'twitter';
|
|
|
|
}
|
|
|
|
if (Addon::isEnabled('wppost')) {
|
|
|
|
$services['outbound'][] = 'wordpress';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $services;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print the nodeinfo version 1
|
|
|
|
*/
|
2019-12-15 17:44:33 -05:00
|
|
|
private static function printNodeInfo1()
|
2019-11-27 02:25:54 -05:00
|
|
|
{
|
2019-12-15 17:44:33 -05:00
|
|
|
$config = DI::config();
|
2019-11-27 02:25:54 -05:00
|
|
|
|
2019-04-22 08:00:17 -04:00
|
|
|
$nodeinfo = [
|
2019-11-27 02:25:54 -05:00
|
|
|
'version' => '1.0',
|
2019-04-22 08:00:17 -04:00
|
|
|
'software' => [
|
2020-01-12 16:07:40 -05:00
|
|
|
'name' => 'friendica',
|
2019-04-22 08:00:17 -04:00
|
|
|
'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
|
|
|
|
],
|
|
|
|
'protocols' => [
|
|
|
|
'inbound' => [
|
2020-01-12 16:07:40 -05:00
|
|
|
'friendica'
|
2019-04-22 08:00:17 -04:00
|
|
|
],
|
|
|
|
'outbound' => [
|
2020-01-12 16:07:40 -05:00
|
|
|
'friendica'
|
2019-04-22 08:00:17 -04:00
|
|
|
],
|
|
|
|
],
|
2019-11-27 02:25:54 -05:00
|
|
|
'services' => [],
|
2019-04-22 08:00:17 -04:00
|
|
|
'usage' => [],
|
|
|
|
'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
|
|
|
|
'metadata' => [
|
|
|
|
'nodeName' => $config->get('config', 'sitename'),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!empty($config->get('system', 'diaspora_enabled'))) {
|
|
|
|
$nodeinfo['protocols']['inbound'][] = 'diaspora';
|
|
|
|
$nodeinfo['protocols']['outbound'][] = 'diaspora';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($config->get('system', 'ostatus_disabled'))) {
|
|
|
|
$nodeinfo['protocols']['inbound'][] = 'gnusocial';
|
|
|
|
$nodeinfo['protocols']['outbound'][] = 'gnusocial';
|
|
|
|
}
|
|
|
|
|
2019-12-15 17:44:33 -05:00
|
|
|
$nodeinfo['usage'] = self::getUsage();
|
2019-04-22 08:00:17 -04:00
|
|
|
|
2019-12-15 17:44:33 -05:00
|
|
|
$nodeinfo['services'] = self::getServices();
|
2019-11-27 02:25:54 -05:00
|
|
|
|
|
|
|
$nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
|
|
|
|
$nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
|
|
|
|
$nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
|
|
|
|
$nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
|
|
|
|
|
|
|
|
$nodeinfo['metadata']['services'] = $nodeinfo['services'];
|
|
|
|
|
|
|
|
if (Addon::isEnabled('twitter')) {
|
|
|
|
$nodeinfo['metadata']['services']['inbound'][] = 'twitter';
|
2019-04-22 08:00:17 -04:00
|
|
|
}
|
|
|
|
|
2019-11-27 02:25:54 -05:00
|
|
|
$nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
|
|
|
|
|
|
|
|
header('Content-type: application/json; charset=utf-8');
|
|
|
|
echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print the nodeinfo version 2
|
|
|
|
*/
|
2019-12-15 17:44:33 -05:00
|
|
|
private static function printNodeInfo2()
|
2019-11-27 02:25:54 -05:00
|
|
|
{
|
2019-12-15 17:44:33 -05:00
|
|
|
$config = DI::config();
|
2019-11-27 02:25:54 -05:00
|
|
|
|
2019-11-27 02:44:59 -05:00
|
|
|
$imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
|
|
|
|
|
2019-11-27 02:25:54 -05:00
|
|
|
$nodeinfo = [
|
|
|
|
'version' => '2.0',
|
|
|
|
'software' => [
|
2020-01-12 16:07:40 -05:00
|
|
|
'name' => 'friendica',
|
2019-11-27 02:25:54 -05:00
|
|
|
'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
|
|
|
|
],
|
|
|
|
'protocols' => ['dfrn', 'activitypub'],
|
|
|
|
'services' => [],
|
|
|
|
'usage' => [],
|
|
|
|
'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
|
|
|
|
'metadata' => [
|
|
|
|
'nodeName' => $config->get('config', 'sitename'),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!empty($config->get('system', 'diaspora_enabled'))) {
|
|
|
|
$nodeinfo['protocols'][] = 'diaspora';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($config->get('system', 'ostatus_disabled'))) {
|
|
|
|
$nodeinfo['protocols'][] = 'ostatus';
|
|
|
|
}
|
|
|
|
|
2019-12-15 17:44:33 -05:00
|
|
|
$nodeinfo['usage'] = self::getUsage();
|
2019-11-27 02:25:54 -05:00
|
|
|
|
2019-12-15 17:44:33 -05:00
|
|
|
$nodeinfo['services'] = self::getServices();
|
2019-11-27 02:25:54 -05:00
|
|
|
|
2019-11-27 02:36:24 -05:00
|
|
|
if (Addon::isEnabled('twitter')) {
|
|
|
|
$nodeinfo['services']['inbound'][] = 'twitter';
|
|
|
|
}
|
|
|
|
|
2019-11-27 02:25:54 -05:00
|
|
|
$nodeinfo['services']['inbound'][] = 'atom1.0';
|
2019-11-27 02:38:57 -05:00
|
|
|
$nodeinfo['services']['inbound'][] = 'rss2.0';
|
2019-11-27 02:25:54 -05:00
|
|
|
$nodeinfo['services']['outbound'][] = 'atom1.0';
|
|
|
|
|
2019-11-27 02:44:59 -05:00
|
|
|
if ($imap) {
|
|
|
|
$nodeinfo['services']['inbound'][] = 'imap';
|
|
|
|
}
|
|
|
|
|
2019-11-27 02:25:54 -05:00
|
|
|
$nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
|
|
|
|
|
2019-04-22 08:00:17 -04:00
|
|
|
header('Content-type: application/json; charset=utf-8');
|
|
|
|
echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|