]> git.mxchange.org Git - friendica.git/commitdiff
Modules separated
authorMichael <heluecht@pirati.ca>
Thu, 28 Nov 2019 07:07:34 +0000 (07:07 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 28 Nov 2019 07:07:34 +0000 (07:07 +0000)
src/Module/NodeInfo.php
src/Module/WellKnown/NodeInfo.php [new file with mode: 0644]
static/routes.config.php

index a4bc9be2b4205bacef7742131e144716d567a41f..deec94d93ffba7f787156625ea44acb61ce833e9 100644 (file)
@@ -17,12 +17,7 @@ class NodeInfo extends BaseModule
        {
                $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') {
+               if ($parameters['version'] == '1.0') {
                        self::printNodeInfo1($app);
                } elseif ($parameters['version'] == '2.0') {
                        self::printNodeInfo2($app);
@@ -31,29 +26,6 @@ class NodeInfo extends BaseModule
                }
        }
 
-       /**
-        * 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
         *
diff --git a/src/Module/WellKnown/NodeInfo.php b/src/Module/WellKnown/NodeInfo.php
new file mode 100644 (file)
index 0000000..7d87252
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+
+namespace Friendica\Module\WellKnown;
+
+use Friendica\App;
+use Friendica\BaseModule;
+
+/**
+ * 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
+ */
+class NodeInfo extends BaseModule
+{
+       public static function rawContent(array $parameters = [])
+       {
+               $app = self::getApp();
+
+               self::printWellKnown($app);
+       }
+
+       /**
+        * 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;
+       }
+}
index bc98fd5952cec782bdf1ecd9aba48ce16f14a1dc..f5b44aec22c80d6c512c54e4c65de89baa42eb2f 100644 (file)
@@ -17,7 +17,7 @@ return [
 
        '/.well-known' => [
                '/host-meta'      => [Module\WellKnown\HostMeta::class,     [R::GET]],
-               '/nodeinfo'       => [Module\NodeInfo::class,               [R::GET]],
+               '/nodeinfo'       => [Module\WellKnown\NodeInfo::class,     [R::GET]],
                '/webfinger'      => [Module\Xrd::class,                    [R::GET]],
                '/x-social-relay' => [Module\WellKnown\XSocialRelay::class, [R::GET]],
        ],