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