]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Nodeinfo.php
Convert custom profile field URL values to rel="me" links
[friendica.git] / src / Model / Nodeinfo.php
index 398666185df1055afb57d194418cdc0e076163fe..93b3b5b2dafe3dfa42f82a15471b6321f668f065 100644 (file)
 namespace Friendica\Model;
 
 use Friendica\Core\Addon;
+use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\Item;
 use stdClass;
 
 /**
@@ -60,8 +62,8 @@ class Nodeinfo
 
                $logger->info('user statistics', $userStats);
 
-               $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]);
+               $posts = DBA::count('post-thread', ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin`)"]);
+               $comments = DBA::count('post', ["NOT `deleted` AND `gravity` = ? AND `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)", Item::GRAVITY_COMMENT]);
                $config->set('nodeinfo', 'local_posts', $posts);
                $config->set('nodeinfo', 'local_comments', $comments);
 
@@ -78,18 +80,17 @@ class Nodeinfo
                $config = DI::config();
 
                $usage = new stdClass();
+               $usage->users = 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->users->total = intval($config->get('nodeinfo', 'total_users'));
+                       $usage->users->activeHalfyear = intval($config->get('nodeinfo', 'active_users_halfyear'));
+                       $usage->users->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'));
+                               $usage->users->activeWeek = intval($config->get('nodeinfo', 'active_users_weekly'));
                        }
                }
 
@@ -156,24 +157,21 @@ class Nodeinfo
                return $services;
        }
 
-       public static function getOrganization()
+       /**
+        * Gathers organization information and returns it as an array
+        *
+        * @param IManageConfigValues $config Configuration instance
+        * @return array Organization information
+        * @throws \Exception
+        */
+       public static function getOrganization(IManageConfigValues $config): array
        {
-               $organization = [
-                       'name' => null,
-                       'contact' => null,
-                       'account' => null
-               ];
+               $administrator = User::getFirstAdmin(['username', 'email', 'nickname']);
 
-               if (!empty(DI::config()->get('config', 'admin_email'))) {
-                       $adminList = explode(',', str_replace(' ', '', DI::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;
+               return [
+                       'name'    => $administrator['username'] ?? null,
+                       'contact' => $administrator['email']    ?? null,
+                       'account' => $administrator['nickname'] ?? '' ? DI::baseUrl()->get() . '/profile/' . $administrator['nickname'] : null,
+               ];
        }
 }