]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Mastodon/Instance.php
Merge pull request #10362 from tobiasd/2021.06-CHANGELOG
[friendica.git] / src / Object / Api / Mastodon / Instance.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\BaseDataTransferObject;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27 use Friendica\Model\User;
28 use Friendica\Module\Register;
29
30 /**
31  * Class Instance
32  *
33  * @see https://docs.joinmastodon.org/api/entities/#instance
34  */
35 class Instance extends BaseDataTransferObject
36 {
37         /** @var string (URL) */
38         protected $uri;
39         /** @var string */
40         protected $title;
41         /** @var string */
42         protected $short_description;
43         /** @var string */
44         protected $description;
45         /** @var string */
46         protected $email;
47         /** @var string */
48         protected $version;
49         /** @var array */
50         protected $urls;
51         /** @var Stats */
52         protected $stats;
53         /** @var string|null */
54         protected $thumbnail = null;
55         /** @var array */
56         protected $languages;
57         /** @var int */
58         protected $max_toot_chars;
59         /** @var bool */
60         protected $registrations;
61         /** @var bool */
62         protected $approval_required;
63         /** @var bool */
64         protected $invites_enabled;
65         /** @var Account|null */
66         protected $contact_account = null;
67         /** @var array */
68         protected $rules = [];
69
70         /**
71          * Creates an instance record
72          *
73          * @return Instance
74          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
75          * @throws \ImagickException
76          */
77         public static function get()
78         {
79                 $register_policy = intval(DI::config()->get('config', 'register_policy'));
80
81                 $baseUrl = DI::baseUrl();
82
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 = [];
98
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']);
105                         }
106                 }
107
108                 return $instance;
109         }
110 }