]> git.mxchange.org Git - friendica.git/blob - src/Model/Nodeinfo.php
Merge pull request #10969 from MrPetovan/task/remove-private-contacts
[friendica.git] / src / Model / Nodeinfo.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Model;
23
24 use Friendica\Core\Addon;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27 use stdClass;
28
29 /**
30  * Model interaction for the nodeinfo
31  */
32 class Nodeinfo
33 {
34         /**
35          * Updates the info about the current node
36          *
37          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
38          */
39         public static function update()
40         {
41                 $config = DI::config();
42                 $logger = DI::logger();
43
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');
48                 }
49
50                 if (empty($config->get('system', 'nodeinfo'))) {
51                         return;
52                 }
53
54                 $userStats = User::getStatistics();
55
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']);
60
61                 $logger->info('user statistics', $userStats);
62
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);
67
68                 $logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]);
69         }
70
71         /**
72          * Return the supported services
73          *
74          * @return Object with supported services
75         */
76         public static function getUsage(bool $version2 = false)
77         {
78                 $config = DI::config();
79
80                 $usage = new stdClass();
81
82                 if (!empty($config->get('system', 'nodeinfo'))) {
83                         $usage->users = [
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'))
87                         ];
88                         $usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
89                         $usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
90
91                         if ($version2) {
92                                 $usage->users['activeWeek'] = intval($config->get('nodeinfo', 'active_users_weekly'));
93                         }
94                 }
95
96                 return $usage;
97         }
98
99         /**
100          * Return the supported services
101          *
102          * @return array with supported services
103         */
104         public static function getServices()
105         {
106                 $services = [
107                         'inbound'  => [],
108                         'outbound' => [],
109                 ];
110
111                 if (Addon::isEnabled('blogger')) {
112                         $services['outbound'][] = 'blogger';
113                 }
114                 if (Addon::isEnabled('dwpost')) {
115                         $services['outbound'][] = 'dreamwidth';
116                 }
117                 if (Addon::isEnabled('statusnet')) {
118                         $services['inbound'][] = 'gnusocial';
119                         $services['outbound'][] = 'gnusocial';
120                 }
121                 if (Addon::isEnabled('ijpost')) {
122                         $services['outbound'][] = 'insanejournal';
123                 }
124                 if (Addon::isEnabled('libertree')) {
125                         $services['outbound'][] = 'libertree';
126                 }
127                 if (Addon::isEnabled('buffer')) {
128                         $services['outbound'][] = 'linkedin';
129                 }
130                 if (Addon::isEnabled('ljpost')) {
131                         $services['outbound'][] = 'livejournal';
132                 }
133                 if (Addon::isEnabled('buffer')) {
134                         $services['outbound'][] = 'pinterest';
135                 }
136                 if (Addon::isEnabled('posterous')) {
137                         $services['outbound'][] = 'posterous';
138                 }
139                 if (Addon::isEnabled('pumpio')) {
140                         $services['inbound'][] = 'pumpio';
141                         $services['outbound'][] = 'pumpio';
142                 }
143
144                 $services['outbound'][] = 'smtp';
145
146                 if (Addon::isEnabled('tumblr')) {
147                         $services['outbound'][] = 'tumblr';
148                 }
149                 if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
150                         $services['outbound'][] = 'twitter';
151                 }
152                 if (Addon::isEnabled('wppost')) {
153                         $services['outbound'][] = 'wordpress';
154                 }
155
156                 return $services;
157         }
158
159         public static function getOrganization($config)
160         {
161                 $organization = ['name' => null, 'contact' => null, 'account' => null];
162
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'];
170                         }
171                 }
172
173                 return $organization;
174         }
175 }