vers. 2.1.1

This commit is contained in:
2026-01-28 19:05:44 +01:00
parent 719d750a7a
commit 52e40799d6
35 changed files with 14523 additions and 14012 deletions

View File

@@ -1,54 +1,202 @@
<?php
// Funzione per caricare il file XML delle radio
function loadRadioStations() {
$xml = simplexml_load_file('./data/radio.xml');
if ($xml === false) {
error_log("Errore nel caricamento del file XML: data/radio.xml");
return [];
}
return $xml->station;
}
// Funzione per ottenere una singola stazione radio
function getRadioStation($id) {
$xml = simplexml_load_file('./data/radio.xml');
if ($xml === false) {
error_log("Errore nel caricamento del file XML: data/radio.xml");
return null;
}
foreach ($xml->station as $station) {
if ((int)$station->id === $id) {
return $station;
}
}
return null;
}
// Funzione per caricare il file XML delle TV
function loadTVStations() {
$xml = simplexml_load_file('./data/tv.xml');
if ($xml === false) {
error_log("Errore nel caricamento del file XML: data/tv.xml");
return [];
}
return $xml->station;
}
// Funzione per ottenere una singola stazione TV
function getTVStation($id) {
$xml = simplexml_load_file('./data/tv.xml');
if ($xml === false) {
error_log("Errore nel caricamento del file XML: data/tv.xml");
return null;
}
foreach ($xml->station as $station) {
if ((int)$station->id === $id) {
return $station;
}
}
return null;
}
$changelog = simplexml_load_file("./data/changelog.xml") or die("Errore: Impossibile accedere al file CHANGELOG");
$version_app = $changelog->version->number[0];
<?php
/**
* Cache XML in memoria per la durata della richiesta
* Previene caricamenti multipli dello stesso file
*/
class StationCache {
private static $radioXML = null;
private static $tvXML = null;
private static $changelogXML = null;
/**
* Carica e cachea il file XML delle radio
*/
public static function getRadioXML() {
if (self::$radioXML === null) {
$xmlPath = './data/radio.xml';
if (!file_exists($xmlPath)) {
error_log("File XML non trovato: $xmlPath");
return false;
}
if (!is_readable($xmlPath)) {
error_log("File XML non leggibile: $xmlPath");
return false;
}
libxml_use_internal_errors(true);
self::$radioXML = simplexml_load_file($xmlPath);
if (self::$radioXML === false) {
$errors = libxml_get_errors();
foreach ($errors as $error) {
error_log("Errore XML radio.xml: " . trim($error->message) . " (Linea: " . $error->line . ")");
}
libxml_clear_errors();
return false;
}
}
return self::$radioXML;
}
/**
* Carica e cachea il file XML delle TV
*/
public static function getTVXML() {
if (self::$tvXML === null) {
$xmlPath = './data/tv.xml';
if (!file_exists($xmlPath)) {
error_log("File XML non trovato: $xmlPath");
return false;
}
if (!is_readable($xmlPath)) {
error_log("File XML non leggibile: $xmlPath");
return false;
}
libxml_use_internal_errors(true);
self::$tvXML = simplexml_load_file($xmlPath);
if (self::$tvXML === false) {
$errors = libxml_get_errors();
foreach ($errors as $error) {
error_log("Errore XML tv.xml: " . trim($error->message) . " (Linea: " . $error->line . ")");
}
libxml_clear_errors();
return false;
}
}
return self::$tvXML;
}
/**
* Carica e cachea il file XML del changelog
*/
public static function getChangelogXML() {
if (self::$changelogXML === null) {
$xmlPath = './data/changelog.xml';
if (!file_exists($xmlPath)) {
error_log("File XML non trovato: $xmlPath");
return false;
}
if (!is_readable($xmlPath)) {
error_log("File XML non leggibile: $xmlPath");
return false;
}
libxml_use_internal_errors(true);
self::$changelogXML = simplexml_load_file($xmlPath);
if (self::$changelogXML === false) {
$errors = libxml_get_errors();
foreach ($errors as $error) {
error_log("Errore XML changelog.xml: " . trim($error->message) . " (Linea: " . $error->line . ")");
}
libxml_clear_errors();
return false;
}
}
return self::$changelogXML;
}
}
/**
* Funzione per caricare tutte le stazioni radio
* @return array|SimpleXMLElement Array di stazioni o array vuoto in caso di errore
*/
function loadRadioStations() {
$xml = StationCache::getRadioXML();
if ($xml === false || !isset($xml->station)) {
error_log("Impossibile caricare le stazioni radio");
return [];
}
return $xml->station;
}
/**
* Funzione per ottenere una singola stazione radio
* @param int $id ID della stazione
* @return SimpleXMLElement|null Stazione o null se non trovata
*/
function getRadioStation($id) {
$xml = StationCache::getRadioXML();
if ($xml === false) {
error_log("Impossibile caricare XML radio per ID: $id");
return null;
}
if (!isset($xml->station)) {
error_log("Nessuna stazione trovata nel file XML");
return null;
}
foreach ($xml->station as $station) {
if ((int)$station->id === (int)$id) {
return $station;
}
}
error_log("Stazione radio non trovata con ID: $id");
return null;
}
/**
* Funzione per caricare tutte le stazioni TV
* @return array|SimpleXMLElement Array di stazioni o array vuoto in caso di errore
*/
function loadTVStations() {
$xml = StationCache::getTVXML();
if ($xml === false || !isset($xml->station)) {
error_log("Impossibile caricare le stazioni TV");
return [];
}
return $xml->station;
}
/**
* Funzione per ottenere una singola stazione TV
* @param int $id ID della stazione
* @return SimpleXMLElement|null Stazione o null se non trovata
*/
function getTVStation($id) {
$xml = StationCache::getTVXML();
if ($xml === false) {
error_log("Impossibile caricare XML TV per ID: $id");
return null;
}
if (!isset($xml->station)) {
error_log("Nessuna stazione TV trovata nel file XML");
return null;
}
foreach ($xml->station as $station) {
if ((int)$station->id === (int)$id) {
return $station;
}
}
error_log("Stazione TV non trovata con ID: $id");
return null;
}
/**
* Carica il changelog e la versione dell'app
*/
$changelog = StationCache::getChangelogXML();
$version_app = "1.0.0"; // Versione di default
if ($changelog !== false && isset($changelog->version) && isset($changelog->version[0]->number)) {
$version_app = (string)$changelog->version[0]->number;
} else {
error_log("Impossibile leggere la versione dal changelog.xml, uso versione di default: $version_app");
}