3 * @copyright Copyright (C) 2010-2022, 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\App\BaseURL;
25 use Friendica\BaseDataTransferObject;
26 use Friendica\Core\Config\Capability\IManageConfigValues;
27 use Friendica\Database\Database;
28 use Friendica\Database\DBA;
30 use Friendica\Model\User;
31 use Friendica\Module\Register;
32 use Friendica\Network\HTTPException;
37 * @see https://docs.joinmastodon.org/api/entities/#instance
39 class Instance extends BaseDataTransferObject
41 /** @var string (URL) */
46 protected $short_description;
48 protected $description;
57 /** @var string|null */
58 protected $thumbnail = null;
62 protected $max_toot_chars;
64 protected $registrations;
66 protected $approval_required;
68 protected $invites_enabled;
69 /** @var Account|null */
70 protected $contact_account = null;
72 protected $rules = [];
75 * @param IManageConfigValues $config
76 * @param BaseURL $baseUrl
77 * @param Database $database
78 * @throws HTTPException\InternalServerErrorException
79 * @throws HTTPException\NotFoundException
80 * @throws \ImagickException
82 public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database)
84 $register_policy = intval($config->get('config', 'register_policy'));
86 $this->uri = $baseUrl->get();
87 $this->title = $config->get('config', 'sitename');
88 $this->short_description = $this->description = $config->get('config', 'info');
89 $this->email = $config->get('config', 'admin_email');
90 $this->version = '2.8.0 (compatible; Friendica ' . FRIENDICA_VERSION . ')';
91 $this->urls = null; // Not supported
92 $this->stats = new Stats($config, $database);
93 $this->thumbnail = $baseUrl->get() . ($config->get('system', 'shortcut_icon') ?? 'images/friendica-32.png');
94 $this->languages = [$config->get('system', 'language')];
95 $this->max_toot_chars = (int)$config->get('config', 'api_import_size', $config->get('config', 'max_import_size'));
96 $this->registrations = ($register_policy != Register::CLOSED);
97 $this->approval_required = ($register_policy == Register::APPROVE);
98 $this->invites_enabled = false;
99 $this->contact_account = [];
101 if (!empty($config->get('config', 'admin_email'))) {
102 $adminList = explode(',', str_replace(' ', '', $config->get('config', 'admin_email')));
103 $administrator = User::getByEmail($adminList[0], ['nickname']);
104 if (!empty($administrator)) {
105 $adminContact = $database->selectFirst('contact', ['id'], ['nick' => $administrator['nickname'], 'self' => true]);
106 $this->contact_account = DI::mstdnAccount()->createFromContactId($adminContact['id']);