1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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>
|