You've already forked Atomcms-edit
67 lines
2.9 KiB
PHP
Executable File
67 lines
2.9 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Radio;
|
|
|
|
use App\Enums\RadioSettings;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Miscellaneous\WebsiteSetting;
|
|
use App\Services\Community\RadioStreamService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\View\View;
|
|
|
|
class EmbedController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly RadioStreamService $streamService,
|
|
) {}
|
|
|
|
public function show(Request $request): View
|
|
{
|
|
$theme = $request->query('theme', $this->getSetting(RadioSettings::EmbedTheme, 'dark'));
|
|
|
|
$settings = [
|
|
'streamUrl' => $this->streamService->formatStreamUrl($this->getSetting(RadioSettings::StreamUrl, '')),
|
|
'theme' => in_array($theme, ['dark', 'light', 'transparent']) ? $theme : 'dark',
|
|
'autoPlay' => $request->query('autoplay', $this->getSetting(RadioSettings::EmbedAutoPlay, '0')) === '1',
|
|
'primaryColor' => $this->getSetting('radio_player_color_primary', '#eeb425'),
|
|
'secondaryColor' => $this->getSetting('radio_player_color_secondary', '#1a1a2e'),
|
|
'textColor' => $this->getSetting('radio_player_color_text', '#ffffff'),
|
|
'accentColor' => $this->getSetting('radio_player_color_accent', '#eeb425'),
|
|
];
|
|
|
|
return view('radio.embed', compact('settings'));
|
|
}
|
|
|
|
public function config(): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'enabled' => (bool) $this->getSetting(RadioSettings::EmbedEnabled, '0'),
|
|
'stream_url' => $this->streamService->formatStreamUrl($this->getSetting(RadioSettings::StreamUrl, '')),
|
|
'theme' => $this->getSetting(RadioSettings::EmbedTheme, 'dark'),
|
|
'auto_play' => (bool) $this->getSetting(RadioSettings::EmbedAutoPlay, '0'),
|
|
'primary_color' => $this->getSetting('radio_player_color_primary', '#eeb425'),
|
|
'secondary_color' => $this->getSetting('radio_player_color_secondary', '#1a1a2e'),
|
|
'text_color' => $this->getSetting('radio_player_color_text', '#ffffff'),
|
|
'accent_color' => $this->getSetting('radio_player_color_accent', '#eeb425'),
|
|
'height' => (int) $this->getSetting(RadioSettings::EmbedHeight, '400'),
|
|
'width' => $this->getSetting(RadioSettings::EmbedWidth, '100%'),
|
|
'allowed_domains' => $this->getSetting(RadioSettings::EmbedAllowedDomains, ''),
|
|
]);
|
|
}
|
|
|
|
private function getSetting(RadioSettings|string $key, mixed $default = null): mixed
|
|
{
|
|
$keyStr = $key instanceof RadioSettings ? $key->value : $key;
|
|
|
|
return Cache::remember("setting_{$keyStr}", 60, function () use ($keyStr, $default): mixed {
|
|
$websiteSetting = WebsiteSetting::where('key', $keyStr)->first();
|
|
|
|
return $websiteSetting?->value ?? $default;
|
|
});
|
|
}
|
|
}
|