Commit 11c916fe authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat(themes): set different default banner per theme

parent e4e7e000
Pipeline #1212 passed with stages
in 8 minutes and 15 seconds
<?php
declare(strict_types=1);
/**
* @copyright 2022 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace Config;
use Modules\Fediverse\Config\Fediverse as FediverseBaseConfig;
class Fediverse extends FediverseBaseConfig
{
public function __construct()
{
parent::__construct();
$defaultBanner = config('Images')
->podcastBannerDefaultPaths[service('settings')->get('App.theme')] ?? config(
'Images'
)->podcastBannerDefaultPaths['default'];
['dirname' => $dirname, 'extension' => $extension, 'filename' => $filename] = pathinfo(
$defaultBanner['path']
);
$defaultBannerPath = $filename;
if ($dirname !== '.') {
$defaultBannerPathList = [$dirname, $filename];
$defaultBannerPath = implode('/', $defaultBannerPathList);
}
helper('media');
$this->defaultCoverImagePath = media_path($defaultBannerPath . '_federation.' . $extension);
$this->defaultCoverImageMimetype = $defaultBanner['mimetype'];
}
}
......@@ -126,11 +126,43 @@ class Images extends BaseConfig
],
];
public string $avatarDefaultPath = 'castopod-avatar-default.jpg';
public string $avatarDefaultPath = 'castopod-avatar.jpg';
public string $avatarDefaultMimeType = 'image/jpg';
public string $podcastBannerDefaultPath = 'castopod-banner-default.jpg';
/**
* @var array<string, array<string, string>>
*/
public array $podcastBannerDefaultPaths = [
'default' => [
'path' => 'castopod-banner-pine.jpg',
'mimetype' => 'image/jpeg',
],
'pine' => [
'path' => 'castopod-banner-pine.jpg',
'mimetype' => 'image/jpeg',
],
'crimson' => [
'path' => 'castopod-banner-crimson.jpg',
'mimetype' => 'image/jpeg',
],
'amber' => [
'path' => 'castopod-banner-amber.jpg',
'mimetype' => 'image/jpeg',
],
'lake' => [
'path' => 'castopod-banner-lake.jpg',
'mimetype' => 'image/jpeg',
],
'jacaranda' => [
'path' => 'castopod-banner-jacaranda.jpg',
'mimetype' => 'image/jpeg',
],
'onyx' => [
'path' => 'castopod-banner-onyx.jpg',
'mimetype' => 'image/jpeg',
],
];
public string $podcastBannerDefaultMimeType = 'image/jpeg';
......@@ -144,6 +176,10 @@ class Images extends BaseConfig
* @var array<string, array<string, int|string>>
*/
public array $personAvatarSizes = [
'federation' => [
'width' => 400,
'height' => 400,
],
'tiny' => [
'width' => 40,
'height' => 40,
......
......@@ -42,8 +42,7 @@ class WebmanifestController extends Controller
'background' => '#F9F3F0',
],
'onyx' => [
'theme' =>
'#040406',
'theme' => '#040406',
'background' => '#F3F3F7',
],
];
......
......@@ -271,11 +271,13 @@ class Podcast extends Entity
public function getBanner(): Image
{
if ($this->banner_id === null) {
$defaultBanner = config('Images')
->podcastBannerDefaultPaths[service('settings')->get('App.theme')] ?? config(
'Images'
)->podcastBannerDefaultPaths['default'];
return new Image([
'file_path' => config('Images')
->podcastBannerDefaultPath,
'file_mimetype' => config('Images')
->podcastBannerDefaultMimeType,
'file_path' => $defaultBanner['path'],
'file_mimetype' => $defaultBanner['mimetype'],
'file_size' => 0,
'file_metadata' => [
'sizes' => config('Images')
......
......@@ -12,6 +12,7 @@ namespace Modules\Admin\Controllers;
use App\Entities\Location;
use App\Entities\Podcast;
use App\Models\ActorModel;
use App\Models\CategoryModel;
use App\Models\EpisodeModel;
use App\Models\LanguageModel;
......@@ -369,6 +370,10 @@ class PodcastController extends BaseController
return redirect()->back();
}
$db = db_connect();
$db->transStart();
$mediaModel = new MediaModel();
if (! $mediaModel->deleteMedia($this->podcast->banner)) {
return redirect()
......@@ -377,6 +382,18 @@ class PodcastController extends BaseController
->with('errors', $mediaModel->errors());
}
// remove banner url from actor
$actor = (new ActorModel())->getActorById($this->podcast->actor_id);
if ($actor !== null) {
$actor->cover_image_url = null;
$actor->cover_image_mimetype = null;
(new ActorModel())->update($actor->id, $actor);
}
$db->transComplete();
return redirect()->back();
}
......
......@@ -30,11 +30,11 @@ class Fediverse extends BaseConfig
* Default avatar and cover images
* --------------------------------------------------------------------
*/
public string $defaultAvatarImagePath = 'media/castopod-avatar-default_thumbnail.jpg';
public string $defaultAvatarImagePath = 'media/castopod-avatar_fediveration.jpg';
public string $defaultAvatarImageMimetype = 'image/jpeg';
public string $defaultCoverImagePath = 'media/castopod-cover-default.jpg';
public string $defaultCoverImagePath = 'media/castopod-banner-pine_fediveration.jpg';
public string $defaultCoverImageMimetype = 'image/jpeg';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment