]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Nodeinfo.php
Funkwhale context file moved
[friendica.git] / src / Model / Nodeinfo.php
index 7ccfefd0079276794d78186041fdee8f81a3f15b..047fe0e58a6c711b27ac195623cb2e80afef0761 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 namespace Friendica\Model;
 
 use Friendica\Core\Addon;
+use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use stdClass;
 
 /**
  * Model interaction for the nodeinfo
@@ -57,17 +59,128 @@ class Nodeinfo
                $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);
+               $logger->info('user statistics', $userStats);
 
-               $items = DBA::p("SELECT COUNT(*) AS `total`, `gravity` FROM `item` WHERE `origin` AND NOT `deleted` AND `uid` != 0 AND `gravity` IN (?, ?) GROUP BY `gravity`",
-                       GRAVITY_PARENT, GRAVITY_COMMENT);
-               while ($item = DBA::fetch($items)) {
-                       if ($item['gravity'] == GRAVITY_PARENT) {
-                               $config->set('nodeinfo', 'local_posts', $item['total']);
-                       } elseif ($item['gravity'] == GRAVITY_COMMENT) {
-                               $config->set('nodeinfo', 'local_comments', $item['total']);
+               $posts = DBA::count('post-thread', ["EXISTS(SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin` AND `uri-id` = `post-thread`.`uri-id`)"]);
+               $comments = DBA::count('post', ["NOT `deleted` AND `gravity` = ? AND EXISTS(SELECT `uri-id` FROM `post-user` WHERE `origin` AND `uri-id` = `post`.`uri-id`)", GRAVITY_COMMENT]);
+               $config->set('nodeinfo', 'local_posts', $posts);
+               $config->set('nodeinfo', 'local_comments', $comments);
+
+               $logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]);
+       }
+
+       /**
+        * Return the supported services
+        *
+        * @return Object with supported services
+       */
+       public static function getUsage(bool $version2 = false)
+       {
+               $config = DI::config();
+
+               $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'));
+
+                       if ($version2) {
+                               $usage->users['activeWeek'] = intval($config->get('nodeinfo', 'active_users_weekly'));
                        }
                }
-               DBA::close($items);
+
+               return $usage;
+       }
+
+       /**
+        * Return the supported services
+        *
+        * @return array with supported services
+       */
+       public static function getServices(): array
+       {
+               $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';
+               }
+
+               $services['outbound'][] = 'smtp';
+
+               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;
+       }
+
+       /**
+        * Gathers organization information and returns it as an array
+        *
+        * @param IManageConfigValues $config Configuration instance
+        * @return array Organization information
+        */
+       public static function getOrganization(IManageConfigValues $config): array
+       {
+               $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;
        }
 }