]> git.mxchange.org Git - friendica.git/commitdiff
Support Nodeinfo2
authorMichael <heluecht@pirati.ca>
Sun, 12 Jul 2020 21:53:17 +0000 (21:53 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 12 Jul 2020 21:53:17 +0000 (21:53 +0000)
src/Model/Nodeinfo.php
src/Model/User.php
src/Module/NodeInfo.php
static/routes.config.php

index d2e168fa5961788641f32905e84fe7a7158ec8b8..7ccfefd0079276794d78186041fdee8f81a3f15b 100644 (file)
@@ -55,6 +55,7 @@ class Nodeinfo
                $config->set('nodeinfo', 'total_users', $userStats['total_users']);
                $config->set('nodeinfo', 'active_users_halfyear', $userStats['active_users_halfyear']);
                $config->set('nodeinfo', 'active_users_monthly', $userStats['active_users_monthly']);
+               $config->set('nodeinfo', 'active_users_weekly', $userStats['active_users_weekly']);
 
                $logger->debug('user statistics', $userStats);
 
index 16dfb512208cf7e3759d1c0778bff435d793d875..b4ada344e16deaa659569511d7f64333776947e6 100644 (file)
@@ -1272,6 +1272,7 @@ class User
                        'total_users'           => 0,
                        'active_users_halfyear' => 0,
                        'active_users_monthly'  => 0,
+                       'active_users_weekly'   => 0,
                ];
 
                $userStmt = DBA::select('owner-view', ['uid', 'login_date', 'last-item'],
@@ -1284,6 +1285,7 @@ class User
 
                $halfyear = time() - (180 * 24 * 60 * 60);
                $month = time() - (30 * 24 * 60 * 60);
+               $week = time() - (7 * 24 * 60 * 60);
 
                while ($user = DBA::fetch($userStmt)) {
                        $statistics['total_users']++;
@@ -1297,6 +1299,11 @@ class User
                        ) {
                                $statistics['active_users_monthly']++;
                        }
+
+                       if ((strtotime($user['login_date']) > $week) || (strtotime($user['last-item']) > $week)
+                       ) {
+                               $statistics['active_users_weekly']++;
+                       }
                }
                DBA::close($userStmt);
 
index 87321489f3934d506cffbcb0b3f3f724917dee3b..eca0ae3e345a46f74c39990e0ed315c0bd4a9780 100644 (file)
@@ -24,6 +24,7 @@ namespace Friendica\Module;
 use Friendica\BaseModule;
 use Friendica\Core\Addon;
 use Friendica\DI;
+use Friendica\Model\User;
 use stdClass;
 
 /**
@@ -34,10 +35,12 @@ class NodeInfo extends BaseModule
 {
        public static function rawContent(array $parameters = [])
        {
-               if ($parameters['version'] == '1.0') {
+               if (empty($parameters['version'])) {
+                       self::printNodeInfo2();
+               } elseif ($parameters['version'] == '1.0') {
                        self::printNodeInfo1();
                } elseif ($parameters['version'] == '2.0') {
-                       self::printNodeInfo2();
+                       self::printNodeInfo20();
                } else {
                        throw new \Friendica\Network\HTTPException\NotFoundException();
                }
@@ -48,7 +51,7 @@ class NodeInfo extends BaseModule
         *
         * @return Object with supported services
        */
-       private static function getUsage()
+       private static function getUsage(bool $version2 = false)
        {
                $config = DI::config();
 
@@ -62,6 +65,10 @@ class NodeInfo extends BaseModule
                        ];
                        $usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
                        $usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
+
+                       if ($version2) {
+                               $usage->users['activeWeek'] = intval($config->get('nodeinfo', 'active_users_weekly'));
+                       }
                }
 
                return $usage;
@@ -189,9 +196,9 @@ class NodeInfo extends BaseModule
        }
 
        /**
-        * Print the nodeinfo version 2
+        * Print the nodeinfo version 2.0
         */
-       private static function printNodeInfo2()
+       private static function printNodeInfo20()
        {
                $config = DI::config();
 
@@ -242,4 +249,74 @@ class NodeInfo extends BaseModule
                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'           => '1.0',
+                       'server'          => [
+                               'baseUrl'  => DI::baseUrl()->get(),
+                               'name'     => $config->get('config', 'sitename'),
+                               'software' => 'friendica',
+                               'version'  => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
+                       ],
+                       'organization'      => self::getOrganization($config),
+                       'protocols'         => ['dfrn', 'activitypub'],
+                       'services'          => [],
+                       'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
+                       'usage'             => [],
+               ];
+
+               if (!empty($config->get('system', 'diaspora_enabled'))) {
+                       $nodeinfo['protocols'][] = 'diaspora';
+               }
+
+               if (empty($config->get('system', 'ostatus_disabled'))) {
+                       $nodeinfo['protocols'][] = 'ostatus';
+               }
+
+               $nodeinfo['usage'] = self::getUsage(true);
+
+               $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';
+               }
+
+               header('Content-type: application/json; charset=utf-8');
+               echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+               exit;
+       }
+
+       private static function getOrganization($config)
+       {
+               $organization = ['name' => null, 'contact' => null, 'account' => null];
+
+               if (!empty($config->get('config', 'admin_email'))) {
+                       $adminList = explode(',', str_replace(' ', '', $config->get('config', 'admin_email')));
+                       $organization['contact'] = $adminList[0];
+                       $administrator = User::getByEmail($adminList[0], ['username', 'nickname']);
+                       if (!empty($administrator)) {
+                               $organization['name'] = $administrator['username'];
+                               $organization['account'] = DI::baseUrl()->get() . '/profile/' . $administrator['nickname'];
+                       }
+               }
+
+               return $organization;
+       }
 }
index 074c1f5710e23a1d869b2873de23299b06a987e7..cb569e01a01c7a9785f69af300dd75433186a084 100644 (file)
@@ -37,6 +37,7 @@ return [
                '/host-meta'      => [Module\WellKnown\HostMeta::class,     [R::GET]],
                '/nodeinfo'       => [Module\WellKnown\NodeInfo::class,     [R::GET]],
                '/webfinger'      => [Module\Xrd::class,                    [R::GET]],
+               '/x-nodeinfo2'    => [Module\NodeInfo::class,               [R::GET]],
                '/x-social-relay' => [Module\WellKnown\XSocialRelay::class, [R::GET]],
        ],