105 lines
3.1 KiB
PHP
105 lines
3.1 KiB
PHP
<?php
|
|
|
|
header('Content-Type: text/html; charset=UTF-8');
|
|
|
|
// File: config/getPage.inc.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"]);
|
|
}
|
|
|
|
// Funzione per sanitizzare l'input
|
|
function sanitizePageInput($input) {
|
|
// Rimuovi caratteri pericolosi
|
|
$input = preg_replace('/[^a-zA-Z0-9\-_]/', '', $input);
|
|
// Previeni path traversal
|
|
return str_replace(['..', '/', '\\'], '', $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 e il parametro iniziale
|
|
$page = 'home';
|
|
$param = '';
|
|
|
|
if (isset($path_parts[0]) && !empty($path_parts[0])) {
|
|
$page = sanitizePageInput($path_parts[0]);
|
|
}
|
|
|
|
if (isset($path_parts[1]) && !empty($path_parts[1])) {
|
|
$param = sanitizePageInput($path_parts[1]);
|
|
}
|
|
|
|
/**
|
|
* Risolve dinamicamente il percorso del file PHP corrispondente alla pagina e al parametro.
|
|
* Cerca automaticamente i file all'interno della cartella './pages/page/'.
|
|
* Se la pagina non esiste, restituisce il file di errore 404.
|
|
*/
|
|
function getPageFilePath($page, $param) {
|
|
$page = sanitizePageInput($page);
|
|
$param = sanitizePageInput($param);
|
|
|
|
// Gestione stazioni radio e TV (player)
|
|
if ($page === 'play') {
|
|
if (ctype_digit($param)) {
|
|
return './pages/page/player.php';
|
|
}
|
|
return './pages/page/404.php';
|
|
}
|
|
|
|
if ($page === 'playtv') {
|
|
if (ctype_digit($param)) {
|
|
return './pages/page/player_tv.php';
|
|
}
|
|
return './pages/page/404.php';
|
|
}
|
|
|
|
// Gestione sottopagine generiche /page/{param}
|
|
if ($page === 'page' && !empty($param)) {
|
|
$param_no_dash = str_replace('-', '', $param);
|
|
$paths = [
|
|
"./pages/page/{$param}.php",
|
|
"./pages/page/{$param_no_dash}.php"
|
|
];
|
|
foreach ($paths as $path) {
|
|
if (file_exists($path)) {
|
|
return $path;
|
|
}
|
|
}
|
|
return './pages/page/404.php';
|
|
}
|
|
|
|
// Gestione pagine principali (es: /home, /radio, /tv, /podcast)
|
|
$page_no_dash = str_replace('-', '', $page);
|
|
$paths = [
|
|
"./pages/page/{$page}.php",
|
|
"./pages/page/{$page_no_dash}.php"
|
|
];
|
|
foreach ($paths as $path) {
|
|
if (file_exists($path)) {
|
|
return $path;
|
|
}
|
|
}
|
|
|
|
return './pages/page/404.php';
|
|
}
|
|
|
|
// Debug (rimuovi in produzione)
|
|
error_log("Page resolved: $page, Param: $param, Path resolved file: " . getPageFilePath($page, $param)); |