diff --git a/src/Contact/Header.php b/src/Contact/Header.php new file mode 100644 index 0000000000..d5116d2907 --- /dev/null +++ b/src/Contact/Header.php @@ -0,0 +1,47 @@ +. + * + */ + +namespace Friendica\Contact; + +use Friendica\Core\Config\Capability\IManageConfigValues; + +class Header +{ + /** @var IManageConfigValues */ + private $config; + + public function __construct(IManageConfigValues $config) + { + $this->config = $config; + } + + /** + * Returns the Mastodon banner path relative to the Friendica folder. + * + * Ensures the existence of a leading slash. + * + * @return string + */ + public function getMastodonBannerPath(): string + { + return '/' . ltrim($this->config->get('api', 'mastodon_banner'), '/'); + } +} diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 23e1f2cbff..d91abe9bcd 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -22,6 +22,7 @@ namespace Friendica\Model; use Friendica\Contact\Avatar; +use Friendica\Contact\Header; use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException; use Friendica\Contact\LocalRelationship\Entity\LocalRelationship; use Friendica\Content\Conversation as ConversationContent; @@ -1899,13 +1900,7 @@ class Contact switch ($platform) { case 'friendica': case 'friendika': - /** - * Picture credits - * @author Lostinlight - * @license CC0 https://creativecommons.org/share-your-work/public-domain/cc0/ - * @link https://gitlab.com/lostinlight/per_aspera_ad_astra/-/blob/master/friendica-404/friendica-promo-bubbles.jpg - */ - $header = DI::baseUrl() . '/images/friendica-banner.jpg'; + $header = DI::baseUrl() . (new Header(DI::config()))->getMastodonBannerPath(); break; case 'diaspora': /** diff --git a/src/Module/Api/Mastodon/InstanceV2.php b/src/Module/Api/Mastodon/InstanceV2.php index 402e0ae93c..bf5cbcfb55 100644 --- a/src/Module/Api/Mastodon/InstanceV2.php +++ b/src/Module/Api/Mastodon/InstanceV2.php @@ -23,6 +23,7 @@ namespace Friendica\Module\Api\Mastodon; use Exception; use Friendica\App; +use Friendica\Contact\Header; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\L10n; use Friendica\Core\System; @@ -49,6 +50,9 @@ class InstanceV2 extends BaseApi /** @var IManageConfigValues */ private $config; + /** @var Header */ + private $contactHeader; + public function __construct( App $app, L10n $l10n, @@ -64,8 +68,9 @@ class InstanceV2 extends BaseApi ) { parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); - $this->database = $database; - $this->config = $config; + $this->database = $database; + $this->config = $config; + $this->contactHeader = new Header($config); } /** @@ -82,7 +87,7 @@ class InstanceV2 extends BaseApi $version = '2.8.0 (compatible; Friendica ' . App::VERSION . ')'; $description = $this->config->get('config', 'info'); $usage = $this->buildUsageInfo(); - $thumbnail = new InstanceEntity\Thumbnail($this->baseUrl->withPath('images/friendica-banner.jpg')); + $thumbnail = new InstanceEntity\Thumbnail($this->baseUrl . $this->contactHeader->getMastodonBannerPath()); $languages = [$this->config->get('system', 'language')]; $configuration = $this->buildConfigurationInfo(); $registration = $this->buildRegistrationsInfo(); diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 954b3f3eec..c8e0656d2d 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -22,6 +22,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\Contact\Header; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Database\DBA; @@ -482,6 +483,6 @@ class Photo extends BaseApi if (!empty($photo)) { return $photo; } - return MPhoto::createPhotoForImageData(file_get_contents(DI::basePath() . '/images/friendica-banner.jpg')); + return MPhoto::createPhotoForImageData(file_get_contents(DI::basePath() . (new Header(DI::config()))->getMastodonBannerPath())); } } diff --git a/src/Object/Api/Mastodon/Instance.php b/src/Object/Api/Mastodon/Instance.php index 2012182519..a7549afd84 100644 --- a/src/Object/Api/Mastodon/Instance.php +++ b/src/Object/Api/Mastodon/Instance.php @@ -24,6 +24,7 @@ namespace Friendica\Object\Api\Mastodon; 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; @@ -91,7 +92,7 @@ class Instance extends BaseDataTransferObject $this->version = '2.8.0 (compatible; Friendica ' . App::VERSION . ')'; $this->urls = ['streaming_api' => '']; // Not supported $this->stats = new Stats($config, $database); - $this->thumbnail = $baseUrl . $config->get('api', 'mastodon_banner'); + $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); diff --git a/static/defaults.config.php b/static/defaults.config.php index 4562da8987..33ed8211b4 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -783,7 +783,12 @@ return [ ], 'api' => [ // mastodon_banner (String) - // Banner for Mastodon API + // Default banner image for Mastodon API, must be a relative path from the base Friendica folder + // + // Default picture credits: + // Author: Lostinlight + // License: CC0 https://creativecommons.org/share-your-work/public-domain/cc0/ + // Link to original work: https://gitlab.com/lostinlight/per_aspera_ad_astra/-/blob/master/friendica-404/friendica-promo-bubbles.jpg 'mastodon_banner' => '/images/friendica-banner.jpg', ], 'blocklist' => [