3 * @copyright Copyright (C) 2010-2022, 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\Database\DBA;
30 * Model interaction for the nodeinfo
35 * Updates the info about the current node
37 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
39 public static function update()
41 $config = DI::config();
42 $logger = DI::logger();
44 // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
45 if (Addon::isEnabled('statistics_json')) {
46 $config->set('system', 'nodeinfo', true);
47 Addon::uninstall('statistics_json');
50 if (empty($config->get('system', 'nodeinfo'))) {
54 $userStats = User::getStatistics();
56 $config->set('nodeinfo', 'total_users', $userStats['total_users']);
57 $config->set('nodeinfo', 'active_users_halfyear', $userStats['active_users_halfyear']);
58 $config->set('nodeinfo', 'active_users_monthly', $userStats['active_users_monthly']);
59 $config->set('nodeinfo', 'active_users_weekly', $userStats['active_users_weekly']);
61 $logger->info('user statistics', $userStats);
63 $posts = DBA::count('post-thread', ["EXISTS(SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin` AND `uri-id` = `post-thread`.`uri-id`)"]);
64 $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]);
65 $config->set('nodeinfo', 'local_posts', $posts);
66 $config->set('nodeinfo', 'local_comments', $comments);
68 $logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]);
72 * Return the supported services
74 * @return Object with supported services
76 public static function getUsage(bool $version2 = false)
78 $config = DI::config();
80 $usage = new stdClass();
82 if (!empty($config->get('system', 'nodeinfo'))) {
84 'total' => intval($config->get('nodeinfo', 'total_users')),
85 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
86 'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly'))
88 $usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
89 $usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
92 $usage->users['activeWeek'] = intval($config->get('nodeinfo', 'active_users_weekly'));
100 * Return the supported services
102 * @return array with supported services
104 public static function getServices()
111 if (Addon::isEnabled('blogger')) {
112 $services['outbound'][] = 'blogger';
114 if (Addon::isEnabled('dwpost')) {
115 $services['outbound'][] = 'dreamwidth';
117 if (Addon::isEnabled('statusnet')) {
118 $services['inbound'][] = 'gnusocial';
119 $services['outbound'][] = 'gnusocial';
121 if (Addon::isEnabled('ijpost')) {
122 $services['outbound'][] = 'insanejournal';
124 if (Addon::isEnabled('libertree')) {
125 $services['outbound'][] = 'libertree';
127 if (Addon::isEnabled('buffer')) {
128 $services['outbound'][] = 'linkedin';
130 if (Addon::isEnabled('ljpost')) {
131 $services['outbound'][] = 'livejournal';
133 if (Addon::isEnabled('buffer')) {
134 $services['outbound'][] = 'pinterest';
136 if (Addon::isEnabled('posterous')) {
137 $services['outbound'][] = 'posterous';
139 if (Addon::isEnabled('pumpio')) {
140 $services['inbound'][] = 'pumpio';
141 $services['outbound'][] = 'pumpio';
144 $services['outbound'][] = 'smtp';
146 if (Addon::isEnabled('tumblr')) {
147 $services['outbound'][] = 'tumblr';
149 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
150 $services['outbound'][] = 'twitter';
152 if (Addon::isEnabled('wppost')) {
153 $services['outbound'][] = 'wordpress';
159 public static function getOrganization($config)
161 $organization = ['name' => null, 'contact' => null, 'account' => null];
163 if (!empty($config->get('config', 'admin_email'))) {
164 $adminList = explode(',', str_replace(' ', '', $config->get('config', 'admin_email')));
165 $organization['contact'] = $adminList[0];
166 $administrator = User::getByEmail($adminList[0], ['username', 'nickname']);
167 if (!empty($administrator)) {
168 $organization['name'] = $administrator['username'];
169 $organization['account'] = DI::baseUrl()->get() . '/profile/' . $administrator['nickname'];
173 return $organization;