3 * @copyright Copyright (C) 2020, Friendica
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->debug('user statistics', $userStats);
63 $items = DBA::p("SELECT COUNT(*) AS `total`, `gravity` FROM `item` WHERE `origin` AND NOT `deleted` AND `uid` != 0 AND `gravity` IN (?, ?) GROUP BY `gravity`",
64 GRAVITY_PARENT, GRAVITY_COMMENT);
65 while ($item = DBA::fetch($items)) {
66 if ($item['gravity'] == GRAVITY_PARENT) {
67 $config->set('nodeinfo', 'local_posts', $item['total']);
68 } elseif ($item['gravity'] == GRAVITY_COMMENT) {
69 $config->set('nodeinfo', 'local_comments', $item['total']);
76 * Return the supported services
78 * @return Object with supported services
80 public static function getUsage(bool $version2 = false)
82 $config = DI::config();
84 $usage = new stdClass();
86 if (!empty($config->get('system', 'nodeinfo'))) {
88 'total' => intval($config->get('nodeinfo', 'total_users')),
89 'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
90 'activeMonth' => intval($config->get('nodeinfo', 'active_users_monthly'))
92 $usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
93 $usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
96 $usage->users['activeWeek'] = intval($config->get('nodeinfo', 'active_users_weekly'));
104 * Return the supported services
106 * @return array with supported services
108 public static function getServices()
115 if (Addon::isEnabled('blogger')) {
116 $services['outbound'][] = 'blogger';
118 if (Addon::isEnabled('dwpost')) {
119 $services['outbound'][] = 'dreamwidth';
121 if (Addon::isEnabled('statusnet')) {
122 $services['inbound'][] = 'gnusocial';
123 $services['outbound'][] = 'gnusocial';
125 if (Addon::isEnabled('ijpost')) {
126 $services['outbound'][] = 'insanejournal';
128 if (Addon::isEnabled('libertree')) {
129 $services['outbound'][] = 'libertree';
131 if (Addon::isEnabled('buffer')) {
132 $services['outbound'][] = 'linkedin';
134 if (Addon::isEnabled('ljpost')) {
135 $services['outbound'][] = 'livejournal';
137 if (Addon::isEnabled('buffer')) {
138 $services['outbound'][] = 'pinterest';
140 if (Addon::isEnabled('posterous')) {
141 $services['outbound'][] = 'posterous';
143 if (Addon::isEnabled('pumpio')) {
144 $services['inbound'][] = 'pumpio';
145 $services['outbound'][] = 'pumpio';
148 $services['outbound'][] = 'smtp';
150 if (Addon::isEnabled('tumblr')) {
151 $services['outbound'][] = 'tumblr';
153 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
154 $services['outbound'][] = 'twitter';
156 if (Addon::isEnabled('wppost')) {
157 $services['outbound'][] = 'wordpress';
163 public static function getOrganization($config)
165 $organization = ['name' => null, 'contact' => null, 'account' => null];
167 if (!empty($config->get('config', 'admin_email'))) {
168 $adminList = explode(',', str_replace(' ', '', $config->get('config', 'admin_email')));
169 $organization['contact'] = $adminList[0];
170 $administrator = User::getByEmail($adminList[0], ['username', 'nickname']);
171 if (!empty($administrator)) {
172 $organization['name'] = $administrator['username'];
173 $organization['account'] = DI::baseUrl()->get() . '/profile/' . $administrator['nickname'];
177 return $organization;