3 * @copyright Copyright (C) 2010-2021, 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;
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;
31 class Statistics extends BaseModule
33 /** @var IManageConfigValues */
35 /** @var LoggerInterface */
38 public function __construct(IManageConfigValues $config, LoggerInterface $logger, L10n $l10n, array $parameters = [])
40 parent::__construct($l10n, $parameters);
42 $this->logger = $logger;
43 $this->config = $config;
45 if (!$this->config->get("system", "nodeinfo")) {
46 throw new NotFoundException();
50 public function rawContent()
53 intval($this->config->get('config', 'register_policy')) !== Register::CLOSED
54 && !$this->config->get('config', 'invitation_only');
56 /// @todo mark the "service" addons and load them dynamically here
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'),
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,
82 header("Content-Type: application/json");
83 echo json_encode($statistics, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
84 $this->logger->debug("statistics.", ['statistics' => $statistics]);