3 * @copyright Copyright (C) 2010-2023, 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;
25 use Friendica\App\BaseURL;
26 use Friendica\BaseDataTransferObject;
27 use Friendica\Contact\Header;
28 use Friendica\Core\Config\Capability\IManageConfigValues;
29 use Friendica\Database\Database;
31 use Friendica\Model\User;
32 use Friendica\Module\Register;
33 use Friendica\Network\HTTPException;
34 use Friendica\Object\Api\Mastodon\InstanceV2\Configuration;
39 * @see https://docs.joinmastodon.org/entities/V1_Instance/
41 class Instance extends BaseDataTransferObject
43 /** @var string (URL) */
48 protected $short_description;
50 protected $description;
59 /** @var string|null This is meant as a server banner, default Mastodon "thumbnail" is 1600×620px */
60 protected $thumbnail = null;
64 protected $max_toot_chars;
66 protected $registrations;
68 protected $approval_required;
70 protected $invites_enabled;
71 /** @var Account|null */
72 /** @var Configuration */
73 protected $configuration;
74 protected $contact_account = null;
76 protected $rules = [];
79 * @param IManageConfigValues $config
80 * @param BaseURL $baseUrl
81 * @param Database $database
83 * @throws HTTPException\InternalServerErrorException
84 * @throws HTTPException\NotFoundException
85 * @throws \ImagickException
87 public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, array $rules = [], Configuration $configuration)
89 $register_policy = intval($config->get('config', 'register_policy'));
91 $this->uri = $baseUrl->getHost();
92 $this->title = $config->get('config', 'sitename');
93 $this->short_description = $this->description = $config->get('config', 'info');
94 $this->email = implode(',', User::getAdminEmailList());
95 $this->version = '2.8.0 (compatible; Friendica ' . App::VERSION . ')';
96 $this->urls = ['streaming_api' => '']; // Not supported
97 $this->stats = new Stats($config, $database);
98 $this->thumbnail = $baseUrl . (new Header($config))->getMastodonBannerPath();
99 $this->languages = [$config->get('system', 'language')];
100 $this->max_toot_chars = (int)$config->get('config', 'api_import_size', $config->get('config', 'max_import_size'));
101 $this->registrations = ($register_policy != Register::CLOSED);
102 $this->approval_required = ($register_policy == Register::APPROVE);
103 $this->invites_enabled = false;
104 $this->configuration = $configuration;
105 $this->contact_account = [];
106 $this->rules = $rules;
108 $administrator = User::getFirstAdmin(['nickname']);
109 if ($administrator) {
110 $adminContact = $database->selectFirst('contact', ['uri-id'], ['nick' => $administrator['nickname'], 'self' => true]);
111 $this->contact_account = DI::mstdnAccount()->createFromUriId($adminContact['uri-id']);