friendica/src/Api/Entity/Mastodon/Instance.php

86 lines
2.5 KiB
PHP
Raw Normal View History

2019-12-11 01:51:59 -05:00
<?php
namespace Friendica\Api\Entity\Mastodon;
2019-12-11 01:51:59 -05:00
use Friendica\Api\BaseEntity;
2019-12-11 01:51:59 -05:00
use Friendica\Core\Config;
use Friendica\Database\DBA;
use Friendica\DI;
2019-12-11 01:51:59 -05:00
use Friendica\Model\User;
use Friendica\Module\Register;
/**
* Class Instance
2019-12-11 01:51:59 -05:00
*
* @see https://docs.joinmastodon.org/api/entities/#instance
*/
class Instance extends BaseEntity
2019-12-11 01:51:59 -05:00
{
/** @var string (URL) */
protected $uri;
2019-12-11 01:51:59 -05:00
/** @var string */
protected $title;
2019-12-11 01:51:59 -05:00
/** @var string */
protected $description;
2019-12-11 01:51:59 -05:00
/** @var string */
protected $email;
2019-12-11 01:51:59 -05:00
/** @var string */
protected $version;
2019-12-11 01:51:59 -05:00
/** @var array */
protected $urls;
2019-12-11 01:51:59 -05:00
/** @var Stats */
protected $stats;
/** @var string|null */
protected $thumbnail = null;
2019-12-11 01:51:59 -05:00
/** @var array */
protected $languages;
2019-12-11 01:51:59 -05:00
/** @var int */
protected $max_toot_chars;
2019-12-11 01:51:59 -05:00
/** @var bool */
protected $registrations;
2019-12-11 01:51:59 -05:00
/** @var bool */
protected $approval_required;
2019-12-11 01:51:59 -05:00
/** @var Account|null */
protected $contact_account = null;
2019-12-11 01:51:59 -05:00
/**
* Creates an instance record
*
* @return Instance
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
2019-12-11 01:51:59 -05:00
*/
public static function get()
{
2019-12-11 01:51:59 -05:00
$register_policy = intval(Config::get('config', 'register_policy'));
$baseUrl = DI::baseUrl();
2019-12-11 01:51:59 -05:00
$instance = new Instance();
$instance->uri = $baseUrl->get();
2019-12-11 01:51:59 -05:00
$instance->title = Config::get('config', 'sitename');
$instance->description = Config::get('config', 'info');
$instance->email = Config::get('config', 'admin_email');
$instance->version = FRIENDICA_VERSION;
$instance->urls = []; // Not supported
$instance->stats = Stats::get();
$instance->thumbnail = $baseUrl->get() . (Config::get('system', 'shortcut_icon') ?? 'images/friendica-32.png');
2019-12-11 01:51:59 -05:00
$instance->languages = [Config::get('system', 'language')];
$instance->max_toot_chars = (int)Config::get('config', 'api_import_size', Config::get('config', 'max_import_size'));
$instance->registrations = ($register_policy != Register::CLOSED);
$instance->approval_required = ($register_policy == Register::APPROVE);
$instance->contact_account = [];
if (!empty(Config::get('config', 'admin_email'))) {
$adminList = explode(',', str_replace(' ', '', Config::get('config', 'admin_email')));
$administrator = User::getByEmail($adminList[0], ['nickname']);
if (!empty($administrator)) {
$adminContact = DBA::selectFirst('contact', ['id'], ['nick' => $administrator['nickname'], 'self' => true]);
$instance->contact_account = DI::mstdnAccount()->createFromContactId($adminContact['id']);
2019-12-11 01:51:59 -05:00
}
}
return $instance;
}
}