X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FNodeinfo.php;h=4dbe06c9b352e78c8662f7a2e223b97f68605482;hb=fb4c76a2b6e6037df47eda2252e9d4c2e24ea025;hp=44181ac941a0ccd9aa3806346a21d4f853e0cc32;hpb=869f3cfec45cfcc4c3f776d6672097fb636c6847;p=friendica.git diff --git a/src/Model/Nodeinfo.php b/src/Model/Nodeinfo.php index 44181ac941..4dbe06c9b3 100644 --- a/src/Model/Nodeinfo.php +++ b/src/Model/Nodeinfo.php @@ -1,6 +1,6 @@ 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']); + DI::keyValue()->set('nodeinfo_total_users', $userStats['total_users']); + DI::keyValue()->set('nodeinfo_active_users_halfyear', $userStats['active_users_halfyear']); + DI::keyValue()->set('nodeinfo_active_users_monthly', $userStats['active_users_monthly']); + DI::keyValue()->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']); - } - } - DBA::close($items); + $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]); + DI::keyValue()->set('nodeinfo_local_posts', $posts); + DI::keyValue()->set('nodeinfo_local_comments', $comments); + + $logger->info('User activity', ['posts' => $posts, 'comments' => $comments]); } /** @@ -82,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->localPosts = intval($config->get('nodeinfo', 'local_posts')); - $usage->localComments = intval($config->get('nodeinfo', 'local_comments')); + $usage->users->total = intval(DI::keyValue()->get('nodeinfo_total_users')); + $usage->users->activeHalfyear = intval(DI::keyValue()->get('nodeinfo_active_users_halfyear')); + $usage->users->activeMonth = intval(DI::keyValue()->get('nodeinfo_active_users_monthly')); + $usage->localPosts = intval(DI::keyValue()->get('nodeinfo_local_posts')); + $usage->localComments = intval(DI::keyValue()->get('nodeinfo_local_comments')); if ($version2) { - $usage->users['activeWeek'] = intval($config->get('nodeinfo', 'active_users_weekly')); + $usage->users->activeWeek = intval(DI::keyValue()->get('nodeinfo_active_users_weekly')); } } @@ -105,7 +102,7 @@ class Nodeinfo * * @return array with supported services */ - public static function getServices() + public static function getServices(): array { $services = [ 'inbound' => [], @@ -160,20 +157,21 @@ class Nodeinfo return $services; } - public static function getOrganization($config) + /** + * 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]; - - 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']; - } - } + $administrator = User::getFirstAdmin(['username', 'email', 'nickname']); - return $organization; + return [ + 'name' => $administrator['username'] ?? null, + 'contact' => $administrator['email'] ?? null, + 'account' => $administrator['nickname'] ?? '' ? DI::baseUrl() . '/profile/' . $administrator['nickname'] : null, + ]; } }