Favorites

This commit is contained in:
Gogs
2026-07-07 11:32:03 +02:00
parent f3d25f20d3
commit c2da564dd6
5 changed files with 127 additions and 87 deletions
+7 -81
View File
@@ -1,11 +1,14 @@
<?php
require_once '/var/www/src/Config.php';
require_once '/var/www/src/XmlTv.php';
require_once '/var/www/src/View.php';
require_once '/var/www/src/Services/ChannelService.php';
require_once '/var/www/src/Services/XmlTvCacheService.php';
require_once '/var/www/src/Services/ProgrammeService.php';
require_once '/var/www/src/View.php';
require_once '/var/www/src/XmlTv.php';
require_once '/var/www/src/Controllers/HomeController.php';
$config = new Config(
'/var/www/config/config.json',
@@ -17,82 +20,5 @@ $xmltv = new XmlTv(
$config->get('timezone', 'Europe/Vienna')
);
$xmltv->synchronizeChannels($config);
$view = $_GET['view'] ?? $config->get('default_view', 'today');
if ($view === 'channels' && $_SERVER['REQUEST_METHOD'] === 'POST') {
$savedChannels = $config->getChannels();
foreach ($savedChannels as $id => &$channel) {
$channel['enabled'] = isset($_POST['enabled'][$id]);
$channel['favorite'] = isset($_POST['favorite'][$id]);
$channel['number'] = (int)($_POST['number'][$id] ?? $channel['number'] ?? 999999);
$channel['group'] = trim($_POST['group'][$id] ?? $channel['group'] ?? 'Unknown');
}
unset($channel);
uasort($savedChannels, function ($a, $b) {
return ((int)($a['number'] ?? 999999)) <=> ((int)($b['number'] ?? 999999));
});
$config->saveChannels($savedChannels);
header('Location: /?view=channels&saved=1');
exit;
}
[$channels, $programmes] = $xmltv->load($config);
$currentProgrammes = $xmltv->getCurrentProgrammes($config);
$tz = new DateTimeZone($config->get('timezone', 'Europe/Vienna'));
$selectedDate = $_GET['date'] ?? (new DateTime('now', $tz))->format('Y-m-d');
$selectedChannel = $_GET['channel'] ?? null;
if ($selectedChannel === '') {
$selectedChannel = null;
}
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $selectedDate)) {
$selectedDate = date('Y-m-d');
}
$dayProgrammes = $xmltv->getDayProgrammes($config, $selectedDate, $selectedChannel);
$tz = new DateTimeZone($config->get('timezone', 'Europe/Vienna'));
$nowDateTime = new DateTime('now', $tz);
$isToday = ($selectedDate === $nowDateTime->format('Y-m-d'));
$nowMinute = null;
if ($isToday) {
$nowMinute =
((int)$nowDateTime->format('H') * 60) +
(int)$nowDateTime->format('i');
}
$contentTemplate = match ($view) {
'channels' => '/var/www/templates/channels.php',
'now' => '/var/www/templates/now.php',
'day' => '/var/www/templates/day.php',
default => '/var/www/templates/home.php',
};
View::render('layout', [
'title' => $config->get('title', 'TVGuide'),
'channels' => $channels,
'programmes' => $programmes,
'contentTemplate' => $contentTemplate,
'view' => $view,
'channelConfig' => $config->getChannels(),
'saved' => isset($_GET['saved']),
'currentProgrammes' => $currentProgrammes,
'selectedDate' => $selectedDate,
'selectedChannel' => $selectedChannel,
'dayProgrammes' => $dayProgrammes,
'isToday' => $isToday,
'nowMinute' => $nowMinute,
]);
$controller = new HomeController($config, $xmltv);
$controller->handle($_GET, $_POST, $_SERVER['REQUEST_METHOD']);