diff options
| author | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
|---|---|---|
| committer | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
| commit | 898b52edcb47bcb3e9d6106e74ca73e74ea01e70 (patch) | |
| tree | 85c6ee5ad58b860144551184d4cf86b560c62b91 /partials/admin_vibe.php | |
| download | www-main.tar.gz www-main.zip | |
Diffstat (limited to '')
| -rw-r--r-- | partials/admin_vibe.php | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/partials/admin_vibe.php b/partials/admin_vibe.php new file mode 100644 index 0000000..74227c3 --- /dev/null +++ b/partials/admin_vibe.php @@ -0,0 +1,201 @@ +<?php +// admin/vibe.php — admin editor for "My Current Vibe" section +// Requires an active session with $_SESSION['admin'] === true (your existing auth). + +require_once __DIR__ . '/session.php'; + +if (empty($_SESSION['admin'])) { + header('Location: /admin/login.php'); + exit; +} + +$vibe_file = __DIR__ . '/../vibe.php'; + +// Load existing config +$vibe = file_exists($vibe_file) + ? require $vibe_file + : ['description' => '', 'url' => '', 'updated' => '']; + +$errors = []; +$success = false; + +// Handle POST save +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $desc = trim($_POST['description'] ?? ''); + $url = trim($_POST['url'] ?? ''); + $updated = date('Y-m-d'); + + // Basic URL validation (allow empty) + if ($url !== '' && !filter_var($url, FILTER_VALIDATE_URL)) { + $errors[] = 'URL does not appear to be valid.'; + } + + if (empty($errors)) { + $export = var_export([ + 'description' => $desc, + 'url' => $url, + 'updated' => $updated, + ], true); + + $content = "<?php\n// vibe.php — current vibe config, edited via admin/vibe.php\n// Do not edit manually unless you know what you're doing.\n\nreturn {$export};\n"; + + if (file_put_contents($vibe_file, $content) !== false) { + $success = true; + $vibe = ['description' => $desc, 'url' => $url, 'updated' => $updated]; + } else { + $errors[] = 'Could not write vibe.php — check file permissions.'; + } + } +} + +// Detect embed type for preview +function admin_vibe_detect_type(string $url): string { + if (empty($url)) return 'none'; + $path = strtolower(parse_url($url, PHP_URL_PATH) ?? ''); + $ext = pathinfo($path, PATHINFO_EXTENSION); + $images = ['jpg','jpeg','png','gif','webp','bmp','svg','avif']; + $videos = ['mp4','webm','ogv','mov']; + $audio = ['mp3','flac','wav','ogg','aac','opus','m4a']; + if (in_array($ext, $images)) return 'image'; + if (in_array($ext, $videos)) return 'video'; + if (in_array($ext, $audio)) return 'audio'; + if (preg_match('/(?:youtube\.com\/watch\?.*v=|youtu\.be\/)([A-Za-z0-9_-]{11})/', $url, $m)) return 'youtube:' . $m[1]; + if (preg_match('/vimeo\.com\/(\d+)/', $url, $m)) return 'vimeo:' . $m[1]; + return 'link'; +} + +$preview_type = admin_vibe_detect_type($vibe['url'] ?? ''); +$safe_url = htmlspecialchars($vibe['url'] ?? '', ENT_QUOTES, 'UTF-8'); + +// Human-readable label for detected type +function type_label(string $type): string { + if ($type === 'none') return '—'; + if ($type === 'image') return 'Image'; + if ($type === 'video') return 'Video'; + if ($type === 'audio') return 'Audio'; + if ($type === 'link') return 'Plain link'; + if (str_starts_with($type, 'youtube:')) return 'YouTube embed'; + if (str_starts_with($type, 'vimeo:')) return 'Vimeo embed'; + return 'Unknown'; +} +?> +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width,initial-scale=1" /> + <title>Edit Current Vibe — SillyLaird</title> + <link rel="stylesheet" href="/assets/css/fonts.css" /> + <link rel="stylesheet" href="/assets/css/site.css?v=1.5" /> + <style> + .admin-wrap { max-width: 640px; margin: 2rem auto; padding: 0 1rem; } + .field { margin-bottom: 1.25rem; } + .field label { display: block; margin-bottom: 0.35rem; font-weight: bold; font-size: 0.9em; } + .field input, + .field textarea { width: 100%; box-sizing: border-box; font-family: inherit; font-size: 1rem; padding: 0.45rem 0.6rem; border: 1px solid #555; background: #111; color: #eee; border-radius: 3px; } + .field textarea { resize: vertical; min-height: 80px; } + .detect-badge { display: inline-block; margin-top: 0.4rem; font-size: 0.8em; padding: 2px 8px; border: 1px solid #555; border-radius: 3px; color: #aaa; } + .btn-save { padding: 0.5rem 1.4rem; font-size: 1rem; cursor: pointer; } + .notice-ok { color: #7f7; border: 1px solid #484; padding: 0.5rem 0.8rem; border-radius: 3px; margin-bottom: 1rem; } + .notice-err { color: #f77; border: 1px solid #844; padding: 0.5rem 0.8rem; border-radius: 3px; margin-bottom: 1rem; } + .preview-box { margin-top: 1.5rem; border-top: 1px solid #333; padding-top: 1rem; } + .preview-box h3 { margin-bottom: 0.75rem; font-size: 0.95em; color: #aaa; text-transform: uppercase; letter-spacing: 0.05em; } + .preview-box img, + .preview-box video, + .preview-box audio { max-width: 100%; display: block; margin-top: 0.5rem; } + .preview-box iframe { width: 100%; border: 0; display: block; margin-top: 0.5rem; } + .back-link { font-size: 0.85em; margin-bottom: 1.5rem; display: inline-block; } + </style> +</head> +<body> +<div class="admin-wrap"> + <a class="back-link" href="/admin/">← Back to admin</a> + <h1>Edit: My Current Vibe</h1> + + <?php if ($success): ?> + <p class="notice-ok">✓ Saved successfully.</p> + <?php endif; ?> + + <?php if (!empty($errors)): ?> + <div class="notice-err"> + <?php foreach ($errors as $e): ?> + <p><?= htmlspecialchars($e, ENT_QUOTES, 'UTF-8') ?></p> + <?php endforeach; ?> + </div> + <?php endif; ?> + + <form method="post" action=""> + <div class="field"> + <label for="description">Description / caption</label> + <textarea id="description" name="description" rows="3"><?= htmlspecialchars($vibe['description'] ?? '', ENT_QUOTES, 'UTF-8') ?></textarea> + </div> + + <div class="field"> + <label for="url">URL (image, video, audio, YouTube, Vimeo, or plain link)</label> + <input + type="url" + id="url" + name="url" + value="<?= $safe_url ?>" + placeholder="https://uploads.sillylaird.ca/..." + autocomplete="off" + /> + <span class="detect-badge"> + Detected type: <strong><?= type_label($preview_type) ?></strong> + </span> + </div> + + <?php if ($vibe['updated'] ?? ''): ?> + <p class="muted" style="font-size:0.85em;">Last saved: <?= htmlspecialchars($vibe['updated'], ENT_QUOTES, 'UTF-8') ?></p> + <?php endif; ?> + + <button class="btn-save" type="submit">Save Vibe</button> + </form> + + <?php if (!empty($vibe['url'])): ?> + <div class="preview-box"> + <h3>Current Preview</h3> + + <?php if ($preview_type === 'image'): ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <img src="<?= $safe_url ?>" alt="Vibe preview" loading="lazy"> + + <?php elseif ($preview_type === 'video'): ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <video controls preload="none" style="max-width:100%;"> + <source src="<?= $safe_url ?>"> + </video> + + <?php elseif ($preview_type === 'audio'): ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <audio controls preload="none" style="width:100%;"> + <source src="<?= $safe_url ?>"> + </audio> + + <?php elseif (str_starts_with($preview_type, 'youtube:')): ?> + <?php $yt_id = substr($preview_type, 8); ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <div style="position:relative;padding-top:56.25%;"> + <iframe src="https://www.youtube.com/embed/<?= htmlspecialchars($yt_id) ?>" + style="position:absolute;top:0;left:0;width:100%;height:100%;border:0;" + allowfullscreen loading="lazy"></iframe> + </div> + + <?php elseif (str_starts_with($preview_type, 'vimeo:')): ?> + <?php $vimeo_id = substr($preview_type, 6); ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <div style="position:relative;padding-top:56.25%;"> + <iframe src="https://player.vimeo.com/video/<?= htmlspecialchars($vimeo_id) ?>" + style="position:absolute;top:0;left:0;width:100%;height:100%;border:0;" + allowfullscreen loading="lazy"></iframe> + </div> + + <?php else: ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <?php endif; ?> + </div> + <?php endif; ?> + +</div> +</body> +</html> |
