]> git.mxchange.org Git - friendica.git/blobdiff - 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
index 63c8b2824f2685dbbdaa63fe5a8bc79f79c65c86..a7549afd8489cd055cf9cbe59fe994403c85cfd1 100644 (file)
@@ -1,25 +1,51 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @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/>.
+ *
+ */
 
 namespace Friendica\Object\Api\Mastodon;
 
-use Friendica\BaseEntity;
-use Friendica\Database\DBA;
+use Friendica\App;
+use Friendica\App\BaseURL;
+use Friendica\BaseDataTransferObject;
+use Friendica\Contact\Header;
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Database\Database;
 use Friendica\DI;
 use Friendica\Model\User;
 use Friendica\Module\Register;
+use Friendica\Network\HTTPException;
 
 /**
  * Class Instance
  *
- * @see https://docs.joinmastodon.org/api/entities/#instance
+ * @see https://docs.joinmastodon.org/entities/V1_Instance/
  */
-class Instance extends BaseEntity
+class Instance extends BaseDataTransferObject
 {
        /** @var string (URL) */
        protected $uri;
        /** @var string */
        protected $title;
        /** @var string */
+       protected $short_description;
+       /** @var string */
        protected $description;
        /** @var string */
        protected $email;
@@ -29,7 +55,7 @@ class Instance extends BaseEntity
        protected $urls;
        /** @var Stats */
        protected $stats;
-       /** @var string|null */
+       /** @var string|null This is meant as a server banner, default Mastodon "thumbnail" is 1600×620px */
        protected $thumbnail = null;
        /** @var array */
        protected $languages;
@@ -39,46 +65,46 @@ class Instance extends BaseEntity
        protected $registrations;
        /** @var bool */
        protected $approval_required;
+       /** @var bool */
+       protected $invites_enabled;
        /** @var Account|null */
        protected $contact_account = null;
+       /** @var array */
+       protected $rules = [];
 
        /**
-        * Creates an instance record
-        *
-        * @return Instance
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @param IManageConfigValues $config
+        * @param BaseURL             $baseUrl
+        * @param Database            $database
+        * @param array               $rules
+        * @throws HTTPException\InternalServerErrorException
+        * @throws HTTPException\NotFoundException
         * @throws \ImagickException
         */
-       public static function get()
+       public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, array $rules = [])
        {
-               $register_policy = intval(DI::config()->get('config', 'register_policy'));
-
-               $baseUrl = DI::baseUrl();
+               $register_policy = intval($config->get('config', 'register_policy'));
 
-               $instance = new Instance();
-               $instance->uri = $baseUrl->get();
-               $instance->title = DI::config()->get('config', 'sitename');
-               $instance->description = DI::config()->get('config', 'info');
-               $instance->email = DI::config()->get('config', 'admin_email');
-               $instance->version = FRIENDICA_VERSION;
-               $instance->urls = []; // Not supported
-               $instance->stats = Stats::get();
-               $instance->thumbnail = $baseUrl->get() . (DI::config()->get('system', 'shortcut_icon') ?? 'images/friendica-32.png');
-               $instance->languages = [DI::config()->get('system', 'language')];
-               $instance->max_toot_chars = (int)DI::config()->get('config', 'api_import_size', DI::config()->get('config', 'max_import_size'));
-               $instance->registrations = ($register_policy != Register::CLOSED);
-               $instance->approval_required = ($register_policy == Register::APPROVE);
-               $instance->contact_account = [];
+               $this->uri               = $baseUrl->getHost();
+               $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              = ['streaming_api' => '']; // Not supported
+               $this->stats             = new Stats($config, $database);
+               $this->thumbnail         = $baseUrl . (new Header($config))->getMastodonBannerPath();
+               $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;
 
-               if (!empty(DI::config()->get('config', 'admin_email'))) {
-                       $adminList = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
-                       $administrator = User::getByEmail($adminList[0], ['nickname']);
-                       if (!empty($administrator)) {
-                               $adminContact = DBA::selectFirst('contact', ['id'], ['nick' => $administrator['nickname'], 'self' => true]);
-                               $instance->contact_account = DI::mstdnAccount()->createFromContactId($adminContact['id']);
-                       }
+               $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']);
                }
-
-               return $instance;
        }
 }