]> git.mxchange.org Git - friendica.git/blob - src/Module/Statistics.php
Merge pull request #11005 from nupplaphil/feat/module_di
[friendica.git] / src / Module / Statistics.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\Module;
23
24 use Friendica\App;
25 use Friendica\BaseModule;
26 use Friendica\Core\Addon;
27 use Friendica\Core\Config\Capability\IManageConfigValues;
28 use Friendica\Core\L10n;
29 use Friendica\Network\HTTPException\NotFoundException;
30 use Friendica\Util\Profiler;
31 use Psr\Log\LoggerInterface;
32
33 class Statistics extends BaseModule
34 {
35         /** @var IManageConfigValues */
36         protected $config;
37
38         public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, Response $response, array $server, array $parameters = [])
39         {
40                 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
41
42                 $this->config = $config;
43
44                 if (!$this->config->get("system", "nodeinfo")) {
45                         throw new NotFoundException();
46                 }
47         }
48
49         protected function rawContent(array $request = [])
50         {
51                 $registration_open =
52                         intval($this->config->get('config', 'register_policy')) !== Register::CLOSED
53                         && !$this->config->get('config', 'invitation_only');
54
55                 /// @todo mark the "service" addons and load them dynamically here
56                 $services = [
57                         'appnet'      => Addon::isEnabled('appnet'),
58                         'buffer'      => Addon::isEnabled('buffer'),
59                         'dreamwidth'  => Addon::isEnabled('dreamwidth'),
60                         'gnusocial'   => Addon::isEnabled('gnusocial'),
61                         'libertree'   => Addon::isEnabled('libertree'),
62                         'livejournal' => Addon::isEnabled('livejournal'),
63                         'pumpio'      => Addon::isEnabled('pumpio'),
64                         'twitter'     => Addon::isEnabled('twitter'),
65                         'tumblr'      => Addon::isEnabled('tumblr'),
66                         'wordpress'   => Addon::isEnabled('wordpress'),
67                 ];
68
69                 $statistics = array_merge([
70                         'name'                  => $this->config->get('config', 'sitename'),
71                         'network'               => FRIENDICA_PLATFORM,
72                         'version'               => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
73                         'registrations_open'    => $registration_open,
74                         'total_users'           => $this->config->get('nodeinfo', 'total_users'),
75                         'active_users_halfyear' => $this->config->get('nodeinfo', 'active_users_halfyear'),
76                         'active_users_monthly'  => $this->config->get('nodeinfo', 'active_users_monthly'),
77                         'local_posts'           => $this->config->get('nodeinfo', 'local_posts'),
78                         'services'              => $services,
79                 ], $services);
80
81                 header("Content-Type: application/json");
82                 echo json_encode($statistics, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
83                 $this->logger->debug("statistics.", ['statistics' => $statistics]);
84                 exit();
85         }
86 }