/
home
/
shalala
/
winterhits.com
/
Upload File
HOME
<?php /** * create-track.php — Winterhits.com Track Creator * ───────────────────────────────────────────────── * Drop in your site root. Visit it in a browser to create new track pages. * * FIRST-TIME SETUP — set your password hash: * 1. Visit https://bcrypt-generator.com (or any bcrypt tool), cost factor 12 * 2. Hash your chosen password * 3. Paste the result below, replacing the placeholder */ define('PASSWORD_HASH', '$2a$12$P4TixG.syo.fW8nTqo0fxezC3QkyIaTkanue85uetBYsWA38hutc'); define('SESSION_NAME', 'wh_creator'); define('SESSION_DURATION', 7200); // 2 hours // ── allowed file types ──────────────────────────────────────────────────────── define('ALLOWED_AUDIO', ['audio/mpeg', 'audio/wav', 'audio/x-wav', 'audio/flac', 'audio/x-flac']); define('ALLOWED_IMAGE', ['image/jpeg', 'image/png', 'image/webp']); define('ALLOWED_AUDIO_EXT', ['mp3', 'wav', 'flac']); define('ALLOWED_IMAGE_EXT', ['jpg', 'jpeg', 'png', 'webp']); // ── session ─────────────────────────────────────────────────────────────────── session_name(SESSION_NAME); session_start(); $error = ''; $success = ''; $step = 'login'; // login | create | done // ── logout ──────────────────────────────────────────────────────────────────── if (isset($_GET['logout'])) { session_destroy(); header('Location: ' . $_SERVER['PHP_SELF']); exit; } // ── login ───────────────────────────────────────────────────────────────────── if (!isset($_SESSION['authed'])) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password'])) { if (password_verify($_POST['password'], PASSWORD_HASH)) { session_regenerate_id(true); $_SESSION['authed'] = true; $_SESSION['time'] = time(); } else { // rate-limit hint: sleep briefly to slow brute force sleep(1); $error = 'Incorrect password.'; } } } else { // session timeout check if (time() - $_SESSION['time'] > SESSION_DURATION) { session_destroy(); header('Location: ' . $_SERVER['PHP_SELF']); exit; } $_SESSION['time'] = time(); } // ── helper ─────────────────────────────────────────────────────────────────── function json_respond(array $data): void { header('Content-Type: application/json'); echo json_encode($data); exit; } // ── ACTION: setup — validate fields, create folders, write index, regen json ── if (isset($_SESSION['authed']) && $_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'setup') { $rawSlug = trim($_POST['slug'] ?? ''); $slug = preg_replace('/[^a-z0-9\-]/', '', strtolower(str_replace(' ', '-', $rawSlug))); if (empty($slug)) json_respond(['ok' => false, 'error' => 'URL slug is required.']); if (is_dir(__DIR__ . '/' . $slug)) json_respond(['ok' => false, 'error' => 'A folder with this slug already exists.']); if (empty($_POST['title'])) json_respond(['ok' => false, 'error' => 'Title is required.']); if (empty($_POST['audio_name'])) json_respond(['ok' => false, 'error' => 'Audio filename is required.']); if (empty($_POST['artwork_name'])) json_respond(['ok' => false, 'error' => 'Artwork filename is required.']); $audioFilename = preg_replace('/[^a-zA-Z0-9\._\-]/', '_', basename($_POST['audio_name'])); $artworkFilename = preg_replace('/[^a-zA-Z0-9\._\-]/', '_', basename($_POST['artwork_name'])); $colors = [ '--bg' => $_POST['color_bg'] ?? '#0d0d0d', '--surface' => $_POST['color_surface'] ?? '#161616', '--border' => $_POST['color_border'] ?? '#2a2a2a', '--accent' => $_POST['color_accent'] ?? '#e8d5a3', '--accent-dim' => $_POST['color_accent_dim'] ?? '#a89060', '--text' => $_POST['color_text'] ?? '#f0ece4', '--text-muted' => $_POST['color_text_muted'] ?? '#7a7570', '--progress-bg' => $_POST['color_progress_bg'] ?? '#252525', ]; $trackConfig = [ 'title' => trim($_POST['title'] ?? ''), 'subtitle' => trim($_POST['subtitle'] ?? ''), 'artist' => trim($_POST['artist'] ?? ''), 'label' => trim($_POST['label'] ?? 'Marshall Records'), 'src' => $audioFilename, 'artwork' => $artworkFilename, 'artworkAlt' => trim($_POST['artworkAlt'] ?? ''), 'description' => trim($_POST['description'] ?? ''), 'downloadUrl' => trim($_POST['downloadUrl'] ?? ''), 'colors' => $colors, ]; foreach (['subtitle', 'artworkAlt', 'description', 'downloadUrl'] as $k) { if ($trackConfig[$k] === '') unset($trackConfig[$k]); } $format = trim($_POST['format'] ?? ''); if ($format !== '') $trackConfig['format'] = $format; $configJson = json_encode($trackConfig, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); $trackDir = __DIR__ . '/' . $slug; $audioDir = $trackDir . '/audio'; $artworkDir = $trackDir . '/artwork'; mkdir($trackDir, 0755, true); mkdir($audioDir, 0755, true); mkdir($artworkDir, 0755, true); file_put_contents($trackDir . '/index.html', getTemplate($configJson)); regenerateTracks(); json_respond(['ok' => true, 'slug' => $slug, 'audio_filename' => $audioFilename, 'artwork_filename' => $artworkFilename]); } // ── ACTION: upload_artwork ──────────────────────────────────────────────────── if (isset($_SESSION['authed']) && $_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'upload_artwork') { $slug = preg_replace('/[^a-z0-9\-]/', '', $_POST['slug'] ?? ''); $trackDir = __DIR__ . '/' . $slug; if (!is_dir($trackDir)) json_respond(['ok' => false, 'error' => 'Track folder not found.']); if (empty($_FILES['artwork']['name'])) json_respond(['ok' => false, 'error' => 'No artwork file received.']); $imgExt = strtolower(pathinfo($_FILES['artwork']['name'], PATHINFO_EXTENSION)); $imgMime = mime_content_type($_FILES['artwork']['tmp_name']); if (!in_array($imgExt, ALLOWED_IMAGE_EXT) || !in_array($imgMime, ALLOWED_IMAGE)) json_respond(['ok' => false, 'error' => 'Invalid artwork file type.']); if (!getimagesize($_FILES['artwork']['tmp_name'])) json_respond(['ok' => false, 'error' => 'File does not appear to be a valid image.']); $artworkFilename = preg_replace('/[^a-zA-Z0-9\._\-]/', '_', basename($_FILES['artwork']['name'])); move_uploaded_file($_FILES['artwork']['tmp_name'], $trackDir . '/artwork/' . $artworkFilename); json_respond(['ok' => true]); } // ── ACTION: upload_audio ────────────────────────────────────────────────────── if (isset($_SESSION['authed']) && $_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'upload_audio') { $slug = preg_replace('/[^a-z0-9\-]/', '', $_POST['slug'] ?? ''); $trackDir = __DIR__ . '/' . $slug; if (!is_dir($trackDir)) json_respond(['ok' => false, 'error' => 'Track folder not found.']); if (empty($_FILES['audio']['name'])) json_respond(['ok' => false, 'error' => 'No audio file received.']); $audioExt = strtolower(pathinfo($_FILES['audio']['name'], PATHINFO_EXTENSION)); $audioMime = mime_content_type($_FILES['audio']['tmp_name']); if (!in_array($audioExt, ALLOWED_AUDIO_EXT) || !in_array($audioMime, ALLOWED_AUDIO)) json_respond(['ok' => false, 'error' => 'Invalid audio file type. Only MP3, WAV and FLAC are allowed.']); $audioFilename = preg_replace('/[^a-zA-Z0-9\._\-]/', '_', basename($_FILES['audio']['name'])); move_uploaded_file($_FILES['audio']['tmp_name'], $trackDir . '/audio/' . $audioFilename); json_respond(['ok' => true, 'url' => '/' . $slug . '/']); } if (isset($_SESSION['authed']) && $step === 'login') { $step = 'create_form'; } // ── tracks.json regenerator (same logic as scan.php) ───────────────────────── function regenerateTracks() { $root = __DIR__; $skip = ['.', '..', 'cgi-bin', 'wp-admin', 'wp-includes', 'wp-content']; $tracks = []; foreach (scandir($root) as $dir) { if (in_array($dir, $skip)) continue; if (!is_dir($root . '/' . $dir)) continue; if (str_starts_with($dir, '.')) continue; $indexFile = $root . '/' . $dir . '/index.html'; if (!file_exists($indexFile)) continue; $html = file_get_contents($indexFile); $pattern = '/<script[^>]+id=["\']track-config["\'][^>]*>(.*?)<\/script>/s'; if (!preg_match($pattern, $html, $matches)) continue; $cfg = json_decode(trim($matches[1]), true); if (json_last_error() !== JSON_ERROR_NONE) continue; $entry = [ 'title' => $cfg['title'] ?? 'Untitled', 'artist' => $cfg['artist'] ?? '', 'url' => '/' . $dir . '/', ]; if (!empty($cfg['subtitle'])) $entry['subtitle'] = $cfg['subtitle']; if (!empty($cfg['artwork'])) $entry['artwork'] = '/' . $dir . '/artwork/' . $cfg['artwork']; if (!empty($cfg['label'])) $entry['label'] = $cfg['label']; $tracks[] = $entry; } usort($tracks, fn($a, $b) => strcasecmp($a['title'], $b['title'])); file_put_contents($root . '/tracks.json', json_encode($tracks, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); } // ── embedded template ───────────────────────────────────────────────────────── function getTemplate(string $configJson): string { // The config JSON is injected into the template's script block $template = <<<'HTMLTEMPLATE' <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title id="page-title">Audio Player</title> <style> @font-face { font-family: 'Mono45Headline'; src: url('../Mono45Headline-Light.woff2') format('woff2'), url('../Mono45Headline-Light.woff') format('woff'); font-weight: 300; font-style: normal; } @font-face { font-family: 'Mono45Headline'; src: url('../Mono45Headline-Regular.woff2') format('woff2'), url('../Mono45Headline-Regular.woff') format('woff'); font-weight: 400; font-style: normal; } @font-face { font-family: 'Mono45Headline'; src: url('../Mono45Headline-Bold.woff2') format('woff2'), url('../Mono45Headline-Bold.woff') format('woff'); font-weight: 700; font-style: normal; } :root { --bg: #0d0d0d; --surface: #161616; --border: #2a2a2a; --accent: #e8d5a3; --accent-dim: #a89060; --text: #f0ece4; --text-muted: #7a7570; --progress-bg: #252525; } *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } body { background: var(--bg); color: var(--text); font-family: 'Mono45Headline', monospace; font-weight: 400; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 0.5rem 2rem 2rem 2rem; } body::before { content: ''; position: fixed; inset: 0; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E"); opacity: 0.04; pointer-events: none; z-index: 0; } .card { position: relative; z-index: 1; width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--border); overflow: hidden; } .artwork-wrap { position: relative; width: 100%; aspect-ratio: 1 / 1; overflow: hidden; background: #111; } .artwork-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter 0.6s ease; } .artwork-wrap.playing img { filter: brightness(0.85); } .eq-bars { position: absolute; bottom: 1.2rem; left: 1.4rem; display: flex; gap: 3px; align-items: flex-end; height: 28px; opacity: 0; transition: opacity 0.3s; } .artwork-wrap.playing .eq-bars { opacity: 1; } .eq-bars span { display: block; width: 3px; background: var(--accent); border-radius: 1px; animation: eq 0.8s ease-in-out infinite alternate; } .eq-bars span:nth-child(1) { height: 40%; animation-duration: 0.6s; } .eq-bars span:nth-child(2) { height: 80%; animation-duration: 0.9s; } .eq-bars span:nth-child(3) { height: 55%; animation-duration: 0.7s; } .eq-bars span:nth-child(4) { height: 90%; animation-duration: 1.0s; } .eq-bars span:nth-child(5) { height: 50%; animation-duration: 0.75s; } @keyframes eq { from { transform: scaleY(1); } to { transform: scaleY(0.2); } } .format-badge { position: absolute; top: 1rem; right: 1rem; font-family: 'Mono45Headline', monospace; font-weight: 300; font-size: 0.65rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); border: 1px solid var(--accent-dim); padding: 0.2rem 0.5rem; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); } .meta { padding: 1.5rem 1.6rem 0.8rem; border-bottom: 1px solid var(--border); } .track-label { font-family: 'Mono45Headline', monospace; font-weight: 300; font-size: 0.6rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.5rem; } .track-title { font-family: 'Mono45Headline', monospace; font-weight: 700; font-size: 1.75rem; line-height: 1.1; color: var(--text); margin-bottom: 0.35rem; } .track-subtitle { display: block; font-weight: 400; font-size: 1.75rem; } .track-artist { font-family: 'Mono45Headline', monospace; font-weight: 400; font-size: 1rem; color: var(--accent-dim); letter-spacing: 0.06em; } .description { padding: 1rem 1.6rem; font-family: 'Mono45Headline', monospace; font-weight: 400; font-size: 1rem; line-height: 1.7; color: var(--text-muted); border-bottom: 1px solid var(--border); } .controls { padding: 1.2rem 1.6rem 1.5rem; } .progress-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.2rem; } .time { font-family: 'Mono45Headline', monospace; font-weight: 400; font-size: 0.65rem; color: var(--text-muted); min-width: 3rem; letter-spacing: 0.05em; } .time.right { text-align: right; } .progress-track { flex: 1; height: 44px; display: flex; align-items: center; position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; } .progress-visual { position: absolute; left: 0; right: 0; height: 3px; background: var(--progress-bg); border-radius: 2px; pointer-events: none; } .progress-fill { height: 100%; background: var(--accent); border-radius: 2px; width: 0%; pointer-events: none; } .progress-thumb { position: absolute; top: 50%; left: 0%; transform: translate(-50%, -50%); width: 12px; height: 12px; border-radius: 50%; background: var(--accent); opacity: 0; transition: opacity 0.2s; pointer-events: none; } .progress-track:hover .progress-thumb, .progress-track.dragging .progress-thumb { opacity: 1; } .buttons-row { display: flex; align-items: center; justify-content: space-between; } .side { flex: 1; display: flex; align-items: center; } .side.right { justify-content: flex-end; } .btn-play { width: 52px; height: 52px; border-radius: 50%; border: 1.5px solid var(--accent); background: transparent; color: var(--accent); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s, color 0.2s; flex-shrink: 0; -webkit-tap-highlight-color: transparent; } .btn-play:hover { background: var(--accent); color: var(--bg); } .btn-play svg { display: block; } .volume-group { display: flex; align-items: center; gap: 0.5rem; } .vol-icon { color: var(--text-muted); cursor: pointer; flex-shrink: 0; transition: color 0.2s; } .vol-icon:hover { color: var(--accent); } input[type=range].vol-slider { -webkit-appearance: none; appearance: none; width: 70px; height: 3px; background: var(--progress-bg); border-radius: 2px; outline: none; cursor: pointer; } input[type=range].vol-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); cursor: pointer; } input[type=range].vol-slider::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: none; cursor: pointer; } .btn-download { font-family: 'Mono45Headline', monospace; font-weight: 400; font-size: 0.6rem; letter-spacing: 0.12em; text-transform: uppercase; text-decoration: none; color: var(--bg); background: var(--accent); border: none; padding: 0.5rem 0.85rem; cursor: pointer; display: inline-block; transition: opacity 0.2s; -webkit-tap-highlight-color: transparent; } .btn-download:hover { opacity: 0.8; } .next-track-bar { display: none; border-top: 1px solid var(--border); padding: 0.75rem 1.6rem; align-items: center; justify-content: space-between; gap: 1rem; } .next-track-bar.ready { display: flex; } .next-track-label { font-family: 'Mono45Headline', monospace; font-weight: 300; font-size: 0.6rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; } .next-track-link { font-family: 'Mono45Headline', monospace; font-weight: 700; font-size: 0.7rem; letter-spacing: 0.06em; color: var(--accent); text-decoration: none; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; transition: opacity 0.2s; } .next-track-link:hover { opacity: 0.7; } .card-footer { padding: 0.7rem 1.6rem; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; } .footer-label { font-family: 'Mono45Headline', monospace; font-weight: 300; font-size: 0.55rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--border); } .waveform-static { display: flex; align-items: center; gap: 2px; height: 14px; } .waveform-static span { display: block; width: 2px; border-radius: 1px; background: var(--border); } </style> </head> <body> <script id="track-config" type="application/json"> %%CONFIG%% </script> <audio id="audio"></audio> <div class="card" id="player-card"> <div class="artwork-wrap" id="artwork-wrap"> <img id="artwork-img" src="" alt="" /> <div class="format-badge" id="format-badge"></div> <div class="eq-bars"> <span></span><span></span><span></span><span></span><span></span> </div> </div> <div class="meta"> <div class="track-label" id="track-label"></div> <div class="track-title" id="track-title"></div> <div class="track-artist" id="track-artist"></div> </div> <div class="description" id="track-description"></div> <div class="controls"> <div class="progress-row"> <span class="time" id="time-current">0:00</span> <div class="progress-track" id="progress-track"> <div class="progress-visual"> <div class="progress-fill" id="progress-fill"></div> </div> <div class="progress-thumb" id="progress-thumb"></div> </div> <span class="time right" id="time-duration">0:00</span> </div> <div class="buttons-row"> <div class="side left"> <div class="volume-group"> <svg class="vol-icon" id="vol-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" onclick="toggleMute()"> <polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"/> <path id="vol-wave-1" d="M15.54 8.46a5 5 0 0 1 0 7.07"/> <path id="vol-wave-2" d="M19.07 4.93a10 10 0 0 1 0 14.14"/> </svg> <input type="range" class="vol-slider" id="vol-slider" min="0" max="1" step="0.01" value="1" oninput="setVolume(this.value)"/> </div> </div> <button class="btn-play" id="btn-play" onclick="togglePlay()" aria-label="Play / Pause"> <svg id="icon-play" width="20" height="20" viewBox="0 0 24 24" fill="currentColor"> <polygon points="5 3 19 12 5 21 5 3"/> </svg> <svg id="icon-pause" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" style="display:none"> <rect x="6" y="4" width="4" height="16"/><rect x="14" y="4" width="4" height="16"/> </svg> </button> <div class="side right"> <a class="btn-download" id="btn-download" href="#" target="_blank" rel="noopener">Download</a> </div> </div> </div> <div class="next-track-bar" id="next-track-bar"> <span class="next-track-label">Up next</span> <a class="next-track-link" id="next-track-link" href="#">—</a> </div> <div class="card-footer"> <span class="footer-label" id="footer-label"></span> <div class="waveform-static" id="waveform-static"></div> </div> </div> <script> const cfg = JSON.parse(document.getElementById('track-config').textContent); if (cfg.colors) { const root = document.documentElement; Object.entries(cfg.colors).forEach(([prop, val]) => root.style.setProperty(prop, val)); } document.title = (cfg.title || 'Track') + ' - Winterhits.com'; document.getElementById('track-label').textContent = cfg.label || ''; document.getElementById('track-artist').textContent = cfg.artist || ''; document.getElementById('track-description').textContent = cfg.description || ''; const titleEl = document.getElementById('track-title'); titleEl.textContent = cfg.title || 'Untitled'; if (cfg.subtitle) { const sub = document.createElement('span'); sub.className = 'track-subtitle'; sub.textContent = cfg.subtitle; titleEl.appendChild(sub); } const badgeEl = document.getElementById('format-badge'); if (cfg.format) { badgeEl.textContent = cfg.format; } else { badgeEl.style.display = 'none'; } document.getElementById('artwork-img').src = cfg.artwork ? 'artwork/' + cfg.artwork : ''; document.getElementById('artwork-img').alt = cfg.artworkAlt || cfg.title || ''; const dlBtn = document.getElementById('btn-download'); if (cfg.downloadUrl) { dlBtn.href = cfg.downloadUrl; } else { dlBtn.style.visibility = 'hidden'; } const audio = document.getElementById('audio'); audio.src = cfg.src ? 'audio/' + cfg.src : ''; document.getElementById('footer-label').textContent = 'Marshall Records \u00a9 2001\u2013' + new Date().getFullYear(); const waveHeights = [4,7,12,6,10,14,8,5,11,9,13,6,8,12,5,9,7,11,4,10]; const wf = document.getElementById('waveform-static'); waveHeights.forEach(h => { const s = document.createElement('span'); s.style.height = h + 'px'; wf.appendChild(s); }); function fmt(s) { if (isNaN(s) || !isFinite(s)) return '0:00'; return Math.floor(s/60) + ':' + String(Math.floor(s%60)).padStart(2,'0'); } function setProgress(pct) { document.getElementById('progress-fill').style.width = pct + '%'; document.getElementById('progress-thumb').style.left = pct + '%'; } let playing = false; function togglePlay() { playing ? audio.pause() : audio.play(); } audio.addEventListener('play', () => { playing = true; document.getElementById('icon-play').style.display = 'none'; document.getElementById('icon-pause').style.display = 'block'; document.getElementById('artwork-wrap').classList.add('playing'); }); audio.addEventListener('pause', () => { playing = false; document.getElementById('icon-play').style.display = 'block'; document.getElementById('icon-pause').style.display = 'none'; document.getElementById('artwork-wrap').classList.remove('playing'); }); audio.addEventListener('ended', () => { playing = false; document.getElementById('icon-play').style.display = 'block'; document.getElementById('icon-pause').style.display = 'none'; document.getElementById('artwork-wrap').classList.remove('playing'); setProgress(0); document.getElementById('time-current').textContent = '0:00'; }); audio.addEventListener('timeupdate', () => { if (!audio.duration) return; setProgress((audio.currentTime / audio.duration) * 100); document.getElementById('time-current').textContent = fmt(audio.currentTime); }); audio.addEventListener('loadedmetadata', () => { document.getElementById('time-duration').textContent = fmt(audio.duration); }); const progressTrack = document.getElementById('progress-track'); function seekTo(clientX) { const rect = progressTrack.getBoundingClientRect(); const pct = Math.min(1, Math.max(0, (clientX - rect.left) / rect.width)); if (audio.duration) audio.currentTime = pct * audio.duration; setProgress(pct * 100); } progressTrack.addEventListener('click', e => seekTo(e.clientX)); let dragging = false; progressTrack.addEventListener('touchstart', e => { dragging = true; progressTrack.classList.add('dragging'); seekTo(e.touches[0].clientX); }, { passive: true }); window.addEventListener('touchmove', e => { if (dragging) seekTo(e.touches[0].clientX); }, { passive: true }); window.addEventListener('touchend', () => { if (!dragging) return; dragging = false; progressTrack.classList.remove('dragging'); }); let lastVol = 1, muted = false; function setVolume(v) { audio.volume = +v; lastVol = +v; muted = (+v === 0); updateVolIcon(+v); } function toggleMute() { if (muted) { const v = lastVol || 0.8; audio.volume = v; document.getElementById('vol-slider').value = v; muted = false; updateVolIcon(v); } else { lastVol = audio.volume; audio.volume = 0; document.getElementById('vol-slider').value = 0; muted = true; updateVolIcon(0); } } function updateVolIcon(v) { document.getElementById('vol-wave-1').style.display = v > 0 ? 'block' : 'none'; document.getElementById('vol-wave-2').style.display = v >= 0.5 ? 'block' : 'none'; } fetch('/tracks.json') .then(r => r.json()) .then(tracks => { const currentPath = window.location.pathname.replace(/\/?$/, '/'); const others = tracks.filter(t => t.url.replace(/\/?$/, '/') !== currentPath); if (!others.length) return; const next = others[Math.floor(Math.random() * others.length)]; const link = document.getElementById('next-track-link'); link.textContent = next.title + (next.artist ? ' \u2014 ' + next.artist : ''); link.href = next.url; document.getElementById('next-track-bar').classList.add('ready'); }) .catch(() => {}); </script> </body> </html> HTMLTEMPLATE; return str_replace('%%CONFIG%%', $configJson, $template); } ?><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>Winterhits — Track Creator</title> <style> *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } body { background: #0d0d0d; color: #f0ece4; font-family: monospace; min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem 4rem; } .wrap { width: 100%; max-width: 600px; } h1 { font-size: 0.7rem; letter-spacing: 0.25em; text-transform: uppercase; color: #e8d5a3; margin-bottom: 2rem; padding-bottom: 0.75rem; border-bottom: 1px solid #444444; } .logout { float: right; font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase; color: #aaaaaa; text-decoration: none; } .logout:hover { color: #ffffff; } .error { background: #2a1010; border: 1px solid #7a2020; color: #e07c7c; padding: 0.75rem 1rem; font-size: 0.8rem; margin-bottom: 1.5rem; } .success-box { background: #0f2a10; border: 1px solid #2a7a20; color: #7ce07c; padding: 1.2rem 1rem; font-size: 0.85rem; margin-bottom: 1.5rem; line-height: 1.8; } .success-box a { color: #e8d5a3; } section { margin-bottom: 2rem; padding-bottom: 2rem; border-bottom: 1px solid #444444; } section:last-of-type { border-bottom: none; } h2 { font-size: 0.7rem; letter-spacing: 0.2em; text-transform: uppercase; color: #ffffff; margin-bottom: 1rem; } .field { margin-bottom: 1rem; } label { display: block; font-size: 0.975rem; letter-spacing: 0.08em; text-transform: uppercase; color: #ffffff; margin-bottom: 0.4rem; } label .optional { color: #888888; font-size: 0.7rem; text-transform: none; letter-spacing: 0; } input[type=text], input[type=password], input[type=url], textarea { width: 100%; background: #1a1a1a; border: 1px solid #555555; color: #ffffff; font-family: monospace; font-size: 0.95rem; padding: 0.6rem 0.75rem; outline: none; transition: border-color 0.2s; } input[type=text]:focus, input[type=password]:focus, input[type=url]:focus, textarea:focus { border-color: #e8d5a3; } textarea { resize: vertical; min-height: 80px; line-height: 1.5; } input[type=file] { width: 100%; background: #1a1a1a; border: 1px solid #555555; color: #ffffff; font-family: monospace; font-size: 0.9rem; padding: 0.5rem 0.75rem; cursor: pointer; } .color-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; } .color-field label { margin-bottom: 0.25rem; } .color-input-wrap { display: flex; gap: 0.5rem; align-items: center; } input[type=color] { width: 36px; height: 36px; border: 1px solid #555555; background: #1a1a1a; padding: 2px; cursor: pointer; flex-shrink: 0; } input[type=text].hex { flex: 1; font-size: 0.8rem; } .hint { font-size: 0.7rem; color: #888888; margin-top: 0.3rem; } .submit-btn { width: 100%; background: #e8d5a3; color: #0d0d0d; border: none; font-family: monospace; font-size: 0.7rem; letter-spacing: 0.15em; text-transform: uppercase; padding: 0.9rem; cursor: pointer; transition: opacity 0.2s; margin-top: 1rem; } .submit-btn:hover { opacity: 0.85; } /* login page */ .login-wrap { width: 100%; max-width: 360px; margin: 8rem auto 0; } /* ── inline validation ── */ .field-error { font-size: 0.75rem; color: #e07c7c; margin-top: 0.35rem; display: none; } .field-error.visible { display: block; } input.invalid, textarea.invalid { border-color: #e07c7c !important; } /* ── upload modal ── */ .modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.88); z-index: 1000; align-items: center; justify-content: center; } .modal-backdrop.visible { display: flex; } .modal-box { background: #161616; border: 1px solid #555555; padding: 2.5rem 2rem; width: 90%; max-width: 400px; text-align: center; } .modal-title { font-size: 0.7rem; letter-spacing: 0.2em; text-transform: uppercase; color: #ffffff; margin-bottom: 1rem; } .modal-filename { font-size: 0.7rem; color: #888888; margin-bottom: 1.5rem; word-break: break-all; line-height: 1.4; } .progress-track-modal { width: 100%; height: 4px; background: #2a2a2a; border-radius: 2px; overflow: hidden; margin-bottom: 0.6rem; } .progress-fill-modal { height: 100%; background: #e8d5a3; border-radius: 2px; width: 0%; transition: width 0.25s ease; } .progress-pct { font-size: 1rem; color: #e8d5a3; margin-bottom: 0.75rem; font-family: monospace; } .modal-status { font-size: 0.75rem; min-height: 1.2rem; font-family: monospace; } </style> </head> <body> <div class="wrap"> <?php if ($step === 'login'): ?> <div class="login-wrap"> <h1>Winterhits — Track Creator</h1> <?php if ($error): ?><div class="error"><?= htmlspecialchars($error) ?></div><?php endif; ?> <form method="POST"> <div class="field"> <label for="password">Password</label> <input type="password" id="password" name="password" autofocus autocomplete="current-password"/> </div> <button type="submit" class="submit-btn">Enter</button> </form> </div> <?php elseif ($step === 'done'): ?> <h1>Winterhits — Track Creator <a href="?logout" class="logout">Log out</a></h1> <div class="success-box"> ✓ Track created successfully at <a href="<?= htmlspecialchars($success) ?>" target="_blank"><?= htmlspecialchars($success) ?></a><br> tracks.json has been updated.<br><br> <a href="<?= $_SERVER['PHP_SELF'] ?>">← Create another track</a> </div> <?php else: ?> <h1>Winterhits — Track Creator <a href="?logout" class="logout">Log out</a></h1> <?php if ($error): ?><div class="error"><?= htmlspecialchars($error) ?></div><?php endif; ?> <form method="POST" enctype="multipart/form-data"> <input type="hidden" name="action" value="create"/> <section> <h2>URL & Files</h2> <div class="field"> <label for="slug">URL Slug <span class="optional">(e.g. my-track-name → winterhits.com/my-track-name/)</span></label> <input type="text" id="slug" name="slug" placeholder="my-track-name" value="<?= htmlspecialchars($_POST['slug'] ?? '') ?>"/> <p class="hint">Lowercase letters, numbers and hyphens only. No spaces.</p> <span class="field-error" id="err-slug"></span> </div> <div class="field"> <label for="audio">Audio File <span class="optional">(MP3, WAV or FLAC)</span></label> <input type="file" id="audio" name="audio" accept=".mp3,.wav,.flac,audio/*"/> <span class="field-error" id="err-audio"></span> </div> <div class="field"> <label for="artwork">Artwork <span class="optional">(JPG, PNG or WEBP — square recommended)</span></label> <input type="file" id="artwork" name="artwork" accept=".jpg,.jpeg,.png,.webp,image/*"/> <span class="field-error" id="err-artwork"></span> </div> </section> <section> <h2>Track Info</h2> <div class="field"> <label for="title">Title</label> <input type="text" id="title" name="title" value="<?= htmlspecialchars($_POST['title'] ?? '') ?>"/> <span class="field-error" id="err-title"></span> </div> <div class="field"> <label for="subtitle">Subtitle <span class="optional">(optional — shown below title in light weight)</span></label> <input type="text" id="subtitle" name="subtitle" value="<?= htmlspecialchars($_POST['subtitle'] ?? '') ?>"/> </div> <div class="field"> <label for="artist">Artist</label> <input type="text" id="artist" name="artist" value="<?= htmlspecialchars($_POST['artist'] ?? '') ?>"/> </div> <div class="field"> <label for="label">Label</label> <input type="text" id="label" name="label" value="<?= htmlspecialchars($_POST['label'] ?? 'Marshall Records') ?>"/> </div> <div class="field"> <label for="format">Format Badge <span class="optional">(optional — e.g. FLAC, MARSH' UP)</span></label> <input type="text" id="format" name="format" value="<?= htmlspecialchars($_POST['format'] ?? '') ?>"/> </div> <div class="field"> <label for="description">Description <span class="optional">(optional)</span></label> <textarea id="description" name="description"><?= htmlspecialchars($_POST['description'] ?? '') ?></textarea> </div> <div class="field"> <label for="artworkAlt">Artwork Alt Text <span class="optional">(optional)</span></label> <input type="text" id="artworkAlt" name="artworkAlt" value="<?= htmlspecialchars($_POST['artworkAlt'] ?? '') ?>"/> </div> <div class="field"> <label for="downloadUrl">Download URL <span class="optional">(optional — Bandcamp link etc.)</span></label> <input type="url" id="downloadUrl" name="downloadUrl" value="<?= htmlspecialchars($_POST['downloadUrl'] ?? '') ?>"/> </div> </section> <section> <h2>Colours <span style="color:#4a4a4a;font-size:0.55rem;text-transform:none;letter-spacing:0"> — defaults pre-filled</span></h2> <div class="color-row"> <?php $colorFields = [ 'color_bg' => ['--bg', '#0d0d0d', 'Background'], 'color_surface' => ['--surface', '#161616', 'Card Surface'], 'color_border' => ['--border', '#2a2a2a', 'Border'], 'color_accent' => ['--accent', '#e8d5a3', 'Accent'], 'color_accent_dim' => ['--accent-dim', '#a89060', 'Accent Dim'], 'color_text' => ['--text', '#f0ece4', 'Text'], 'color_text_muted' => ['--text-muted', '#7a7570', 'Text Muted'], 'color_progress_bg' => ['--progress-bg', '#252525', 'Progress BG'], ]; foreach ($colorFields as $name => [$var, $default, $label]): $val = htmlspecialchars($_POST[$name] ?? $default); ?> <div class="color-field field"> <label><?= $label ?></label> <div class="color-input-wrap"> <input type="color" value="<?= $val ?>" oninput="document.getElementById('<?= $name ?>').value=this.value"/> <input type="text" id="<?= $name ?>" name="<?= $name ?>" class="hex" value="<?= $val ?>" maxlength="7" oninput="syncColor(this)"/> </div> </div> <?php endforeach; ?> </div> </section> <button type="button" class="submit-btn" onclick="handleSubmit()">Create Track</button> </form> <?php endif; ?> </div> <!-- ── upload progress modal ────────────────────────────────────────────── --> <div class="modal-backdrop" id="modal"> <div class="modal-box"> <div class="modal-title" id="modal-title">Uploading</div> <div class="modal-filename" id="modal-filename"></div> <div class="progress-track-modal"> <div class="progress-fill-modal" id="modal-bar"></div> </div> <div class="progress-pct" id="modal-pct">0%</div> <div class="modal-status" id="modal-status"></div> </div> </div> <script> // ── colour picker sync ─────────────────────────────────────────────────────── function syncColor(input) { const val = input.value; if (/^#[0-9a-fA-F]{6}$/.test(val)) { input.previousElementSibling.value = val; } } // ── validation ─────────────────────────────────────────────────────────────── function showError(fieldId, errorId, message) { const field = document.getElementById(fieldId); const err = document.getElementById(errorId); if (field) field.classList.add('invalid'); if (err) { err.textContent = message; err.classList.add('visible'); } } function clearErrors() { document.querySelectorAll('.field-error').forEach(el => { el.classList.remove('visible'); el.textContent = ''; }); document.querySelectorAll('.invalid').forEach(el => el.classList.remove('invalid')); } function validate() { clearErrors(); let valid = true; const slug = document.getElementById('slug').value.trim(); if (!slug) { showError('slug', 'err-slug', 'URL slug is required.'); valid = false; } else if (!/^[a-z0-9\-]+$/.test(slug)) { showError('slug', 'err-slug', 'Only lowercase letters, numbers and hyphens.'); valid = false; } const title = document.getElementById('title').value.trim(); if (!title) { showError('title', 'err-title', 'Title is required.'); valid = false; } const audio = document.getElementById('audio').files[0]; if (!audio) { showError('audio', 'err-audio', 'An audio file is required.'); valid = false; } const artwork = document.getElementById('artwork').files[0]; if (!artwork) { showError('artwork', 'err-artwork', 'An artwork image is required.'); valid = false; } return valid; } // ── modal helpers ──────────────────────────────────────────────────────────── function showModal(title, filename) { document.getElementById('modal-title').textContent = title; document.getElementById('modal-filename').textContent = filename; document.getElementById('modal-bar').style.width = '0%'; document.getElementById('modal-pct').textContent = '0%'; document.getElementById('modal-status').textContent = ''; document.getElementById('modal').classList.add('visible'); } function setModalProgress(pct) { const p = Math.round(pct); document.getElementById('modal-bar').style.width = p + '%'; document.getElementById('modal-pct').textContent = p + '%'; } function setModalStatus(msg, isError) { const el = document.getElementById('modal-status'); el.textContent = msg; el.style.color = isError ? '#e07c7c' : '#7ce07c'; } // ── AJAX helpers ───────────────────────────────────────────────────────────── function post(action, formData, onProgress) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); if (onProgress) { xhr.upload.addEventListener('progress', e => { if (e.lengthComputable) onProgress(e.loaded / e.total); }); } xhr.addEventListener('load', () => { try { resolve(JSON.parse(xhr.responseText)); } catch(e) { reject(new Error('Unexpected server response.')); } }); xhr.addEventListener('error', () => reject(new Error('Connection error.'))); formData.append('action', action); xhr.open('POST', window.location.href); xhr.send(formData); }); } // ── three-step submit ───────────────────────────────────────────────────────── async function handleSubmit() { if (!validate()) return; const form = document.querySelector('form'); const audio = document.getElementById('audio').files[0]; const artwork = document.getElementById('artwork').files[0]; // ── STEP 1: setup (text fields only — instant) ──────────────────────────── showModal('Setting up track page...', ''); setModalProgress(0); const setupData = new FormData(form); // send filenames but not the actual files setupData.delete('audio'); setupData.delete('artwork'); setupData.append('audio_name', audio ? audio.name : ''); setupData.append('artwork_name', artwork ? artwork.name : ''); let setupRes; try { setupRes = await post('setup', setupData, null); } catch(e) { setModalStatus('Setup failed: ' + e.message, true); return; } if (!setupRes.ok) { setModalStatus('Error: ' + setupRes.error, true); document.getElementById('modal-title').textContent = 'Setup failed'; setTimeout(() => document.getElementById('modal').classList.remove('visible'), 3500); return; } setModalStatus('\u2713 Page created. Uploading artwork...', false); setModalProgress(5); const slug = setupRes.slug; // ── STEP 2: upload artwork ──────────────────────────────────────────────── const artworkData = new FormData(); artworkData.append('slug', slug); artworkData.append('artwork', artwork); let artworkRes; try { artworkRes = await post('upload_artwork', artworkData, pct => setModalProgress(5 + pct * 15)); } catch(e) { setModalStatus('Artwork upload failed: ' + e.message, true); return; } if (!artworkRes.ok) { setModalStatus('Artwork error: ' + artworkRes.error, true); return; } setModalStatus('\u2713 Artwork uploaded. Uploading audio...', false); setModalProgress(20); // ── STEP 3: upload audio (the big one) ─────────────────────────────────── const audioData = new FormData(); audioData.append('slug', slug); audioData.append('audio', audio); let audioRes; try { audioRes = await post('upload_audio', audioData, pct => setModalProgress(20 + pct * 80)); } catch(e) { setModalStatus('Audio upload failed: ' + e.message + ' — the page is live but audio is missing. Upload the file manually to /' + slug + '/audio/', true); return; } if (!audioRes.ok) { setModalStatus('Audio error: ' + audioRes.error, true); return; } setModalProgress(100); setModalStatus('\u2713 All done! Redirecting...', false); document.getElementById('modal-title').textContent = 'Complete'; setTimeout(() => { window.location.href = audioRes.url; }, 1200); } </script> </body> </html>