diff --git a/zanzara.php b/zanzara.php new file mode 100644 index 0000000..6e4642e --- /dev/null +++ b/zanzara.php @@ -0,0 +1,1282 @@ + 'lazanzara.greenpirates.org', + 'dirfiles' => 'lazanzara', + 'base_dir' => __DIR__, + 'file_pattern' => '/^(\d{8})-lazanzara\.mp3$/i', + 'cache_file' => __DIR__ . '/cache/valid_dates.json', + 'cache_timeout' => 3600, // 1 ora + 'show_download_link' => false // Mostra/nascondi link download diretto +]; + +/** + * Scansiona ricorsivamente le directory per trovare i file mp3 + * + * @param string $dir Directory da scansionare + * @param array $config Configurazione + * @return array Array di date valide (formato YYYYMMDD) + */ +function findValidDates($dir, $config) { + $validDates = []; + + // Costruisci il percorso completo + $fullPath = $config['base_dir'] . DIRECTORY_SEPARATOR . $dir; + + if (!is_dir($fullPath)) { + return $validDates; + } + + // Scansiona tutte le sottodirectory (anni) + $years = scandir($fullPath); + + foreach ($years as $year) { + // Salta . e .. e verifica che sia una directory anno valida + if ($year === '.' || $year === '..' || !preg_match('/^\d{4}$/', $year)) { + continue; + } + + $yearPath = $fullPath . DIRECTORY_SEPARATOR . $year; + + if (!is_dir($yearPath)) { + continue; + } + + // Scansiona i file nella directory dell'anno + $files = scandir($yearPath); + + foreach ($files as $file) { + // Verifica se il file corrisponde al pattern + if (preg_match($config['file_pattern'], $file, $matches)) { + $validDates[] = $matches[1]; + } + } + } + + // Ordina le date in ordine cronologico + sort($validDates); + + return $validDates; +} + +/** + * Ottiene le date valide con cache + */ +function getValidDates($config) { + // Verifica se usare la cache + $useCache = false; + if (file_exists($config['cache_file'])) { + $cacheAge = time() - filemtime($config['cache_file']); + if ($cacheAge < $config['cache_timeout']) { + $useCache = true; + } + } + + if ($useCache) { + // Usa i dati dalla cache + return json_decode(file_get_contents($config['cache_file']), true); + } else { + // Scansiona le directory + $validDates = findValidDates($config['dirfiles'], $config); + + // Salva nella cache (se la directory cache esiste) + $cacheDir = dirname($config['cache_file']); + if (is_dir($cacheDir) || @mkdir($cacheDir, 0755, true)) { + file_put_contents($config['cache_file'], json_encode($validDates)); + } + + return $validDates; + } +} + +// Funzione per validare e formattare la data +function validateDate($date) { + // Verifica se la data è nel formato YYYYMMDD + if (!preg_match('/^\d{8}$/', $date)) { + return false; + } + + $year = substr($date, 0, 4); + $month = substr($date, 4, 2); + $day = substr($date, 6, 2); + + // Verifica se è una data valida + return checkdate($month, $day, $year) ? $date : false; +} + +// Funzione per generare il percorso del file +function generateFilePath($date, $config) { + $year = substr($date, 0, 4); + + return [ + 'local_path' => sprintf("%s/%s/%s/%s-lazanzara.mp3", + $config['base_dir'], + $config['dirfiles'], + $year, + $date + ), + 'url' => sprintf("https://%s/%s/%s/%s-lazanzara.mp3", + $config['urlname'], + $config['dirfiles'], + $year, + $date + ), + 'filename' => sprintf("%s-lazanzara.mp3", $date) + ]; +} + +// Gestione richiesta AJAX per date valide +if (isset($_GET['action']) && $_GET['action'] === 'get_valid_dates') { + header('Content-Type: application/json'); + header('Cache-Control: max-age=3600'); + echo json_encode(getValidDates($config)); + exit; +} +?> + + + + + + + + + + Crux mea lux - LaZanzara Repository + + + + + + + + + + + + + +
+
+

- - - Crux mea Lux - - -

+

Unofficial LaZanzara Repository

+
+ +
+ 0) { + $randomIndex = array_rand($validDates); + $_POST['datepicker'] = $validDates[$randomIndex]; + } + } + + // Determina il valore da mostrare nell'input + $inputValue = ''; + if (isset($_POST['datepicker']) && !empty($_POST['datepicker'])) { + $inputValue = $_POST['datepicker']; + } + ?> + +
+
+
+ + + + + +
+
+ + +
+ + '; + + if (file_exists($paths['local_path'])) { + // File trovato + $year = substr($selectedDate, 0, 4); + $month = substr($selectedDate, 4, 2); + $day = substr($selectedDate, 6, 2); + $formattedDate = sprintf("%s/%s/%s", $day, $month, $year); + + // Ottieni dimensione file + $fileSize = filesize($paths['local_path']); + $fileSizeMB = round($fileSize / 1024 / 1024, 1); + + // Trova puntata precedente e successiva + $validDates = getValidDates($config); + $currentIndex = array_search($selectedDate, $validDates); + $prevDate = ($currentIndex > 0) ? $validDates[$currentIndex - 1] : null; + $nextDate = ($currentIndex < count($validDates) - 1) ? $validDates[$currentIndex + 1] : null; + + // Mostra se è una puntata random + if (isset($_POST['random']) && $_POST['random'] == '1') { + echo '

🎲 Puntata casuale in riproduzione!

'; + } + + // Audio player custom + echo '
'; + echo ''; + + // Layout principale + echo '
'; + + // Pulsante Play/Pause + echo ''; + + // Container progresso + echo '
'; + echo '
+
+
'; + echo '
'; + echo '0:00'; + echo '0:00'; + echo '
'; + echo '
'; + + echo '
'; // Chiude player-layout + echo '
'; // Chiude custom-audio-player + + // JavaScript per il player + echo ''; + + // Navigazione dopo il player + echo ''; + + // Mostra link download solo se configurato + if ($config['show_download_link']) { + echo '

+ Oppure scarica direttamente: + ' . + htmlspecialchars($paths['filename']) . ' +

'; + } + } else { + // File non trovato + echo '

File non trovato per la data: ' . + htmlspecialchars($selectedDate) . '

'; + } + + echo '
'; + } else { + echo '
+

Data non valida. Usa il formato YYYYMMDD

+
'; + } + } + + // Mostra statistiche + $validDates = getValidDates($config); + $totalFiles = count($validDates); + if ($totalFiles > 0) { + $firstDate = $validDates[0]; + $lastDate = $validDates[$totalFiles - 1]; + + echo '
'; + echo '

Statistiche archivio

'; + echo '

File disponibili: ' . $totalFiles . '

'; + echo '

Prima puntata: ' . substr($firstDate, 6, 2) . '/' . substr($firstDate, 4, 2) . '/' . substr($firstDate, 0, 4) . '

'; + echo '

Ultima puntata: ' . substr($lastDate, 6, 2) . '/' . substr($lastDate, 4, 2) . '/' . substr($lastDate, 0, 4) . '

'; + + // Conta file per anno + $yearCount = []; + foreach ($validDates as $date) { + $year = substr($date, 0, 4); + if (!isset($yearCount[$year])) { + $yearCount[$year] = 0; + } + $yearCount[$year]++; + } + + echo '
'; + echo 'File per anno'; + echo ''; + echo '
'; + echo '
'; + } + ?> + + + + +
+ Scorciatoie: ← → per navigare | R per random | Spazio per play/pause +
+ + + + + + + + + \ No newline at end of file