namespace Friendica\Module\Api\Mastodon;
+use Exception;
use Friendica\App;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\Database;
+use Friendica\DI;
+use Friendica\Model\User;
use Friendica\Module\Api\ApiResponse;
use Friendica\Module\BaseApi;
+use Friendica\Module\Register;
use Friendica\Object\Api\Mastodon\InstanceV2 as InstanceEntity;
+use Friendica\Util\Images;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \Friendica\Network\HTTPException\NotFoundException
* @throws \ImagickException
+ * @throws Exception
*/
protected function rawContent(array $request = [])
{
- System::jsonExit(new InstanceEntity($this->config, $this->baseUrl, $this->database, System::getRules()));
+ $domain = $this->baseUrl->getHostname();
+ $title = $this->config->get('config', 'sitename');
+ $version = '2.8.0 (compatible; Friendica ' . App::VERSION . ')';
+ $description = $this->config->get('config', 'info');
+ $usage = $this->buildUsageInfo();
+ $thumbnail = new InstanceEntity\Thumbnail($this->baseUrl->get() . 'images/friendica-banner.jpg');
+ $languages = [$this->config->get('system', 'language')];
+ $configuration = $this->buildConfigurationInfo();
+ $registration = $this->buildRegistrationsInfo();
+ $contact = $this->buildContactInfo();
+ $friendica_extensions = $this->buildFriendicaExtensionInfo();
+ $rules = System::getRules();
+ System::jsonExit(new InstanceEntity(
+ $domain,
+ $title,
+ $version,
+ $description,
+ $usage,
+ $thumbnail,
+ $languages,
+ $configuration,
+ $registration,
+ $contact,
+ $friendica_extensions,
+ $rules
+ ));
+ }
+
+ private function buildConfigurationInfo():InstanceEntity\Configuration
+ {
+ $statuses_config = new InstanceEntity\StatusesConfig((int)$this->config->get(
+ 'config',
+ 'api_import_size',
+ $this->config->get('config', 'max_import_size')
+ ));
+
+ return new InstanceEntity\Configuration(
+ $statuses_config,
+ new InstanceEntity\MediaAttachmentsConfig(Images::supportedTypes()),
+ $this->config->get('system', 'maximagesize')
+ );
+ }
+
+ private function buildContactInfo():InstanceEntity\Contact
+ {
+ $email = implode(',', User::getAdminEmailList());
+ $administrator = User::getFirstAdmin();
+ $account = null;
+
+ if ($administrator) {
+ $adminContact = $this->database->selectFirst(
+ 'contact',
+ ['uri-id'],
+ ['nick' => $administrator['nickname'], 'self' => true]
+ );
+ $account = DI::mstdnAccount()->createFromUriId($adminContact['uri-id']);
+ }
+
+ return new InstanceEntity\Contact($email, $account);
+ }
+
+ private function buildFriendicaExtensionInfo():InstanceEntity\FriendicaExtensions
+ {
+ return new InstanceEntity\FriendicaExtensions(
+ App::VERSION,
+ App::CODENAME,
+ $this->config->get('system', 'build')
+ );
+ }
+
+ private function buildRegistrationsInfo():InstanceEntity\Registrations
+ {
+ $register_policy = intval($this->config->get('config', 'register_policy'));
+ $enabled = ($register_policy != Register::CLOSED);
+ $approval_required = ($register_policy == Register::APPROVE);
+
+ return new InstanceEntity\Registrations($enabled, $approval_required);
+ }
+
+ private function buildUsageInfo():InstanceEntity\Usage
+ {
+ if (!empty($this->config->get('system', 'nodeinfo'))) {
+ $active_monthly = intval(DI::keyValue()->get('nodeinfo_active_users_monthly'));
+ } else {
+ $active_monthly = 0;
+ }
+
+ return new InstanceEntity\Usage(new InstanceEntity\UserStats($active_monthly));
}
}
namespace Friendica\Object\Api\Mastodon;
-use Friendica\App;
-use Friendica\App\BaseURL;
use Friendica\BaseDataTransferObject;
-use Friendica\Core\Config\Capability\IManageConfigValues;
-use Friendica\Database\Database;
-use Friendica\Network\HTTPException;
use Friendica\Object\Api\Mastodon\InstanceV2\Configuration;
use Friendica\Object\Api\Mastodon\InstanceV2\Contact;
use Friendica\Object\Api\Mastodon\InstanceV2\FriendicaExtensions;
protected $friendica;
/**
- * @param IManageConfigValues $config
- * @param BaseURL $baseUrl
- * @param Database $database
- * @param array $rules
- * @throws HTTPException\InternalServerErrorException
- * @throws HTTPException\NotFoundException
- * @throws \ImagickException
+ * @param string $domain
+ * @param string $title
+ * @param $version
+ * @param string $description
+ * @param Usage $usage
+ * @param Thumbnail $thumbnail
+ * @param array $languages
+ * @param Configuration $configuration
+ * @param Registrations $registrations
+ * @param Contact $contact
+ * @param FriendicaExtensions $friendica_extensions
+ * @param array $rules
*/
- public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, array $rules = [])
- {
- $this->domain = $baseUrl->getHostname();
- $this->title = $config->get('config', 'sitename');
- $this->version = '2.8.0 (compatible; Friendica ' . App::VERSION . ')';
- $this->source_url = null; //not supported yet
- $this->description = $config->get('config', 'info');
- $this->usage = new Usage($config);
- $this->thumbnail = new Thumbnail($baseUrl);
- $this->languages = [$config->get('system', 'language')];
- $this->configuration = new Configuration();
- $this->registrations = new Registrations();
- $this->contact = new Contact($database);
+ public function __construct(
+ string $domain,
+ string $title,
+ string $version,
+ string $description,
+ Usage $usage,
+ Thumbnail $thumbnail,
+ array $languages,
+ Configuration $configuration,
+ Registrations $registrations,
+ Contact $contact,
+ FriendicaExtensions $friendica_extensions,
+ array $rules
+ ) {
+ $this->domain = $domain;
+ $this->title = $title;
+ $this->version = $version;
+ $this->source_url = null; //not supported yet
+ $this->description = $description;
+ $this->usage = $usage;
+ $this->thumbnail = $thumbnail;
+ $this->languages = $languages;
+ $this->configuration = $configuration;
+ $this->registrations = $registrations;
+ $this->contact = $contact;
$this->rules = $rules;
- $this->friendica = new FriendicaExtensions();
+ $this->friendica = $friendica_extensions;
}
}
namespace Friendica\Object\Api\Mastodon\InstanceV2;
use Friendica\BaseDataTransferObject;
-use Friendica\DI;
/**
* Class Configuration
{
/** @var StatusesConfig */
protected $statuses;
- /** @var MediaAttachmentsConfig */
+ /** @var MediaAttachmentsConfig */
protected $media_attachments;
/** @var int */
protected $image_size_limit;
- public function __construct()
- {
- $this->statuses = new StatusesConfig();
- $this->media_attachments = new MediaAttachmentsConfig();
- $this->image_size_limit = DI::config()->get('system', 'maximagesize');
+ /**
+ * @param StatusesConfig $statuses
+ * @param MediaAttachmentsConfig $media_attachments
+ * @param int $image_size_limit
+ */
+ public function __construct(
+ StatusesConfig $statuses,
+ MediaAttachmentsConfig $media_attachments,
+ int $image_size_limit
+ ) {
+ $this->statuses = $statuses;
+ $this->media_attachments = $media_attachments;
+ $this->image_size_limit = $image_size_limit;
}
}
namespace Friendica\Object\Api\Mastodon\InstanceV2;
use Friendica\BaseDataTransferObject;
-use Friendica\Database\Database;
-use Friendica\DI;
-use Friendica\Model\User;
use Friendica\Object\Api\Mastodon\Account;
/**
{
/** @var string */
protected $email;
- /** @var Account */
+ /** @var Account|null */
protected $account = null;
- public function __construct(Database $database)
+ /**
+ * @param string $email
+ * @param Account $account
+ */
+ public function __construct(string $email, Account $account)
{
- $this->email = implode(',', User::getAdminEmailList());
- $administrator = User::getFirstAdmin();
- if ($administrator) {
- $adminContact = $database->selectFirst(
- 'contact',
- ['uri-id'],
- ['nick' => $administrator['nickname'], 'self' => true]
- );
- $this->account = DI::mstdnAccount()->createFromUriId($adminContact['uri-id']);
- }
+ $this->email = $email;
+ $this->account = $account;
}
}
namespace Friendica\Object\Api\Mastodon\InstanceV2;
-use Friendica\App;
use Friendica\BaseDataTransferObject;
-use Friendica\DI;
/**
* Class FriendicaExtensions
/** @var int */
protected $db_version;
- public function __construct()
+ /**
+ * @param string $version
+ * @param string $codename
+ * @param int $db_version
+ */
+ public function __construct(string $version, string $codename, int $db_version)
{
- $this->version = App::VERSION;
- $this->codename = App::CODENAME;
- $this->db_version = DI::config()->get('system', 'build');
+ $this->version = $version;
+ $this->codename = $codename;
+ $this->db_version = $db_version;
}
}
namespace Friendica\Object\Api\Mastodon\InstanceV2;
use Friendica\BaseDataTransferObject;
-use Friendica\Util\Images;
/**
* Class MediaAttachmentsConfig
{
/** @var string[] */
protected $supported_mime_types;
- public function __construct()
+
+ /**
+ * @param array $supported_mime_types
+ */
+ public function __construct(array $supported_mime_types)
{
- $this->supported_mime_types = Images::supportedTypes();
+ $this->supported_mime_types = $supported_mime_types;
}
}
namespace Friendica\Object\Api\Mastodon\InstanceV2;
use Friendica\BaseDataTransferObject;
-use Friendica\DI;
-use Friendica\Module\Register;
/**
* Class Registrations
/** @var bool */
protected $approval_required;
- public function __construct()
+ /**
+ * @param bool $enabled
+ * @param bool $approval_required
+ */
+ public function __construct(bool $enabled, bool $approval_required)
{
- $config = DI::config();
- $register_policy = intval($config->get('config', 'register_policy'));
- $this->enabled = ($register_policy != Register::CLOSED);
- $this->approval_required = ($register_policy == Register::APPROVE);
+ $this->enabled = $enabled;
+ $this->approval_required = $approval_required;
}
}
namespace Friendica\Object\Api\Mastodon\InstanceV2;
use Friendica\BaseDataTransferObject;
-use Friendica\DI;
/**
* Class StatusConfig
*/
class StatusesConfig extends BaseDataTransferObject
{
- /** @var int */
+ /** @var int */
protected $max_characters = 0;
- public function __construct()
+ /**
+ * @param int $max_characters
+ */
+ public function __construct(int $max_characters)
{
- $config = DI::config();
- $this->max_characters = (int)$config->get(
- 'config',
- 'api_import_size',
- $config->get('config', 'max_import_size')
- );
+ $this->max_characters = $max_characters;
}
}
namespace Friendica\Object\Api\Mastodon\InstanceV2;
-use Friendica\App\BaseURL;
use Friendica\BaseDataTransferObject;
/**
/** @var string (URL) */
protected $url;
- public function __construct(BaseURL $baseUrl)
+ /**
+ * @param string $url
+ */
+ public function __construct(string $url)
{
- $this->url = $baseUrl->get() . 'images/friendica-banner.jpg';
+ $this->url = $url;
}
}
/** @var UserStats */
protected $users;
- public function __construct()
+ /**
+ * @param UserStats $users
+ */
+ public function __construct(UserStats $users)
{
- $this->users = new UserStats();
+ $this->users = $users;
}
}
namespace Friendica\Object\Api\Mastodon\InstanceV2;
use Friendica\BaseDataTransferObject;
-use Friendica\DI;
/**
* Class UserStats
/** @var int */
protected $active_monthly = 0;
- public function __construct()
+ /**
+ * @param $active_monthly
+ */
+ public function __construct($active_monthly)
{
- $config = DI::config();
- if (!empty($config->get('system', 'nodeinfo'))) {
- $this->active_monthly = intval(DI::keyValue()->get('nodeinfo_active_users_monthly'));
- }
+ $this->active_monthly = $active_monthly;
}
}