X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FNodeinfo.php;h=4dbe06c9b352e78c8662f7a2e223b97f68605482;hb=fb4c76a2b6e6037df47eda2252e9d4c2e24ea025;hp=6d9c77154a17b720c570f3ab04663c05e39b7b94;hpb=03038e7a3bb74bdab497d26b7f829a5c3036d1c2;p=friendica.git diff --git a/src/Model/Nodeinfo.php b/src/Model/Nodeinfo.php index 6d9c77154a..4dbe06c9b3 100644 --- a/src/Model/Nodeinfo.php +++ b/src/Model/Nodeinfo.php @@ -1,10 +1,32 @@ . + * + */ 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; /** * Model interaction for the nodeinfo @@ -24,40 +46,132 @@ class Nodeinfo // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo. if (Addon::isEnabled('statistics_json')) { $config->set('system', 'nodeinfo', true); + Addon::uninstall('statistics_json'); + } + + if (empty($config->get('system', 'nodeinfo'))) { + return; + } + + $userStats = User::getStatistics(); - $addon = 'statistics_json'; - $addons = $config->get('system', 'addon'); + 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']); - if ($addons) { - $addons_arr = explode(',', str_replace(' ', '', $addons)); + $logger->info('user statistics', $userStats); + + $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]); + } - $idx = array_search($addon, $addons_arr); - if ($idx !== false) { - unset($addons_arr[$idx]); - Addon::uninstall($addon); - $config->set('system', 'addon', implode(', ', $addons_arr)); - } + /** + * Return the supported services + * + * @return Object with supported services + */ + public static function getUsage(bool $version2 = false) + { + $config = DI::config(); + + $usage = new stdClass(); + $usage->users = new \stdClass; + + if (!empty($config->get('system', 'nodeinfo'))) { + $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(DI::keyValue()->get('nodeinfo_active_users_weekly')); } } - if (empty($config->get('system', 'nodeinfo'))) { - return; + 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'; } - $userStats = User::getStatistics(); + $services['outbound'][] = 'smtp'; - $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']); + if (Addon::isEnabled('tumblr')) { + $services['outbound'][] = 'tumblr'; + } + if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) { + $services['outbound'][] = 'twitter'; + } + if (Addon::isEnabled('wppost')) { + $services['outbound'][] = 'wordpress'; + } - $logger->debug('user statistics', $userStats); + return $services; + } - $local_posts = DBA::count('thread', ["`wall` AND NOT `deleted` AND `uid` != 0"]); - $config->set('nodeinfo', 'local_posts', $local_posts); - $logger->debug('thread statistics', ['local_posts' => $local_posts]); + /** + * 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 + { + $administrator = User::getFirstAdmin(['username', 'email', 'nickname']); - $local_comments = DBA::count('item', ["`origin` AND `id` != `parent` AND NOT `deleted` AND `uid` != 0"]); - $config->set('nodeinfo', 'local_comments', $local_comments); - $logger->debug('item statistics', ['local_comments' => $local_comments]); + return [ + 'name' => $administrator['username'] ?? null, + 'contact' => $administrator['email'] ?? null, + 'account' => $administrator['nickname'] ?? '' ? DI::baseUrl() . '/profile/' . $administrator['nickname'] : null, + ]; } }