friendica/src/Api/Mastodon/Instance.php

89 lines
2.5 KiB
PHP
Raw Normal View History

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\Api\Mastodon\Account;
use Friendica\Api\Mastodon\Stats;
use Friendica\Core\Config;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\APContact;
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
{
/** @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
*/
public static function get()
{
2019-12-11 01:51:59 -05:00
$register_policy = intval(Config::get('config', 'register_policy'));
$instance = new Instance();
$instance->uri = DI::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 = DI::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]);
$apcontact = APContact::getByURL($adminContact['url'], false);
$instance->contact_account = Account::createFromContact($adminContact, $apcontact);
2019-12-11 01:51:59 -05:00
}
}
return $instance;
}
}