]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Mastodon/Instance.php
Replace remaining references to default banner image by api.mastodon_banner configura...
[friendica.git] / src / Object / Api / Mastodon / Instance.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Object\Api\Mastodon;
23
24 use Friendica\App;
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;
30 use Friendica\DI;
31 use Friendica\Model\User;
32 use Friendica\Module\Register;
33 use Friendica\Network\HTTPException;
34
35 /**
36  * Class Instance
37  *
38  * @see https://docs.joinmastodon.org/entities/V1_Instance/
39  */
40 class Instance extends BaseDataTransferObject
41 {
42         /** @var string (URL) */
43         protected $uri;
44         /** @var string */
45         protected $title;
46         /** @var string */
47         protected $short_description;
48         /** @var string */
49         protected $description;
50         /** @var string */
51         protected $email;
52         /** @var string */
53         protected $version;
54         /** @var array */
55         protected $urls;
56         /** @var Stats */
57         protected $stats;
58         /** @var string|null This is meant as a server banner, default Mastodon "thumbnail" is 1600×620px */
59         protected $thumbnail = null;
60         /** @var array */
61         protected $languages;
62         /** @var int */
63         protected $max_toot_chars;
64         /** @var bool */
65         protected $registrations;
66         /** @var bool */
67         protected $approval_required;
68         /** @var bool */
69         protected $invites_enabled;
70         /** @var Account|null */
71         protected $contact_account = null;
72         /** @var array */
73         protected $rules = [];
74
75         /**
76          * @param IManageConfigValues $config
77          * @param BaseURL             $baseUrl
78          * @param Database            $database
79          * @param array               $rules
80          * @throws HTTPException\InternalServerErrorException
81          * @throws HTTPException\NotFoundException
82          * @throws \ImagickException
83          */
84         public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, array $rules = [])
85         {
86                 $register_policy = intval($config->get('config', 'register_policy'));
87
88                 $this->uri               = $baseUrl->getHost();
89                 $this->title             = $config->get('config', 'sitename');
90                 $this->short_description = $this->description = $config->get('config', 'info');
91                 $this->email             = implode(',', User::getAdminEmailList());
92                 $this->version           = '2.8.0 (compatible; Friendica ' . App::VERSION . ')';
93                 $this->urls              = ['streaming_api' => '']; // Not supported
94                 $this->stats             = new Stats($config, $database);
95                 $this->thumbnail         = $baseUrl . (new Header($config))->getMastodonBannerPath();
96                 $this->languages         = [$config->get('system', 'language')];
97                 $this->max_toot_chars    = (int)$config->get('config', 'api_import_size', $config->get('config', 'max_import_size'));
98                 $this->registrations     = ($register_policy != Register::CLOSED);
99                 $this->approval_required = ($register_policy == Register::APPROVE);
100                 $this->invites_enabled   = false;
101                 $this->contact_account   = [];
102                 $this->rules             = $rules;
103
104                 $administrator = User::getFirstAdmin(['nickname']);
105                 if ($administrator) {
106                         $adminContact = $database->selectFirst('contact', ['uri-id'], ['nick' => $administrator['nickname'], 'self' => true]);
107                         $this->contact_account = DI::mstdnAccount()->createFromUriId($adminContact['uri-id']);
108                 }
109         }
110 }