feat: multi-EPG support + auto-migration old config format
- setup.php: dynamic EPG source fields (+ Add source button) - setup.php: toggle to allow personal EPG for visitors - index.php: auto-migrates old epg_url/m3u_url to epg_sources[] on first load - index.php: EPG_SOURCES array injected from PHP into JS - Backward compatible: single-source instances migrate silently
This commit is contained in:
@@ -1,14 +1,35 @@
|
||||
<?php
|
||||
// GridTV — index.php
|
||||
// Redirige vers setup.php si config.json absent
|
||||
if (!file_exists(__DIR__ . "/config.json")) {
|
||||
$config_path = __DIR__ . "/config.json";
|
||||
|
||||
if (!file_exists($config_path)) {
|
||||
header("Location: setup.php");
|
||||
exit;
|
||||
}
|
||||
$config = json_decode(file_get_contents(__DIR__ . "/config.json"), true);
|
||||
$group_name = htmlspecialchars($config["group_name"] ?? "GridTV");
|
||||
$epg_url = htmlspecialchars($config["epg_url"] ?? "");
|
||||
$m3u_url = htmlspecialchars($config["m3u_url"] ?? "");
|
||||
|
||||
$config = json_decode(file_get_contents($config_path), true);
|
||||
|
||||
// ── Migration automatique ancien format → nouveau ─────────────────────────────
|
||||
if (isset($config['epg_url']) && !isset($config['epg_sources'])) {
|
||||
$config['epg_sources'] = [[
|
||||
'name' => 'Main',
|
||||
'epg_url' => $config['epg_url'],
|
||||
'm3u_url' => $config['m3u_url'] ?? '',
|
||||
]];
|
||||
$config['allow_personal_epg'] = false;
|
||||
unset($config['epg_url'], $config['m3u_url']);
|
||||
file_put_contents($config_path, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
$group_name = htmlspecialchars($config['group_name'] ?? 'GridTV');
|
||||
$epg_sources = $config['epg_sources'] ?? [];
|
||||
$allow_personal_epg = !empty($config['allow_personal_epg']);
|
||||
|
||||
// Première source par défaut (pour compatibilité avec le reste du code)
|
||||
$first_source = $epg_sources[0] ?? [];
|
||||
$epg_url = htmlspecialchars($first_source['epg_url'] ?? '');
|
||||
$m3u_url = htmlspecialchars($first_source['m3u_url'] ?? '');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
@@ -809,8 +830,14 @@ foreach ($theme_files as $file) {
|
||||
<div class="mobile-view" id="mobileView"></div>
|
||||
|
||||
<script>
|
||||
const DEFAULT_EPG_URL = '<?= $epg_url ?>';
|
||||
const DEFAULT_M3U_URL = '<?= $m3u_url ?>';
|
||||
const EPG_SOURCES = <?= json_encode(array_values($epg_sources)) ?>;
|
||||
const ALLOW_PERSONAL_EPG = <?= $allow_personal_epg ? 'true' : 'false' ?>;
|
||||
|
||||
// Source active (index)
|
||||
let activeSourceIndex = 0;
|
||||
|
||||
const DEFAULT_EPG_URL = EPG_SOURCES[0]?.epg_url ?? '';
|
||||
const DEFAULT_M3U_URL = EPG_SOURCES[0]?.m3u_url ?? '';
|
||||
const PX_PER_MIN = 5;
|
||||
const GRID_HOURS = 72;
|
||||
const CORS_PROXY = 'https://corsproxy.io/?';
|
||||
|
||||
Reference in New Issue
Block a user