3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model;
24 use Friendica\Core\Addon;
25 use Friendica\Core\Config\Capability\IManageConfigValues;
26 use Friendica\Database\DBA;
28 use Friendica\Model\Item;
32 * Model interaction for the nodeinfo
37 * Updates the info about the current node
39 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
41 public static function update()
43 $config = DI::config();
44 $logger = DI::logger();
46 // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
47 if (Addon::isEnabled('statistics_json')) {
48 $config->set('system', 'nodeinfo', true);
49 Addon::uninstall('statistics_json');
52 if (empty($config->get('system', 'nodeinfo'))) {
56 $userStats = User::getStatistics();
58 DI::keyValue()->set('nodeinfo_total_users', $userStats['total_users']);
59 DI::keyValue()->set('nodeinfo_active_users_halfyear', $userStats['active_users_halfyear']);
60 DI::keyValue()->set('nodeinfo_active_users_monthly', $userStats['active_users_monthly']);
61 DI::keyValue()->set('nodeinfo_active_users_weekly', $userStats['active_users_weekly']);
63 $logger->info('user statistics', $userStats);
65 $posts = DBA::count('post-thread', ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin`)"]);
66 $comments = DBA::count('post', ["NOT `deleted` AND `gravity` = ? AND `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)", Item::GRAVITY_COMMENT]);
67 DI::keyValue()->set('nodeinfo_local_posts', $posts);
68 DI::keyValue()->set('nodeinfo_local_comments', $comments);
70 $logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]);
74 * Return the supported services
76 * @return Object with supported services
78 public static function getUsage(bool $version2 = false)
80 $config = DI::config();
82 $usage = new stdClass();
83 $usage->users = new \stdClass;
85 if (!empty($config->get('system', 'nodeinfo'))) {
86 $usage->users->total = intval(DI::keyValue()->get('nodeinfo_total_users'));
87 $usage->users->activeHalfyear = intval(DI::keyValue()->get('nodeinfo_active_users_halfyear'));
88 $usage->users->activeMonth = intval(DI::keyValue()->get('nodeinfo_active_users_monthly'));
89 $usage->localPosts = intval(DI::keyValue()->get('nodeinfo_local_posts'));
90 $usage->localComments = intval(DI::keyValue()->get('nodeinfo_local_comments'));
93 $usage->users->activeWeek = intval(DI::keyValue()->get('nodeinfo_active_users_weekly'));
101 * Return the supported services
103 * @return array with supported services
105 public static function getServices(): array
112 if (Addon::isEnabled('blogger')) {
113 $services['outbound'][] = 'blogger';
115 if (Addon::isEnabled('dwpost')) {
116 $services['outbound'][] = 'dreamwidth';
118 if (Addon::isEnabled('statusnet')) {
119 $services['inbound'][] = 'gnusocial';
120 $services['outbound'][] = 'gnusocial';
122 if (Addon::isEnabled('ijpost')) {
123 $services['outbound'][] = 'insanejournal';
125 if (Addon::isEnabled('libertree')) {
126 $services['outbound'][] = 'libertree';
128 if (Addon::isEnabled('buffer')) {
129 $services['outbound'][] = 'linkedin';
131 if (Addon::isEnabled('ljpost')) {
132 $services['outbound'][] = 'livejournal';
134 if (Addon::isEnabled('buffer')) {
135 $services['outbound'][] = 'pinterest';
137 if (Addon::isEnabled('posterous')) {
138 $services['outbound'][] = 'posterous';
140 if (Addon::isEnabled('pumpio')) {
141 $services['inbound'][] = 'pumpio';
142 $services['outbound'][] = 'pumpio';
145 $services['outbound'][] = 'smtp';
147 if (Addon::isEnabled('tumblr')) {
148 $services['outbound'][] = 'tumblr';
150 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
151 $services['outbound'][] = 'twitter';
153 if (Addon::isEnabled('wppost')) {
154 $services['outbound'][] = 'wordpress';
161 * Gathers organization information and returns it as an array
163 * @param IManageConfigValues $config Configuration instance
164 * @return array Organization information
167 public static function getOrganization(IManageConfigValues $config): array
169 $administrator = User::getFirstAdmin(['username', 'email', 'nickname']);
172 'name' => $administrator['username'] ?? null,
173 'contact' => $administrator['email'] ?? null,
174 'account' => $administrator['nickname'] ?? '' ? DI::baseUrl()->get() . '/profile/' . $administrator['nickname'] : null,