2019-12-11 01:51:59 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Api\Mastodon;
|
|
|
|
|
2019-12-11 01:54:31 -05:00
|
|
|
use Friendica\App;
|
2019-12-11 01:51:59 -05:00
|
|
|
use Friendica\Core\Config;
|
|
|
|
use Friendica\Database\DBA;
|
2019-12-29 21:50:15 -05:00
|
|
|
use Friendica\DI;
|
2019-12-18 23:11:31 -05:00
|
|
|
use Friendica\Model\APContact;
|
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
|
|
|
|
*/
|
|
|
|
class Instance
|
|
|
|
{
|
|
|
|
/** @var string (URL) */
|
|
|
|
var $uri;
|
|
|
|
/** @var string */
|
|
|
|
var $title;
|
|
|
|
/** @var string */
|
|
|
|
var $description;
|
|
|
|
/** @var string */
|
|
|
|
var $email;
|
|
|
|
/** @var string */
|
|
|
|
var $version;
|
|
|
|
/** @var array */
|
|
|
|
var $urls;
|
|
|
|
/** @var Stats */
|
|
|
|
var $stats;
|
|
|
|
/** @var string */
|
|
|
|
var $thumbnail;
|
|
|
|
/** @var array */
|
|
|
|
var $languages;
|
|
|
|
/** @var int */
|
|
|
|
var $max_toot_chars;
|
|
|
|
/** @var bool */
|
|
|
|
var $registrations;
|
|
|
|
/** @var bool */
|
|
|
|
var $approval_required;
|
|
|
|
/** @var Account|null */
|
|
|
|
var $contact_account;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an instance record
|
|
|
|
*
|
2019-12-11 01:54:31 -05:00
|
|
|
* @param App $app
|
|
|
|
*
|
2019-12-11 01:51:59 -05:00
|
|
|
* @return Instance
|
|
|
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
|
|
|
*/
|
2019-12-29 21:50:15 -05:00
|
|
|
public static function get()
|
|
|
|
{
|
2019-12-11 01:51:59 -05:00
|
|
|
$register_policy = intval(Config::get('config', 'register_policy'));
|
|
|
|
|
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();
|
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();
|
2019-12-25 05:41:35 -05:00
|
|
|
$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', [], ['nick' => $administrator['nickname'], 'self' => true]);
|
2019-12-18 23:11:31 -05:00
|
|
|
$apcontact = APContact::getByURL($adminContact['url'], false);
|
2019-12-25 05:58:54 -05:00
|
|
|
$instance->contact_account = Account::create($baseUrl, $adminContact, $apcontact);
|
2019-12-11 01:51:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
}
|