- Implemented configurable public URL rewriting.
What changed: Added pretty URL helpers/default setting in [includes/db.php](/Users/tyemeclifford/Documents/GH/mediaplayer/includes/db.php). Added root rewrite rules in [.htaccess](/Users/tyemeclifford/Documents/GH/mediaplayer/.htaccess):/v/<slug> /all /search/<query> Added Admin → Settings “Public URL Style” toggle in [admin/settings.php](/Users/tyemeclifford/Documents/GH/mediaplayer/admin/settings.php), defaulting to pretty URLs. Updated public/player/catalogue/embed/admin preview links to use the configured URL style. Added redirects from legacy ?v= and ?q= URLs to pretty routes when rewriting is enabled. Documented deployment and fallback behavior in [README.md](/Users/tyemeclifford/Documents/GH/mediaplayer/README.md).
This commit is contained in:
@@ -3,7 +3,14 @@ require_once __DIR__ . '/includes/db.php';
|
||||
require_once __DIR__ . '/includes/layout.php';
|
||||
|
||||
// Determine which video to play
|
||||
$slug = $_GET['v'] ?? '';
|
||||
$slug = public_video_slug_from_request();
|
||||
if (url_rewrite_enabled() && $slug !== '' && isset($_GET['v']) && ((public_route_segments()[0] ?? '') !== 'v')) {
|
||||
$target = public_video_url($slug);
|
||||
$redirect_page = max(1, (int)($_GET['page'] ?? 1));
|
||||
if ($redirect_page > 1) $target = media_append_query($target, ['page' => (string)$redirect_page]);
|
||||
header('Location: ' . $target, true, 302);
|
||||
exit;
|
||||
}
|
||||
$video = $slug ? get_video_by_slug($slug) : null;
|
||||
|
||||
// Latest video as default if none specified
|
||||
@@ -30,12 +37,6 @@ foreach ($player_sources as $player_source) {
|
||||
if (($player_source['kind'] ?? '') !== 'iframe') $native_player_sources[] = $player_source;
|
||||
}
|
||||
|
||||
// Build absolute base URL used for embed snippet generation
|
||||
$_scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$_host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
||||
$_script = rtrim(dirname($_SERVER['SCRIPT_NAME'] ?? '/'), '/');
|
||||
$_base_url = $_scheme . '://' . $_host . $_script . '/';
|
||||
|
||||
render_head('Media — TyClifford.com', '
|
||||
/* ── Catalogue grid ── */
|
||||
.cat-section { display:flex; flex-direction:column; gap:1rem; }
|
||||
@@ -279,7 +280,7 @@ render_head('Media — TyClifford.com', '
|
||||
</div>
|
||||
|
||||
<?php if ($video):
|
||||
$embed_url = $_base_url . 'embed.php?v=' . urlencode($video['slug']);
|
||||
$embed_url = public_absolute_url('embed.php?v=' . rawurlencode($video['slug']));
|
||||
$iframe_code = '<iframe src="' . $embed_url . '" width="560" height="315" frameborder="0" allowfullscreen allow="fullscreen"></iframe>';
|
||||
?>
|
||||
<div class="embed-panel" id="embed-panel" role="region" aria-label="Embed code">
|
||||
@@ -314,14 +315,14 @@ render_head('Media — TyClifford.com', '
|
||||
<section class="cat-section">
|
||||
<div class="cat-header">
|
||||
<p class="eyebrow eyebrow-purple">Video Catalogue</p>
|
||||
<form class="cat-search" method="get" action="catalogue.php" role="search">
|
||||
<form class="cat-search" method="get" action="<?= h(public_catalogue_url()) ?>" role="search">
|
||||
<input class="form-input" type="search" name="q" placeholder="Search public videos…">
|
||||
<button class="btn btn-secondary btn-sm" type="submit">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
|
||||
Search
|
||||
</button>
|
||||
</form>
|
||||
<a href="catalogue.php" class="btn btn-secondary btn-sm">Browse all →</a>
|
||||
<a href="<?= h(public_catalogue_url()) ?>" class="btn btn-secondary btn-sm">Browse all →</a>
|
||||
</div>
|
||||
|
||||
<?php if (empty($paged['videos'])): ?>
|
||||
@@ -340,9 +341,9 @@ render_head('Media — TyClifford.com', '
|
||||
$vthumb = $v['thumbnail'];
|
||||
$vdur = (int)$v['duration'];
|
||||
$created = substr($v['created_at'], 0, 10);
|
||||
?>
|
||||
?>
|
||||
<a class="cat-thumb <?= $active ? 'active' : '' ?>"
|
||||
href="?v=<?= urlencode($vslug) ?>"
|
||||
href="<?= h(public_video_url($vslug)) ?>"
|
||||
title="<?= h($vtitle) ?>">
|
||||
<div class="cat-active-indicator"></div>
|
||||
<div class="cat-thumb-img">
|
||||
@@ -373,8 +374,7 @@ render_head('Media — TyClifford.com', '
|
||||
· page <?= $paged['page'] ?> of <?= $paged['total_pages'] ?>
|
||||
</span>
|
||||
<?php
|
||||
$url_v = $video ? '&v=' . urlencode($video['slug']) : '';
|
||||
render_pagination($paged['page'], $paged['total_pages'], '?page=%d' . $url_v);
|
||||
render_pagination($paged['page'], $paged['total_pages'], public_player_page_url_pattern($video['slug'] ?? ''));
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
Reference in New Issue
Block a user