2019-12-11 06:51:59 +00:00
|
|
|
<?php
|
|
|
|
|
2020-01-05 22:29:54 +00:00
|
|
|
namespace Friendica\Api\Entity\Mastodon;
|
2019-12-11 06:51:59 +00:00
|
|
|
|
2020-01-05 22:29:54 +00:00
|
|
|
use Friendica\Api\BaseEntity;
|
2019-12-11 06:51:59 +00:00
|
|
|
use Friendica\Core\Config;
|
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Database\DBA;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Stats
|
|
|
|
*
|
|
|
|
* @see https://docs.joinmastodon.org/api/entities/#stats
|
|
|
|
*/
|
2020-01-05 22:29:54 +00:00
|
|
|
class Stats extends BaseEntity
|
2019-12-11 06:51:59 +00:00
|
|
|
{
|
|
|
|
/** @var int */
|
2020-01-05 22:29:54 +00:00
|
|
|
protected $user_count = 0;
|
2019-12-11 06:51:59 +00:00
|
|
|
/** @var int */
|
2020-01-05 22:29:54 +00:00
|
|
|
protected $status_count = 0;
|
2019-12-11 06:51:59 +00:00
|
|
|
/** @var int */
|
2020-01-05 22:29:54 +00:00
|
|
|
protected $domain_count = 0;
|
2019-12-11 06:51:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a stats record
|
|
|
|
*
|
|
|
|
* @return Stats
|
|
|
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
|
|
|
*/
|
|
|
|
public static function get() {
|
|
|
|
$stats = new Stats();
|
|
|
|
if (!empty(Config::get('system', 'nodeinfo'))) {
|
|
|
|
$stats->user_count = intval(Config::get('nodeinfo', 'total_users'));
|
|
|
|
$stats->status_count = Config::get('nodeinfo', 'local_posts') + Config::get('nodeinfo', 'local_comments');
|
|
|
|
$stats->domain_count = DBA::count('gserver', ["`network` in (?, ?) AND `last_contact` >= `last_failure`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
|
|
|
|
}
|
|
|
|
return $stats;
|
|
|
|
}
|
|
|
|
}
|