3 * @copyright Copyright (C) 2010-2021, the Friendica project
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\BaseDataTransferObject;
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 BaseDataTransferObject
37 /** @var string (URL) */
42 protected $short_description;
44 protected $description;
53 /** @var string|null */
54 protected $thumbnail = null;
58 protected $max_toot_chars;
60 protected $registrations;
62 protected $approval_required;
64 protected $invites_enabled;
65 /** @var Account|null */
66 protected $contact_account = null;
68 protected $rules = [];
71 * Creates an instance record
74 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
75 * @throws \ImagickException
77 public static function get()
79 $register_policy = intval(DI::config()->get('config', 'register_policy'));
81 $baseUrl = DI::baseUrl();
83 $instance = new Instance();
84 $instance->uri = $baseUrl->get();
85 $instance->title = DI::config()->get('config', 'sitename');
86 $instance->short_description = $instance->description = DI::config()->get('config', 'info');
87 $instance->email = DI::config()->get('config', 'admin_email');
88 $instance->version = FRIENDICA_VERSION;
89 $instance->urls = null; // Not supported
90 $instance->stats = Stats::get();
91 $instance->thumbnail = $baseUrl->get() . (DI::config()->get('system', 'shortcut_icon') ?? 'images/friendica-32.png');
92 $instance->languages = [DI::config()->get('system', 'language')];
93 $instance->max_toot_chars = (int)DI::config()->get('config', 'api_import_size', DI::config()->get('config', 'max_import_size'));
94 $instance->registrations = ($register_policy != Register::CLOSED);
95 $instance->approval_required = ($register_policy == Register::APPROVE);
96 $instance->invites_enabled = false;
97 $instance->contact_account = [];
99 if (!empty(DI::config()->get('config', 'admin_email'))) {
100 $adminList = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
101 $administrator = User::getByEmail($adminList[0], ['nickname']);
102 if (!empty($administrator)) {
103 $adminContact = DBA::selectFirst('contact', ['id'], ['nick' => $administrator['nickname'], 'self' => true]);
104 $instance->contact_account = DI::mstdnAccount()->createFromContactId($adminContact['id']);