3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Object\Api\Mastodon;
24 use Friendica\BaseEntity;
25 use Friendica\Database\DBA;
27 use Friendica\Model\User;
28 use Friendica\Module\Register;
33 * @see https://docs.joinmastodon.org/api/entities/#instance
35 class Instance extends BaseEntity
37 /** @var string (URL) */
42 protected $description;
51 /** @var string|null */
52 protected $thumbnail = null;
56 protected $max_toot_chars;
58 protected $registrations;
60 protected $approval_required;
61 /** @var Account|null */
62 protected $contact_account = null;
65 * Creates an instance record
68 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
69 * @throws \ImagickException
71 public static function get()
73 $register_policy = intval(DI::config()->get('config', 'register_policy'));
75 $baseUrl = DI::baseUrl();
77 $instance = new Instance();
78 $instance->uri = $baseUrl->get();
79 $instance->title = DI::config()->get('config', 'sitename');
80 $instance->description = DI::config()->get('config', 'info');
81 $instance->email = DI::config()->get('config', 'admin_email');
82 $instance->version = FRIENDICA_VERSION;
83 $instance->urls = []; // Not supported
84 $instance->stats = Stats::get();
85 $instance->thumbnail = $baseUrl->get() . (DI::config()->get('system', 'shortcut_icon') ?? 'images/friendica-32.png');
86 $instance->languages = [DI::config()->get('system', 'language')];
87 $instance->max_toot_chars = (int)DI::config()->get('config', 'api_import_size', DI::config()->get('config', 'max_import_size'));
88 $instance->registrations = ($register_policy != Register::CLOSED);
89 $instance->approval_required = ($register_policy == Register::APPROVE);
90 $instance->contact_account = [];
92 if (!empty(DI::config()->get('config', 'admin_email'))) {
93 $adminList = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
94 $administrator = User::getByEmail($adminList[0], ['nickname']);
95 if (!empty($administrator)) {
96 $adminContact = DBA::selectFirst('contact', ['id'], ['nick' => $administrator['nickname'], 'self' => true]);
97 $instance->contact_account = DI::mstdnAccount()->createFromContactId($adminContact['id']);