friendica/src/Object/Api/Mastodon/Stats.php

53 lines
1.7 KiB
PHP
Raw Normal View History

2019-12-11 07:51:59 +01:00
<?php
2020-02-09 15:45:36 +01:00
/**
2023-01-01 15:36:24 +01:00
* @copyright Copyright (C) 2010-2023, the Friendica project
2020-02-09 15:45:36 +01:00
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
2019-12-11 07:51:59 +01:00
namespace Friendica\Object\Api\Mastodon;
2019-12-11 07:51:59 +01:00
use Friendica\BaseDataTransferObject;
use Friendica\Core\Config\Capability\IManageConfigValues;
2019-12-11 07:51:59 +01:00
use Friendica\Core\Protocol;
use Friendica\Database\Database;
use Friendica\DI;
2019-12-11 07:51:59 +01:00
/**
* Class Stats
*
* @see https://docs.joinmastodon.org/api/entities/#stats
*/
class Stats extends BaseDataTransferObject
2019-12-11 07:51:59 +01:00
{
/** @var int */
protected $user_count = 0;
2019-12-11 07:51:59 +01:00
/** @var int */
protected $status_count = 0;
2019-12-11 07:51:59 +01:00
/** @var int */
protected $domain_count = 0;
2019-12-11 07:51:59 +01:00
public function __construct(IManageConfigValues $config, Database $database)
{
if (!empty($config->get('system', 'nodeinfo'))) {
2023-01-18 06:04:37 +01:00
$this->user_count = intval(DI::keyValue()->get('nodeinfo_total_users'));
$this->status_count = DI::keyValue()->get('nodeinfo_local_posts') + DI::keyValue()->get('nodeinfo_local_comments');
$this->domain_count = $database->count('gserver', ["`network` in (?, ?) AND NOT `failed` AND NOT `blocked`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
2019-12-11 07:51:59 +01:00
}
}
}