]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/NodeInfo.php
Merge pull request #8156 from MrPetovan/task/7817-custom-fields-part-2
[friendica.git] / src / Module / NodeInfo.php
index 999b3fb8f29e34aa68ef9bdd68fc8baeed8dd23e..99ae26b381536f1fd8960a0c1bd200365dc33814 100644 (file)
@@ -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.
@@ -15,66 +15,34 @@ class NodeInfo extends BaseModule
 {
        public static function rawContent(array $parameters = [])
        {
-               $app = self::getApp();
-
-               // @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
-               } elseif ($parameters['version'] == '1.0') {
-                       self::printNodeInfo1($app);
+               if ($parameters['version'] == '1.0') {
+                       self::printNodeInfo1();
                } elseif ($parameters['version'] == '2.0') {
-                       self::printNodeInfo2($app);
+                       self::printNodeInfo2();
                } else {
                        throw new \Friendica\Network\HTTPException\NotFoundException();
                }
        }
 
-       /**
-        * Prints the well-known nodeinfo redirect
-        *
-        * @param App $app
-        *
-        * @throws \Friendica\Network\HTTPException\NotFoundException
-        */
-       private static function printWellKnown(App $app)
-       {
-               $nodeinfo = [
-                       'links' => [
-                               ['rel'  => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
-                               'href' => $app->getBaseURL() . '/nodeinfo/1.0'],
-                               ['rel'  => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
-                               'href' => $app->getBaseURL() . '/nodeinfo/2.0'],
-                       ]
-               ];
-
-               header('Content-type: application/json; charset=utf-8');
-               echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
-               exit;
-       }
-
        /**
         * Return the supported services
         *
-        * @param App $app
-        *
-        * @return array with supported services
+        * @return Object with supported services
        */
-       private static function getUsage(App $app)
+       private static function getUsage()
        {
-               $config = $app->getConfig();
+               $config = DI::config();
 
-               $usage = [];
+               $usage = new stdClass();
 
                if (!empty($config->get('system', 'nodeinfo'))) {
-                       $usage['users'] = [
+                       $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'));
+                       $usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
+                       $usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
                }
 
                return $usage;
@@ -83,21 +51,15 @@ class NodeInfo extends BaseModule
        /**
         * Return the supported services
         *
-        * @param App $app
-        *
         * @return array with supported services
        */
-       private static function getServices(App $app)
+       private static function getServices()
        {
-               $config = $app->getConfig();
-
                $services = [
                        'inbound'  => [],
                        'outbound' => [],
                ];
 
-               $smtp = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
-
                if (Addon::isEnabled('blogger')) {
                        $services['outbound'][] = 'blogger';
                }
@@ -130,9 +92,9 @@ class NodeInfo extends BaseModule
                        $services['inbound'][] = 'pumpio';
                        $services['outbound'][] = 'pumpio';
                }
-               if ($smtp) {
-                       $services['outbound'][] = 'smtp';
-               }
+
+               $services['outbound'][] = 'smtp';
+
                if (Addon::isEnabled('tumblr')) {
                        $services['outbound'][] = 'tumblr';
                }
@@ -148,12 +110,10 @@ class NodeInfo extends BaseModule
 
        /**
         * Print the nodeinfo version 1
-        *
-        * @param App $app
         */
-       private static function printNodeInfo1(App $app)
+       private static function printNodeInfo1()
        {
-               $config = $app->getConfig();
+               $config = DI::config();
 
                $nodeinfo = [
                        'version'           => '1.0',
@@ -163,10 +123,10 @@ class NodeInfo extends BaseModule
                        ],
                        'protocols'         => [
                                'inbound'  => [
-                                       'friendica', 'activitypub'
+                                       'friendica'
                                ],
                                'outbound' => [
-                                       'friendica', 'activitypub'
+                                       'friendica'
                                ],
                        ],
                        'services'          => [],
@@ -187,9 +147,9 @@ class NodeInfo extends BaseModule
                        $nodeinfo['protocols']['outbound'][] = 'gnusocial';
                }
 
-               $nodeinfo['usage'] = self::getUsage($app);
+               $nodeinfo['usage'] = self::getUsage();
 
-               $nodeinfo['services'] = self::getServices($app);
+               $nodeinfo['services'] = self::getServices();
 
                $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
                $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
@@ -211,12 +171,12 @@ class NodeInfo extends BaseModule
 
        /**
         * Print the nodeinfo version 2
-        *
-        * @param App $app
         */
-       private static function printNodeInfo2(App $app)
+       private static function printNodeInfo2()
        {
-               $config = $app->getConfig();
+               $config = DI::config();
+
+               $imap = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
 
                $nodeinfo = [
                        'version'           => '2.0',
@@ -241,9 +201,9 @@ class NodeInfo extends BaseModule
                        $nodeinfo['protocols'][] = 'ostatus';
                }
 
-               $nodeinfo['usage'] = self::getUsage($app);
+               $nodeinfo['usage'] = self::getUsage();
 
-               $nodeinfo['services'] = self::getServices($app);
+               $nodeinfo['services'] = self::getServices();
 
                if (Addon::isEnabled('twitter')) {
                        $nodeinfo['services']['inbound'][] = 'twitter';
@@ -253,6 +213,10 @@ class NodeInfo extends BaseModule
                $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');