- Added ?land=live support for the homepage in [index.php](/Users/tyemeclifford/Documents/GH/mediaplayer/index.php). When live is enabled, visiting the homepage with ?land=live now renders the Live tab active first, hides the normal video player initially, preserves the live mode through homepage pagination, and updates the URL when switching between Videos and Live.
Also updated [README.md](/Users/tyemeclifford/Documents/GH/mediaplayer/README.md) and [changelog.md](/Users/tyemeclifford/Documents/GH/mediaplayer/changelog.md).
This commit is contained in:
@@ -20,8 +20,16 @@ if (!$video) {
|
||||
if ($latest) $video = get_video_by_slug($latest['slug']);
|
||||
}
|
||||
|
||||
$live_enabled = live_enabled();
|
||||
$live_url = $live_enabled ? live_embed_url() : '';
|
||||
$live_title = live_embed_title();
|
||||
$requested_land = strtolower(trim(is_scalar($_GET['land'] ?? '') ? (string)$_GET['land'] : ''));
|
||||
$home_live_first = $live_enabled && $requested_land === 'live';
|
||||
|
||||
if ($video) {
|
||||
$video['view_count'] = increment_video_view_count((int)$video['id']);
|
||||
$video['view_count'] = $home_live_first
|
||||
? (int)($video['view_count'] ?? 0)
|
||||
: increment_video_view_count((int)$video['id']);
|
||||
}
|
||||
|
||||
$show_video_views = setting_bool('public_show_video_views', true);
|
||||
@@ -33,9 +41,6 @@ $public_stats = $show_page_stats ? public_page_stats() : [
|
||||
'sources' => 0,
|
||||
'views' => $total_public_views,
|
||||
];
|
||||
$live_enabled = live_enabled();
|
||||
$live_url = $live_enabled ? live_embed_url() : '';
|
||||
$live_title = live_embed_title();
|
||||
|
||||
$per_page = (int)setting('catalogue_per_page', '10');
|
||||
$page = max(1, (int)($_GET['page'] ?? 1));
|
||||
@@ -55,15 +60,22 @@ foreach ($player_sources as $player_source) {
|
||||
}
|
||||
|
||||
$site_title = setting('site_title', 'Ty Clifford');
|
||||
$share_title = $video ? $video['title'] . ' — ' . $site_title : 'Media — ' . $site_title;
|
||||
$share_description = $video && trim($video['description'] ?? '') !== ''
|
||||
? trim($video['description'])
|
||||
: setting('site_sub', 'tyclifford.com / media');
|
||||
$share_url = $video ? public_absolute_url(public_video_url($video['slug'])) : public_absolute_url(public_home_url());
|
||||
$share_image = ($video && !empty($video['thumbnail'])) ? public_absolute_url(public_media_url($video['thumbnail'])) : '';
|
||||
if ($home_live_first) {
|
||||
$share_title = $live_title . ' — ' . $site_title;
|
||||
$share_description = setting('site_sub', 'tyclifford.com / media');
|
||||
$share_url = public_absolute_url(media_append_query(public_home_url(), ['land' => 'live']));
|
||||
$share_image = '';
|
||||
} else {
|
||||
$share_title = $video ? $video['title'] . ' — ' . $site_title : 'Media — ' . $site_title;
|
||||
$share_description = $video && trim($video['description'] ?? '') !== ''
|
||||
? trim($video['description'])
|
||||
: setting('site_sub', 'tyclifford.com / media');
|
||||
$share_url = $video ? public_absolute_url(public_video_url($video['slug'])) : public_absolute_url(public_home_url());
|
||||
$share_image = ($video && !empty($video['thumbnail'])) ? public_absolute_url(public_media_url($video['thumbnail'])) : '';
|
||||
}
|
||||
$share_image_width = 0;
|
||||
$share_image_height = 0;
|
||||
if ($video && !empty($video['thumbnail']) && function_exists('getimagesize')) {
|
||||
if (!$home_live_first && $video && !empty($video['thumbnail']) && function_exists('getimagesize')) {
|
||||
$share_image_file = MEDIA_DIR . ltrim($video['thumbnail'], '/');
|
||||
if (is_file($share_image_file)) {
|
||||
$share_image_size = @getimagesize($share_image_file);
|
||||
@@ -76,9 +88,9 @@ if ($video && !empty($video['thumbnail']) && function_exists('getimagesize')) {
|
||||
$share_meta = [
|
||||
'description' => $share_description,
|
||||
'url' => $share_url,
|
||||
'type' => $video ? 'video.other' : 'website',
|
||||
'type' => ($video && !$home_live_first) ? 'video.other' : 'website',
|
||||
'image' => $share_image,
|
||||
'image_alt' => $video ? $video['title'] : $site_title,
|
||||
'image_alt' => $home_live_first ? $live_title : ($video ? $video['title'] : $site_title),
|
||||
'image_width' => $share_image_width,
|
||||
'image_height' => $share_image_height,
|
||||
];
|
||||
@@ -304,11 +316,11 @@ render_head($share_title, '
|
||||
|
||||
<?php if ($live_enabled): ?>
|
||||
<div class="home-mode-toggle" role="tablist" aria-label="Homepage media mode">
|
||||
<button type="button" class="active" data-home-mode="videos" role="tab" aria-selected="true" aria-controls="home-video-panel">Videos</button>
|
||||
<button type="button" data-home-mode="live" role="tab" aria-selected="false" aria-controls="home-live-panel">Live</button>
|
||||
<button type="button" class="<?= $home_live_first ? '' : 'active' ?>" data-home-mode="videos" role="tab" aria-selected="<?= $home_live_first ? 'false' : 'true' ?>" aria-controls="home-video-panel">Videos</button>
|
||||
<button type="button" class="<?= $home_live_first ? 'active' : '' ?>" data-home-mode="live" role="tab" aria-selected="<?= $home_live_first ? 'true' : 'false' ?>" aria-controls="home-live-panel">Live</button>
|
||||
</div>
|
||||
|
||||
<section class="stream-card home-mode-panel" id="home-live-panel" aria-label="Live stream" hidden>
|
||||
<section class="stream-card home-mode-panel" id="home-live-panel" aria-label="Live stream" <?= $home_live_first ? '' : 'hidden' ?>>
|
||||
<div class="stream-ratio">
|
||||
<iframe class="provider-embed-frame"
|
||||
src="<?= h($live_url) ?>"
|
||||
@@ -325,7 +337,7 @@ render_head($share_title, '
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- ═══════════════════════════ PLAYER CARD ════════════════════════════════ -->
|
||||
<section class="stream-card home-mode-panel" id="home-video-panel" aria-label="Media player">
|
||||
<section class="stream-card home-mode-panel" id="home-video-panel" aria-label="Media player" <?= $home_live_first ? 'hidden' : '' ?>>
|
||||
<div class="stream-ratio">
|
||||
<?php if ($primary_player_source && ($primary_player_source['kind'] ?? '') === 'iframe'): ?>
|
||||
<iframe class="provider-embed-frame"
|
||||
@@ -476,7 +488,9 @@ render_head($share_title, '
|
||||
· page <?= $paged['page'] ?> of <?= $paged['total_pages'] ?>
|
||||
</span>
|
||||
<?php
|
||||
render_pagination($paged['page'], $paged['total_pages'], public_player_page_url_pattern($video['slug'] ?? ''));
|
||||
$player_page_base = ($slug !== '' && $video) ? public_video_url($video['slug']) : public_home_url();
|
||||
if ($home_live_first) $player_page_base = media_append_query($player_page_base, ['land' => 'live']);
|
||||
render_pagination($paged['page'], $paged['total_pages'], public_page_url_pattern($player_page_base));
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
@@ -578,16 +592,26 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
var modeButtons = document.querySelectorAll('[data-home-mode]');
|
||||
var livePanel = document.getElementById('home-live-panel');
|
||||
var videoPanel = document.getElementById('home-video-panel');
|
||||
|
||||
function setHomeMode(mode, updateUrl) {
|
||||
modeButtons.forEach(function(other) {
|
||||
var active = other.getAttribute('data-home-mode') === mode;
|
||||
other.classList.toggle('active', active);
|
||||
other.setAttribute('aria-selected', active ? 'true' : 'false');
|
||||
});
|
||||
if (livePanel) livePanel.hidden = mode !== 'live';
|
||||
if (videoPanel) videoPanel.hidden = mode === 'live';
|
||||
if (updateUrl && window.history && typeof window.URL !== 'undefined') {
|
||||
var url = new URL(window.location.href);
|
||||
if (mode === 'live') url.searchParams.set('land', 'live');
|
||||
else url.searchParams.delete('land');
|
||||
window.history.replaceState({}, '', url.pathname + url.search + url.hash);
|
||||
}
|
||||
}
|
||||
|
||||
modeButtons.forEach(function(btn) {
|
||||
btn.addEventListener('click', function() {
|
||||
var mode = btn.getAttribute('data-home-mode');
|
||||
modeButtons.forEach(function(other) {
|
||||
var active = other === btn;
|
||||
other.classList.toggle('active', active);
|
||||
other.setAttribute('aria-selected', active ? 'true' : 'false');
|
||||
});
|
||||
if (livePanel) livePanel.hidden = mode !== 'live';
|
||||
if (videoPanel) videoPanel.hidden = mode === 'live';
|
||||
setHomeMode(btn.getAttribute('data-home-mode'), true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user