friendica/src/Object/Api/Mastodon/Instance.php

110 lines
3.7 KiB
PHP
Raw Normal View History

2019-12-11 07:51:59 +01:00
<?php
2020-02-09 15:45:36 +01:00
/**
2023-01-01 15:36:24 +01:00
* @copyright Copyright (C) 2010-2023, the Friendica project
2020-02-09 15:45:36 +01:00
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
2019-12-11 07:51:59 +01:00
namespace Friendica\Object\Api\Mastodon;
2019-12-11 07:51:59 +01:00
use Friendica\App;
use Friendica\App\BaseURL;
use Friendica\BaseDataTransferObject;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\Database;
use Friendica\DI;
2019-12-11 07:51:59 +01:00
use Friendica\Model\User;
use Friendica\Module\Register;
use Friendica\Network\HTTPException;
2019-12-11 07:51:59 +01:00
/**
* Class Instance
2019-12-11 07:51:59 +01:00
*
* @see https://docs.joinmastodon.org/api/entities/#instance
*/
class Instance extends BaseDataTransferObject
2019-12-11 07:51:59 +01:00
{
/** @var string (URL) */
protected $uri;
2019-12-11 07:51:59 +01:00
/** @var string */
protected $title;
2019-12-11 07:51:59 +01:00
/** @var string */
2021-06-10 21:10:33 +02:00
protected $short_description;
/** @var string */
protected $description;
2019-12-11 07:51:59 +01:00
/** @var string */
protected $email;
2019-12-11 07:51:59 +01:00
/** @var string */
protected $version;
2019-12-11 07:51:59 +01:00
/** @var array */
protected $urls;
2019-12-11 07:51:59 +01:00
/** @var Stats */
protected $stats;
/** @var string|null This is meant as a server banner, default Mastodon "thumbnail" is 1600×620px */
protected $thumbnail = null;
2019-12-11 07:51:59 +01:00
/** @var array */
protected $languages;
2019-12-11 07:51:59 +01:00
/** @var int */
protected $max_toot_chars;
2019-12-11 07:51:59 +01:00
/** @var bool */
protected $registrations;
2019-12-11 07:51:59 +01:00
/** @var bool */
protected $approval_required;
2021-06-10 21:10:33 +02:00
/** @var bool */
protected $invites_enabled;
2019-12-11 07:51:59 +01:00
/** @var Account|null */
protected $contact_account = null;
2021-06-10 21:10:33 +02:00
/** @var array */
protected $rules = [];
2019-12-11 07:51:59 +01:00
/**
* @param IManageConfigValues $config
* @param BaseURL $baseUrl
* @param Database $database
* @param array $rules
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\NotFoundException
* @throws \ImagickException
2019-12-11 07:51:59 +01:00
*/
public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, array $rules = [])
{
$register_policy = intval($config->get('config', 'register_policy'));
2019-12-11 07:51:59 +01:00
$this->uri = $baseUrl;
$this->title = $config->get('config', 'sitename');
$this->short_description = $this->description = $config->get('config', 'info');
$this->email = implode(',', User::getAdminEmailList());
$this->version = '2.8.0 (compatible; Friendica ' . App::VERSION . ')';
$this->urls = null; // Not supported
$this->stats = new Stats($config, $database);
$this->thumbnail = $baseUrl . 'images/friendica-banner.jpg';
$this->languages = [$config->get('system', 'language')];
$this->max_toot_chars = (int)$config->get('config', 'api_import_size', $config->get('config', 'max_import_size'));
$this->registrations = ($register_policy != Register::CLOSED);
$this->approval_required = ($register_policy == Register::APPROVE);
$this->invites_enabled = false;
$this->contact_account = [];
$this->rules = $rules;
$administrator = User::getFirstAdmin(['nickname']);
if ($administrator) {
$adminContact = $database->selectFirst('contact', ['uri-id'], ['nick' => $administrator['nickname'], 'self' => true]);
$this->contact_account = DI::mstdnAccount()->createFromUriId($adminContact['uri-id']);
2019-12-11 07:51:59 +01:00
}
}
}