vers. 2.1.1
This commit is contained in:
@@ -1,67 +1,69 @@
|
||||
<?php
|
||||
|
||||
// Verifica se è una richiesta AJAX
|
||||
$is_ajax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
|
||||
|
||||
// Se è una richiesta AJAX, carica solo il contenuto della pagina
|
||||
if ($is_ajax) {
|
||||
switch ($page) {
|
||||
case 'home':
|
||||
include './pages/page/home.php';
|
||||
break;
|
||||
case 'radio':
|
||||
include './pages/page/radio.php';
|
||||
break;
|
||||
case 'tv':
|
||||
include './pages/page/tv.php';
|
||||
break;
|
||||
case 'play':
|
||||
$stationId = (int)$param;
|
||||
$station = getRadioStation($stationId);
|
||||
if ($station !== null) {
|
||||
include './pages/page/player.php';
|
||||
} else {
|
||||
include './pages/page/404.php';
|
||||
}
|
||||
break;
|
||||
case 'playtv':
|
||||
$stationId = (int)$param;
|
||||
$station = getTVStation($stationId);
|
||||
if ($station !== null) {
|
||||
include './pages/page/player_tv.php';
|
||||
} else {
|
||||
include './pages/page/404.php';
|
||||
}
|
||||
break;
|
||||
case 'page':
|
||||
switch ($param) {
|
||||
case 'about':
|
||||
include './pages/page/about.php';
|
||||
break;
|
||||
case 'contact':
|
||||
include './pages/page/contact.php';
|
||||
break;
|
||||
case 'copyright':
|
||||
include './pages/page/copyright.php';
|
||||
break;
|
||||
case 'addradio':
|
||||
include './pages/page/addradio.php';
|
||||
break;
|
||||
case 'termini-condizioni':
|
||||
include './pages/page/terminicondizioni.php';
|
||||
break;
|
||||
case 'policy-privacy':
|
||||
include './pages/page/policyprivacy.php';
|
||||
break;
|
||||
case 'changelog':
|
||||
include './pages/page/changelog.php';
|
||||
break;
|
||||
default:
|
||||
include './pages/page/404.php';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
include './pages/page/404.php';
|
||||
}
|
||||
exit; // Termina l'esecuzione per le richieste AJAX
|
||||
<?php
|
||||
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
// Verifica se è una richiesta AJAX
|
||||
$is_ajax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
|
||||
|
||||
// Se è una richiesta AJAX, carica solo il contenuto della pagina
|
||||
if ($is_ajax) {
|
||||
switch ($page) {
|
||||
case 'home':
|
||||
include './pages/page/home.php';
|
||||
break;
|
||||
case 'radio':
|
||||
include './pages/page/radio.php';
|
||||
break;
|
||||
case 'tv':
|
||||
include './pages/page/tv.php';
|
||||
break;
|
||||
case 'play':
|
||||
$stationId = (int)$param;
|
||||
$station = getRadioStation($stationId);
|
||||
if ($station !== null) {
|
||||
include './pages/page/player.php';
|
||||
} else {
|
||||
include './pages/page/404.php';
|
||||
}
|
||||
break;
|
||||
case 'playtv':
|
||||
$stationId = (int)$param;
|
||||
$station = getTVStation($stationId);
|
||||
if ($station !== null) {
|
||||
include './pages/page/player_tv.php';
|
||||
} else {
|
||||
include './pages/page/404.php';
|
||||
}
|
||||
break;
|
||||
case 'page':
|
||||
switch ($param) {
|
||||
case 'about':
|
||||
include './pages/page/about.php';
|
||||
break;
|
||||
case 'contact':
|
||||
include './pages/page/contact.php';
|
||||
break;
|
||||
case 'copyright':
|
||||
include './pages/page/copyright.php';
|
||||
break;
|
||||
case 'addradio':
|
||||
include './pages/page/addradio.php';
|
||||
break;
|
||||
case 'termini-condizioni':
|
||||
include './pages/page/terminicondizioni.php';
|
||||
break;
|
||||
case 'policy-privacy':
|
||||
include './pages/page/policyprivacy.php';
|
||||
break;
|
||||
case 'changelog':
|
||||
include './pages/page/changelog.php';
|
||||
break;
|
||||
default:
|
||||
include './pages/page/404.php';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
include './pages/page/404.php';
|
||||
}
|
||||
exit; // Termina l'esecuzione per le richieste AJAX
|
||||
}
|
||||
@@ -1,26 +1,29 @@
|
||||
<?php
|
||||
|
||||
// Information App
|
||||
$title_site = "RPIGroup Play";
|
||||
$description_site = "Ascolta le radio del gruppo RPIGroup";
|
||||
$logo_site = "./img/logoapp.png";
|
||||
|
||||
include_once './config/getBasePath.inc.php';
|
||||
include_once './config/getStation.inc.php';
|
||||
include_once './config/getPage.inc.php';
|
||||
|
||||
// Controllo se l'utente è su mobile o desktop
|
||||
$is_mobile = isMobile();
|
||||
|
||||
// Se l'utente è su mobile, mostra l'app direttamente
|
||||
// Se è su desktop, mostra prima la pagina con il pulsante "Apri l'app"
|
||||
$show_app = $is_mobile || (isset($_GET['app']) && $_GET['app'] == 'true');
|
||||
|
||||
if ($show_app && isset($_GET['redirect']) && !empty($_GET['redirect'])) {
|
||||
$redirect_parts = explode('/', $_GET['redirect']);
|
||||
$page = isset($redirect_parts[0]) ? $redirect_parts[0] : 'home';
|
||||
$param = isset($redirect_parts[1]) ? $redirect_parts[1] : '';
|
||||
}
|
||||
|
||||
// Include AJAX module DOPO aver definito le variabili
|
||||
<?php
|
||||
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
|
||||
// Information App
|
||||
$title_site = "RPIGroup Play";
|
||||
$description_site = "Ascolta le radio del gruppo RPIGroup";
|
||||
$logo_site = "./img/logoapp.png";
|
||||
|
||||
include_once './config/getBasePath.inc.php';
|
||||
include_once './config/getStation.inc.php';
|
||||
include_once './config/getPage.inc.php';
|
||||
|
||||
// Controllo se l'utente è su mobile o desktop
|
||||
$is_mobile = isMobile();
|
||||
|
||||
// Se l'utente è su mobile, mostra l'app direttamente
|
||||
// Se è su desktop, mostra prima la pagina con il pulsante "Apri l'app"
|
||||
$show_app = $is_mobile || (isset($_GET['app']) && $_GET['app'] == 'true');
|
||||
|
||||
if ($show_app && isset($_GET['redirect']) && !empty($_GET['redirect'])) {
|
||||
$redirect_parts = explode('/', $_GET['redirect']);
|
||||
$page = isset($redirect_parts[0]) ? $redirect_parts[0] : 'home';
|
||||
$param = isset($redirect_parts[1]) ? $redirect_parts[1] : '';
|
||||
}
|
||||
|
||||
// Include AJAX module DOPO aver definito le variabili
|
||||
include_once './config/ajaxModule.inc.php';
|
||||
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
// Determina il percorso base dell'applicazione
|
||||
$script_name = $_SERVER['SCRIPT_NAME'];
|
||||
$script_path = dirname($script_name);
|
||||
$base_path = rtrim($script_path, '/');
|
||||
<?php
|
||||
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
// Determina il percorso base dell'applicazione
|
||||
$script_name = $_SERVER['SCRIPT_NAME'];
|
||||
$script_path = dirname($script_name);
|
||||
$base_path = rtrim($script_path, '/');
|
||||
$base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$base_path";
|
||||
@@ -1,31 +1,84 @@
|
||||
<?php
|
||||
|
||||
// Rileva se l'utente sta usando un dispositivo mobile
|
||||
function isMobile() {
|
||||
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
|
||||
}
|
||||
|
||||
// Recupera l'URL richiesto
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
$path = substr(urldecode($request_uri), strlen($base_path));
|
||||
$path = parse_url($path, PHP_URL_PATH);
|
||||
$path = trim($path, '/');
|
||||
|
||||
// Rimuovi parametri GET dall'URL se presenti
|
||||
if (strpos($path, '?') !== false) {
|
||||
$path = substr($path, 0, strpos($path, '?'));
|
||||
}
|
||||
|
||||
$path_parts = explode('/', $path);
|
||||
|
||||
// Rimuovi index.php dall'URL se presente
|
||||
if (isset($path_parts[0]) && $path_parts[0] == 'index.php') {
|
||||
array_shift($path_parts);
|
||||
}
|
||||
|
||||
// Determina la pagina da mostrare in base all'URL
|
||||
$page = isset($path_parts[0]) && !empty($path_parts[0]) ? $path_parts[0] : 'home';
|
||||
$param = isset($path_parts[1]) && !empty($path_parts[1]) ? $path_parts[1] : '';
|
||||
|
||||
// Debug (rimuovi in produzione)
|
||||
error_log("Page: $page, Param: $param, Path: $path");
|
||||
<?php
|
||||
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
// File: config/getPage.inc.php
|
||||
|
||||
// Whitelist delle pagine valide
|
||||
$validPages = ['home', 'radio', 'tv', 'play', 'playtv', 'page'];
|
||||
$validSubPages = ['about', 'contact', 'copyright', 'addradio', 'termini-condizioni', 'policy-privacy', 'changelog'];
|
||||
|
||||
// Rileva se l'utente sta usando un dispositivo mobile
|
||||
function isMobile() {
|
||||
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
|
||||
}
|
||||
|
||||
// Funzione per sanitizzare l'input
|
||||
function sanitizePageInput($input) {
|
||||
// Rimuovi caratteri pericolosi
|
||||
$input = preg_replace('/[^a-zA-Z0-9\-_]/', '', $input);
|
||||
// Previeni path traversal
|
||||
$input = str_replace(['..', '/', '\\'], '', $input);
|
||||
return $input;
|
||||
}
|
||||
|
||||
// Recupera l'URL richiesto
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
$path = substr(urldecode($request_uri), strlen($base_path));
|
||||
$path = parse_url($path, PHP_URL_PATH);
|
||||
$path = trim($path, '/');
|
||||
|
||||
// Rimuovi parametri GET dall'URL se presenti
|
||||
if (strpos($path, '?') !== false) {
|
||||
$path = substr($path, 0, strpos($path, '?'));
|
||||
}
|
||||
|
||||
$path_parts = explode('/', $path);
|
||||
|
||||
// Rimuovi index.php dall'URL se presente
|
||||
if (isset($path_parts[0]) && $path_parts[0] == 'index.php') {
|
||||
array_shift($path_parts);
|
||||
}
|
||||
|
||||
// Determina la pagina da mostrare in base all'URL con validazione
|
||||
$page = 'home'; // Default sicuro
|
||||
$param = '';
|
||||
|
||||
if (isset($path_parts[0]) && !empty($path_parts[0])) {
|
||||
$requestedPage = sanitizePageInput($path_parts[0]);
|
||||
|
||||
// Verifica se la pagina è nella whitelist
|
||||
if (in_array($requestedPage, $validPages)) {
|
||||
$page = $requestedPage;
|
||||
} else {
|
||||
// Pagina non valida, redirect a 404
|
||||
$page = 'home';
|
||||
error_log("Tentativo di accesso a pagina non valida: " . $path_parts[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($path_parts[1]) && !empty($path_parts[1])) {
|
||||
$requestedParam = sanitizePageInput($path_parts[1]);
|
||||
|
||||
// Validazione specifica per tipo di pagina
|
||||
if ($page === 'play' || $page === 'playtv') {
|
||||
// Per play/playtv, il parametro deve essere un numero
|
||||
if (ctype_digit($requestedParam)) {
|
||||
$param = $requestedParam;
|
||||
} else {
|
||||
error_log("ID stazione non valido: " . $path_parts[1]);
|
||||
$page = 'home';
|
||||
}
|
||||
} elseif ($page === 'page') {
|
||||
// Per page, il parametro deve essere nella whitelist
|
||||
if (in_array($requestedParam, $validSubPages)) {
|
||||
$param = $requestedParam;
|
||||
} else {
|
||||
error_log("Sottopagina non valida: " . $path_parts[1]);
|
||||
$page = 'home';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Debug (rimuovi in produzione)
|
||||
error_log("Page: $page, Param: $param, Path: $path");
|
||||
@@ -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");
|
||||
}
|
||||
Reference in New Issue
Block a user