Files
Atomcms-edit/app/Http/Controllers/Admin/RadioSetupController.php
T
root 4094f0fb14 Fix 40+ codebase issues: security, performance, duplication, dead code, and routes
HIGH:
- Add missing import RadioSongRequestFormRequest (fixes crash on POST)
- Add Purify XSS sanitization for article full_story
- Fix duplicate radio API routes (/api/radio vs /api/radio/v2)
- Add try-catch guards in InstallationController for missing records

MEDIUM:
- Fix N+1: eager load comments.user in ArticleController::show()
- Fix GuestbookController authorization logic
- Remove dead doSetup() method and duplicate route
- Extract shared HasRadioDefaults trait (remove code duplication)
- Use named routes in ForceStaffTwoFactorMiddleware
- Fix WebsiteHelpCenterTicket::isOpen() (no permission leak)
- Enable  on WebsiteHelpCenterTicket (matches schema)
- Replace WebsiteTeam::all()->pluck() with direct pluck()
- Replace CatalogPage::all()->pluck() with direct pluck()
- Replace WebsiteBadge::all() with direct pluck()
- Add throttle middleware to guestbook store, logo-generator, radio embed

LOW:
- Remove unused imports
- Remove dead /inertia-test route
- Consolidate cache keys in RadioController
2026-06-08 18:56:34 +02:00

172 lines
6.7 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Miscellaneous\WebsiteSetting;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\View\View;
class RadioSetupController extends Controller
{
use \App\Http\Controllers\Concerns\HasRadioDefaults;
public function index(): View
{
return view('admin.radio.setup');
}
public function setup(Request $request): RedirectResponse
{
try {
// Standard radio settings
$settings = [
// Basic Radio Settings
'radio_enabled' => '1',
'radio_stream_url' => 'https://stream.radioking.com/radio/83232/radio.mp3',
'radio_style' => 'dark',
'radio_auto_play' => '0',
// Points System Settings
'points_enabled' => '1',
'points_per_minute' => '2',
'max_points_per_day' => '100',
'points_for_request' => '5',
'points_for_vote' => '2',
'points_for_giveaway_win' => '50',
'points_for_contest_win' => '100',
// Features Settings
'radio_shouts_enabled' => '1',
'radio_now_playing_enabled' => '1',
'radio_listeners_enabled' => '1',
'radio_show_current_dj' => '1',
'radio_widget_enabled' => '1',
'radio_widget_show_globally' => '1',
'radio_widget_position' => 'bottom-right',
// DJ Settings
'radio_applications_enabled' => '1',
'radio_auto_dj_detection' => '1',
// Monitoring Settings
'radio_monitoring_enabled' => '1',
'radio_monitoring_timeout' => '5',
// Stream Settings
'radio_stream_fallback_url' => '',
'radio_stream_backup_enabled' => '0',
// Display Settings
'radio_show_song_history' => '1',
'radio_show_schedule_preview' => '1',
'radio_max_history_items' => '10',
// Social Settings
'radio_social_links_enabled' => '1',
'radio_facebook_url' => '',
'radio_twitter_url' => '',
'radio_discord_url' => '',
'radio_instagram_url' => '',
'radio_youtube_url' => '',
'radio_twitch_url' => '',
// Moderation Settings
'radio_word_filter_enabled' => '1',
'radio_max_shout_length' => '280',
'radio_shout_cooldown' => '30',
// Contest Settings
'radio_contests_enabled' => '1',
'radio_giveaways_enabled' => '1',
'radio_auto_contest_creation' => '0',
];
$this->saveRadioSettings($settings);
// Create default radio ranks if they don't exist
$this->createDefaultRanks();
// Clear caches
Artisan::call('config:clear');
Artisan::call('cache:clear');
return redirect()->route('admin.radio.setup')
->with('success', __('radio.setup.success_body'));
} catch (\Exception $e) {
return redirect()->route('admin.radio.setup')
->with('error', __('radio.setup.error_body', ['message' => $e->getMessage()]));
}
}
public function reset(): RedirectResponse
{
try {
WebsiteSetting::where('key', 'like', 'radio_%')->delete();
WebsiteSetting::where('key', 'like', 'points_%')->delete();
Artisan::call('config:clear');
Artisan::call('cache:clear');
return redirect()->route('admin.radio.setup')
->with('success', 'Radio instellingen zijn gereset.');
} catch (\Exception $e) {
return redirect()->route('admin.radio.setup')
->with('error', 'Fout bij resetten: ' . $e->getMessage());
}
}
private function getSettingComment(string $key): string
{
$comments = [
'radio_enabled' => 'Enable radio system',
'radio_stream_url' => 'Main radio stream URL',
'radio_style' => 'Radio player theme style',
'radio_auto_play' => 'Auto-play radio on page load',
'points_enabled' => 'Enable points system',
'points_per_minute' => 'Points awarded per minute',
'max_points_per_day' => 'Maximum points per day',
'points_for_request' => 'Points for song request',
'points_for_vote' => 'Points for voting',
'points_for_giveaway_win' => 'Points for giveaway win',
'points_for_contest_win' => 'Points for contest win',
'radio_shouts_enabled' => 'Enable shouts system',
'radio_now_playing_enabled' => 'Show now playing info',
'radio_listeners_enabled' => 'Show listener count',
'radio_show_current_dj' => 'Show current DJ',
'radio_widget_enabled' => 'Enable radio widget',
'radio_widget_show_globally' => 'Show widget on all pages',
'radio_widget_position' => 'Widget position',
'radio_applications_enabled' => 'Enable DJ applications',
'radio_auto_dj_detection' => 'Auto-detect DJ from schedule',
'radio_monitoring_enabled' => 'Enable stream monitoring',
'radio_monitoring_timeout' => 'Stream check timeout',
'radio_stream_fallback_url' => 'Backup stream URL',
'radio_stream_backup_enabled' => 'Enable backup stream',
'radio_show_song_history' => 'Show recent songs',
'radio_show_schedule_preview' => 'Show today\'s schedule',
'radio_max_history_items' => 'Max history items to show',
'radio_social_links_enabled' => 'Enable social media links',
'radio_facebook_url' => 'Facebook page URL',
'radio_twitter_url' => 'Twitter profile URL',
'radio_discord_url' => 'Discord server URL',
'radio_instagram_url' => 'Instagram profile URL',
'radio_youtube_url' => 'YouTube channel URL',
'radio_twitch_url' => 'Twitch channel URL',
'radio_word_filter_enabled' => 'Enable word filter',
'radio_max_shout_length' => 'Maximum shout character length',
'radio_shout_cooldown' => 'Shout cooldown in seconds',
'radio_contests_enabled' => 'Enable contests',
'radio_giveaways_enabled' => 'Enable giveaways',
'radio_auto_contest_creation' => 'Auto-create contests',
];
return $comments[$key] ?? 'Radio setting';
}
}