3 * @copyright Copyright (C) 2010-2022, the Friendica project
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\Module;
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;
33 class Statistics extends BaseModule
35 /** @var IManageConfigValues */
38 public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, Response $response, array $server, array $parameters = [])
40 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
42 $this->config = $config;
44 if (!$this->config->get("system", "nodeinfo")) {
45 throw new NotFoundException();
49 protected function rawContent(array $request = [])
52 intval($this->config->get('config', 'register_policy')) !== Register::CLOSED
53 && !$this->config->get('config', 'invitation_only');
55 /// @todo mark the "service" addons and load them dynamically here
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'),
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,
81 header("Content-Type: application/json");
82 echo json_encode($statistics, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
83 $this->logger->debug("statistics.", ['statistics' => $statistics]);