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/vibe.php | |
| download | www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.tar.gz www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.zip | |
Diffstat (limited to 'partials/vibe.php')
| -rw-r--r-- | partials/vibe.php | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/partials/vibe.php b/partials/vibe.php new file mode 100644 index 0000000..84b148a --- /dev/null +++ b/partials/vibe.php @@ -0,0 +1,73 @@ +<?php +$vibe = file_exists(__DIR__ . '/../vibe.php') + ? require __DIR__ . '/../vibe.php' + : ['description' => '', 'url' => '', 'updated' => '']; + +$vibe_desc = htmlspecialchars($vibe['description'] ?? '', ENT_QUOTES, 'UTF-8'); +$vibe_url = $vibe['url'] ?? ''; +$safe_url = htmlspecialchars($vibe_url, ENT_QUOTES, 'UTF-8'); + +function vibe_detect_type(string $url): string { + if (empty($url)) return 'none'; + $path = strtolower(parse_url($url, PHP_URL_PATH) ?? ''); + $ext = pathinfo($path, PATHINFO_EXTENSION); + if (in_array($ext, ['jpg','jpeg','png','gif','webp','bmp','svg','avif'])) return 'image'; + if (in_array($ext, ['mp4','webm','ogv','mov'])) return 'video'; + if (in_array($ext, ['mp3','flac','wav','ogg','aac','opus','m4a'])) 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'; +} + +$type = vibe_detect_type($vibe_url); +?> + +<section aria-labelledby="vibe-title"> + <h2 id="vibe-title">My Current Vibe</h2> + + <?php if ($vibe_desc): ?> + <p><?= $vibe_desc ?></p> + <?php endif; ?> + + <?php if ($vibe_url): ?> + + <?php if ($type === 'image'): ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <img src="<?= $safe_url ?>" alt="Current vibe" style="max-width:100%;height:auto;" loading="lazy"> + + <?php elseif ($type === 'video'): ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <video controls style="max-width:100%;" preload="none"> + <source src="<?= $safe_url ?>"> + </video> + + <?php elseif ($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($type, 'youtube:')): ?> + <?php $yt_id = substr($type, 8); ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <div style="position:relative;padding-top:56.25%;overflow:hidden;"> + <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($type, 'vimeo:')): ?> + <?php $vimeo_id = substr($type, 6); ?> + <p><a href="<?= $safe_url ?>" target="_blank" rel="noopener noreferrer"><?= $safe_url ?></a></p> + <div style="position:relative;padding-top:56.25%;overflow:hidden;"> + <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; ?> + + <?php endif; ?> +</section> |
