2019-12-11 01:51:59 -05:00
|
|
|
<?php
|
|
|
|
|
2020-01-27 20:01:32 -05:00
|
|
|
namespace Friendica\Object\Api\Mastodon;
|
2019-12-11 01:51:59 -05:00
|
|
|
|
2020-01-27 20:01:32 -05:00
|
|
|
use Friendica\BaseEntity;
|
2019-12-11 01:51:59 -05:00
|
|
|
use Friendica\Database\DBA;
|
2019-12-29 21:50:15 -05:00
|
|
|
use Friendica\DI;
|
2019-12-11 01:51:59 -05:00
|
|
|
use Friendica\Model\User;
|
|
|
|
use Friendica\Module\Register;
|
|
|
|
|
|
|
|
/**
|
2019-12-18 23:11:31 -05:00
|
|
|
* Class Instance
|
2019-12-11 01:51:59 -05:00
|
|
|
*
|
|
|
|
* @see https://docs.joinmastodon.org/api/entities/#instance
|
|
|
|
*/
|
2020-01-05 17:29:54 -05:00
|
|
|
class Instance extends BaseEntity
|
2019-12-11 01:51:59 -05:00
|
|
|
{
|
|
|
|
/** @var string (URL) */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $uri;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var string */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $title;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var string */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $description;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var string */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $email;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var string */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $version;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var array */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $urls;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var Stats */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $stats;
|
|
|
|
/** @var string|null */
|
|
|
|
protected $thumbnail = null;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var array */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $languages;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var int */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $max_toot_chars;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var bool */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $registrations;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var bool */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $approval_required;
|
2019-12-11 01:51:59 -05:00
|
|
|
/** @var Account|null */
|
2020-01-05 17:29:54 -05:00
|
|
|
protected $contact_account = null;
|
2019-12-11 01:51:59 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an instance record
|
|
|
|
*
|
|
|
|
* @return Instance
|
|
|
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
2020-01-05 17:29:54 -05:00
|
|
|
* @throws \ImagickException
|
2019-12-11 01:51:59 -05:00
|
|
|
*/
|
2019-12-29 21:50:15 -05:00
|
|
|
public static function get()
|
|
|
|
{
|
2020-01-19 15:21:13 -05:00
|
|
|
$register_policy = intval(DI::config()->get('config', 'register_policy'));
|
2019-12-11 01:51:59 -05:00
|
|
|
|
2019-12-25 05:41:35 -05:00
|
|
|
$baseUrl = DI::baseUrl();
|
|
|
|
|
2019-12-11 01:51:59 -05:00
|
|
|
$instance = new Instance();
|
2019-12-25 05:41:35 -05:00
|
|
|
$instance->uri = $baseUrl->get();
|
2020-01-19 15:21:13 -05:00
|
|
|
$instance->title = DI::config()->get('config', 'sitename');
|
|
|
|
$instance->description = DI::config()->get('config', 'info');
|
|
|
|
$instance->email = DI::config()->get('config', 'admin_email');
|
2019-12-11 01:51:59 -05:00
|
|
|
$instance->version = FRIENDICA_VERSION;
|
|
|
|
$instance->urls = []; // Not supported
|
|
|
|
$instance->stats = Stats::get();
|
2020-01-19 15:21:13 -05:00
|
|
|
$instance->thumbnail = $baseUrl->get() . (DI::config()->get('system', 'shortcut_icon') ?? 'images/friendica-32.png');
|
|
|
|
$instance->languages = [DI::config()->get('system', 'language')];
|
|
|
|
$instance->max_toot_chars = (int)DI::config()->get('config', 'api_import_size', DI::config()->get('config', 'max_import_size'));
|
2019-12-11 01:51:59 -05:00
|
|
|
$instance->registrations = ($register_policy != Register::CLOSED);
|
|
|
|
$instance->approval_required = ($register_policy == Register::APPROVE);
|
|
|
|
$instance->contact_account = [];
|
|
|
|
|
2020-01-19 15:21:13 -05:00
|
|
|
if (!empty(DI::config()->get('config', 'admin_email'))) {
|
|
|
|
$adminList = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
|
2019-12-11 01:51:59 -05:00
|
|
|
$administrator = User::getByEmail($adminList[0], ['nickname']);
|
|
|
|
if (!empty($administrator)) {
|
2020-01-05 17:29:54 -05:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|