]> git.mxchange.org Git - friendica.git/blob - src/Module/Statistics.php
Merge pull request #8271 from MrPetovan/bug/8229-frio-mobile-back-to-top
[friendica.git] / src / Module / Statistics.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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\Module;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\Addon;
26 use Friendica\DI;
27 use Friendica\Network\HTTPException\NotFoundException;
28
29 class Statistics extends BaseModule
30 {
31         public static function init(array $parameters = [])
32         {
33                 if (!DI::config()->get("system", "nodeinfo")) {
34                         throw new NotFoundException();
35                 }
36         }
37
38         public static function rawContent(array $parameters = [])
39         {
40                 $config = DI::config();
41                 $logger = DI::logger();
42
43                 $registration_open =
44                         intval($config->get('config', 'register_policy')) !== Register::CLOSED
45                         && !$config->get('config', 'invitation_only');
46
47                 /// @todo mark the "service" addons and load them dynamically here
48                 $services = [
49                         'appnet'      => Addon::isEnabled('appnet'),
50                         'buffer'      => Addon::isEnabled('buffer'),
51                         'dreamwidth'  => Addon::isEnabled('dreamwidth'),
52                         'gnusocial'   => Addon::isEnabled('gnusocial'),
53                         'libertree'   => Addon::isEnabled('libertree'),
54                         'livejournal' => Addon::isEnabled('livejournal'),
55                         'pumpio'      => Addon::isEnabled('pumpio'),
56                         'twitter'     => Addon::isEnabled('twitter'),
57                         'tumblr'      => Addon::isEnabled('tumblr'),
58                         'wordpress'   => Addon::isEnabled('wordpress'),
59                 ];
60
61                 $statistics = array_merge([
62                         'name'                  => $config->get('config', 'sitename'),
63                         'network'               => FRIENDICA_PLATFORM,
64                         'version'               => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
65                         'registrations_open'    => $registration_open,
66                         'total_users'           => $config->get('nodeinfo', 'total_users'),
67                         'active_users_halfyear' => $config->get('nodeinfo', 'active_users_halfyear'),
68                         'active_users_monthly'  => $config->get('nodeinfo', 'active_users_monthly'),
69                         'local_posts'           => $config->get('nodeinfo', 'local_posts'),
70                         'services'              => $services,
71                 ], $services);
72
73                 header("Content-Type: application/json");
74                 echo json_encode($statistics, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
75                 $logger->debug("statistics.", ['statistics' => $statistics]);
76                 exit();
77         }
78 }