X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FNodeInfo.php;h=99ae26b381536f1fd8960a0c1bd200365dc33814;hb=09de4a5b47439542d5e73d5452e1d30da26c3ae6;hp=3261ef690241b33ddbd47696fb2265c11a1b2a0b;hpb=2628da422a57f573466f08ca3eb5791bf2bc35cf;p=friendica.git diff --git a/src/Module/NodeInfo.php b/src/Module/NodeInfo.php index 3261ef6902..99ae26b381 100644 --- a/src/Module/NodeInfo.php +++ b/src/Module/NodeInfo.php @@ -2,10 +2,10 @@ namespace Friendica\Module; -use Friendica\App; use Friendica\BaseModule; use Friendica\Core\Addon; -use Friendica\Core\System; +use Friendica\DI; +use stdClass; /** * Standardized way of exposing metadata about a server running one of the distributed social networks. @@ -13,84 +13,123 @@ use Friendica\Core\System; */ class NodeInfo extends BaseModule { - public static function init() + public static function rawContent(array $parameters = []) { - $config = self::getApp()->getConfig(); - - if (!$config->get('system', 'nodeinfo')) { + if ($parameters['version'] == '1.0') { + self::printNodeInfo1(); + } elseif ($parameters['version'] == '2.0') { + self::printNodeInfo2(); + } else { throw new \Friendica\Network\HTTPException\NotFoundException(); } } - public static function rawContent() + /** + * Return the supported services + * + * @return Object with supported services + */ + private static function getUsage() { - $app = self::getApp(); + $config = DI::config(); - // @TODO: Replace with parameter from router - // if the first argument is ".well-known", print the well-known text - if (($app->argc > 1) && ($app->argv[0] == '.well-known')) { - self::printWellKnown($app); - // otherwise print the nodeinfo - } else { - self::printNodeInfo($app); + $usage = new stdClass(); + + if (!empty($config->get('system', 'nodeinfo'))) { + $usage->users = [ + 'total' => intval($config->get('nodeinfo', 'total_users')), + 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')), + 'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly')) + ]; + $usage->localPosts = intval($config->get('nodeinfo', 'local_posts')); + $usage->localComments = intval($config->get('nodeinfo', 'local_comments')); } + + return $usage; } /** - * Prints the well-known nodeinfo redirect - * - * @param App $app + * Return the supported services * - * @throws \Friendica\Network\HTTPException\NotFoundException - */ - private static function printWellKnown(App $app) + * @return array with supported services + */ + private static function getServices() { - $config = $app->getConfig(); + $services = [ + 'inbound' => [], + 'outbound' => [], + ]; - if (!$config->get('system', 'nodeinfo')) { - throw new \Friendica\Network\HTTPException\NotFoundException(); + 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'; } - $nodeinfo = [ - 'links' => [[ - 'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0', - 'href' => $app->getBaseURL() . '/nodeinfo/1.0']] - ]; + $services['outbound'][] = 'smtp'; - header('Content-type: application/json; charset=utf-8'); - echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - exit; + 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 - * - * @param App $app + * Print the nodeinfo version 1 */ - private static function printNodeInfo(App $app) + private static function printNodeInfo1() { - $config = $app->getConfig(); - - $smtp = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only')); + $config = DI::config(); $nodeinfo = [ - 'version' => 1.0, + 'version' => '1.0', 'software' => [ 'name' => 'friendica', 'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION, ], 'protocols' => [ 'inbound' => [ - 'friendica', + 'friendica' ], 'outbound' => [ - 'friendica', + 'friendica' ], ], - 'services' => [ - 'inbound' => [], - 'outbound' => [], - ], + 'services' => [], 'usage' => [], 'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED, 'metadata' => [ @@ -108,75 +147,78 @@ class NodeInfo extends BaseModule $nodeinfo['protocols']['outbound'][] = 'gnusocial'; } - if (!empty($config->get('system', 'nodeinfo'))) { + $nodeinfo['usage'] = self::getUsage(); - $nodeinfo['usage']['users'] = [ - 'total' => intval($config->get('nodeinfo', 'total_users')), - 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')), - 'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly')) - ]; - $nodeinfo['usage']['localPosts'] = intval($config->get('nodeinfo', 'local_posts')); - $nodeinfo['usage']['localComments'] = intval($config->get('nodeinfo', 'local_comments')); - - if (Addon::isEnabled('blogger')) { - $nodeinfo['services']['outbound'][] = 'blogger'; - } - if (Addon::isEnabled('dwpost')) { - $nodeinfo['services']['outbound'][] = 'dreamwidth'; - } - if (Addon::isEnabled('statusnet')) { - $nodeinfo['services']['inbound'][] = 'gnusocial'; - $nodeinfo['services']['outbound'][] = 'gnusocial'; - } - if (Addon::isEnabled('ijpost')) { - $nodeinfo['services']['outbound'][] = 'insanejournal'; - } - if (Addon::isEnabled('libertree')) { - $nodeinfo['services']['outbound'][] = 'libertree'; - } - if (Addon::isEnabled('buffer')) { - $nodeinfo['services']['outbound'][] = 'linkedin'; - } - if (Addon::isEnabled('ljpost')) { - $nodeinfo['services']['outbound'][] = 'livejournal'; - } - if (Addon::isEnabled('buffer')) { - $nodeinfo['services']['outbound'][] = 'pinterest'; - } - if (Addon::isEnabled('posterous')) { - $nodeinfo['services']['outbound'][] = 'posterous'; - } - if (Addon::isEnabled('pumpio')) { - $nodeinfo['services']['inbound'][] = 'pumpio'; - $nodeinfo['services']['outbound'][] = 'pumpio'; - } - - if ($smtp) { - $nodeinfo['services']['outbound'][] = 'smtp'; - } - if (Addon::isEnabled('tumblr')) { - $nodeinfo['services']['outbound'][] = 'tumblr'; - } - if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) { - $nodeinfo['services']['outbound'][] = 'twitter'; - } - if (Addon::isEnabled('wppost')) { - $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'; - - $nodeinfo['metadata']['services'] = $nodeinfo['services']; - - if (Addon::isEnabled('twitter')) { - $nodeinfo['metadata']['services']['inbound'][] = 'twitter'; - } - - $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true; + $nodeinfo['services'] = self::getServices(); + + $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'; } + $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 + */ + private static function printNodeInfo2() + { + $config = DI::config(); + + $imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only')); + + $nodeinfo = [ + 'version' => '2.0', + 'software' => [ + 'name' => 'friendica', + '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'; + } + + $nodeinfo['usage'] = self::getUsage(); + + $nodeinfo['services'] = self::getServices(); + + if (Addon::isEnabled('twitter')) { + $nodeinfo['services']['inbound'][] = 'twitter'; + } + + $nodeinfo['services']['inbound'][] = 'atom1.0'; + $nodeinfo['services']['inbound'][] = 'rss2.0'; + $nodeinfo['services']['outbound'][] = 'atom1.0'; + + if ($imap) { + $nodeinfo['services']['inbound'][] = 'imap'; + } + + $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;