feat: add À la une feature

This commit is contained in:
2026-01-14 16:51:44 +04:00
parent 66de41b118
commit 10f0b9a6eb
6 changed files with 149 additions and 34 deletions
+1 -1
View File
@@ -641,7 +641,7 @@ img {
.hero-video-info {
position: absolute;
bottom: 70px;
bottom: 0;
left: 0;
width: 100%;
background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
+30 -15
View File
@@ -14,8 +14,9 @@ require_once 'includes/structured-data.php';
// Appliquer les en-têtes de sécurité
setSecurityHeaders();
// Vérifier s'il y a un direct en cours
$liveStream = getLiveStream();
// Récupérer la vidéo à afficher selon le mode configuré
$displayData = getDisplayVideo();
$video = $displayData['video'];
?>
<!DOCTYPE html>
<html lang="fr">
@@ -114,39 +115,53 @@ $liveStream = getLiveStream();
<div class="live-container">
<?php
// Vérifier s'il y a un direct en cours
$liveStream = getLiveStream();
// Récupérer les données d'affichage
$isLive = $displayData['isLive'];
$badge = $displayData['badge'];
$mode = $displayData['mode'];
if ($liveStream) {
// Afficher le direct en cours
if ($video) {
// Construire les paramètres de l'iframe selon le mode
$iframeParams = '';
if ($mode === 'auto' && $isLive) {
// Mode auto avec direct : autoplay
$iframeParams = '?autoplay=1';
}
// Mode static : pas d'autoplay
// Afficher la vidéo
?>
<div class="live-badge large">
<i class="fas fa-circle"></i> EN DIRECT
<?php if ($isLive): ?>
<i class="fas fa-circle"></i> <?php echo htmlspecialchars($badge); ?>
<?php else: ?>
<?php echo htmlspecialchars($badge); ?>
<?php endif; ?>
</div>
<div class="live-player">
<iframe
src="<?php echo PEERTUBE_URL; ?>/videos/embed/<?php echo $liveStream['id']; ?>?autoplay=1"
src="<?php echo PEERTUBE_URL; ?>/videos/embed/<?php echo $video['id']; ?><?php echo $iframeParams; ?>"
frameborder="0"
allowfullscreen="allowfullscreen"
allow="autoplay; fullscreen"
title="<?php echo htmlspecialchars($liveStream['title']); ?>">
title="<?php echo htmlspecialchars($video['title']); ?>">
</iframe>
</div>
<div class="live-info">
<h1 class="live-title"><?php echo htmlspecialchars($liveStream['title']); ?></h1>
<h1 class="live-title"><?php echo htmlspecialchars($video['title']); ?></h1>
<div class="live-channel-info">
<?php if (strpos($liveStream['channelAvatar'], 'default-avatar.png') !== false || empty($liveStream['channelAvatar'])): ?>
<?php if (strpos($video['channelAvatar'], 'default-avatar.png') !== false || empty($video['channelAvatar'])): ?>
<div class="channel-avatar-placeholder">
<i class="fas fa-user-circle"></i>
</div>
<?php else: ?>
<img src="<?php echo $liveStream['channelAvatar']; ?>" alt="<?php echo $liveStream['channel']; ?>" class="channel-avatar">
<img src="<?php echo $video['channelAvatar']; ?>" alt="<?php echo $video['channel']; ?>" class="channel-avatar">
<?php endif; ?>
<span class="channel-name"><?php echo $liveStream['channel']; ?></span>
<span class="channel-name"><?php echo $video['channel']; ?></span>
</div>
<?php if (!empty($liveStream['description'])): ?>
<?php if (!empty($video['description'])): ?>
<div class="live-description">
<?php echo markdown_to_html($liveStream['description']); ?>
<?php echo markdown_to_html($video['description']); ?>
</div>
<?php endif; ?>
</div>
+9
View File
@@ -98,6 +98,15 @@ if (!defined('CACHE_DURATION')) define('CACHE_DURATION', 3600); // En secondes (
// Compte pour les lives
if (!defined('LIVE_ACCOUNT_NAME')) define('LIVE_ACCOUNT_NAME', 'admin');
// Mode d'affichage de la section live/vidéo : 'auto' (détection automatique du direct) ou 'static' (vidéo fixe)
if (!defined('LIVE_MODE')) define('LIVE_MODE', 'auto');
// ID de la vidéo à afficher en mode 'static' (ex: 'abc123-def456-ghi789')
if (!defined('STATIC_VIDEO_ID')) define('STATIC_VIDEO_ID', '');
// Texte du badge à afficher en mode 'static' (ex: 'À LA UNE', 'REPLAY', etc.)
if (!defined('STATIC_VIDEO_BADGE')) define('STATIC_VIDEO_BADGE', 'À LA UNE');
// Tags pour filtrer les vidéos selon les catégories
if (!defined('TAG_SHORT')) define('TAG_SHORT', 'short');
+14
View File
@@ -26,6 +26,20 @@
// Compte PeerTube pour les lives
// define('LIVE_ACCOUNT_NAME', 'admin');
// Mode d'affichage de la section live/vidéo
// 'auto' : Détection automatique du direct en cours
// 'static' : Afficher une vidéo spécifique (définie par STATIC_VIDEO_ID)
// define('LIVE_MODE', 'auto');
// ID de la vidéo à afficher en mode 'static'
// Pour trouver l'ID : https://votre-instance.fr/videos/watch/ID_DE_LA_VIDEO
// Exemple : '9c9de5e8-0a1e-484a-b099-e80766180a6d'
// define('STATIC_VIDEO_ID', '');
// Texte du badge à afficher en mode 'static'
// Exemples : 'À LA UNE', 'REPLAY', 'VIDÉO SPÉCIALE', etc.
// define('STATIC_VIDEO_BADGE', 'À LA UNE');
// =========================================
// Filtres et tags
// =========================================
+61
View File
@@ -397,6 +397,67 @@ function getLiveStream() {
return !empty($activeLives) ? reset($activeLives) : null;
}
/**
* Récupère une vidéo spécifique par son ID
*
* @param string $videoId ID de la vidéo
* @return array|null Informations sur la vidéo ou null si non trouvée
*/
function getVideoById($videoId) {
if (empty($videoId)) {
return null;
}
$data = callPeerTubeApi('videos/' . $videoId);
// Vérifier si on a des résultats
if (empty($data)) {
return null;
}
// Formater les données de la vidéo
$videoData = formatVideosData([$data]);
// Retourner la première vidéo formatée
return !empty($videoData) ? reset($videoData) : null;
}
/**
* Récupère la vidéo à afficher selon le mode configuré (auto ou static)
*
* En mode 'auto' : détecte automatiquement un direct en cours
* En mode 'static' : affiche une vidéo spécifique définie par STATIC_VIDEO_ID
*
* @return array|null Tableau avec 'video' (données de la vidéo ou null), 'mode' ('auto'|'static'), 'isLive' (bool), 'badge' (texte du badge)
*/
function getDisplayVideo() {
$mode = defined('LIVE_MODE') ? LIVE_MODE : 'auto';
if ($mode === 'static') {
// Mode vidéo statique
$videoId = defined('STATIC_VIDEO_ID') ? STATIC_VIDEO_ID : '';
$video = getVideoById($videoId);
$badge = defined('STATIC_VIDEO_BADGE') ? STATIC_VIDEO_BADGE : 'À LA UNE';
return [
'video' => $video,
'mode' => 'static',
'isLive' => false,
'badge' => $badge
];
} else {
// Mode automatique (détection de direct)
$video = getLiveStream();
return [
'video' => $video,
'mode' => 'auto',
'isLive' => $video !== null,
'badge' => 'DIRECT'
];
}
}
/**
* Formate les données brutes des vidéos venant de l'API
*
+30 -14
View File
@@ -105,39 +105,55 @@ setSecurityHeaders();
<section class="hero" aria-labelledby="live-section-title">
<h2 id="live-section-title" class="sr-only">Diffusion en direct</h2>
<?php
// Vérifier s'il y a un direct en cours
$liveStream = getLiveStream();
// Récupérer la vidéo à afficher selon le mode configuré
$displayData = getDisplayVideo();
$video = $displayData['video'];
$isLive = $displayData['isLive'];
$badge = $displayData['badge'];
$mode = $displayData['mode'];
if ($liveStream) {
// Afficher le direct en cours
if ($video) {
// Construire les paramètres de l'iframe selon le mode
$iframeParams = '';
if ($mode === 'auto' && $isLive) {
// Mode auto avec direct : autoplay + muted
$iframeParams = '?autoplay=1&muted=1';
}
// Mode static : pas d'autoplay (iframe params reste vide)
// Afficher la vidéo
?>
<div class="live-badge">
<i class="fas fa-circle"></i> DIRECT
<?php if ($isLive): ?>
<i class="fas fa-circle"></i> <?php echo htmlspecialchars($badge); ?>
<?php else: ?>
<?php echo htmlspecialchars($badge); ?>
<?php endif; ?>
</div>
<div class="hero-video-container">
<iframe
src="<?php echo PEERTUBE_URL; ?>/videos/embed/<?php echo $liveStream['id']; ?>?autoplay=1&muted=1"
src="<?php echo PEERTUBE_URL; ?>/videos/embed/<?php echo $video['id']; ?><?php echo $iframeParams; ?>"
frameborder="0"
allowfullscreen="allowfullscreen"
allow="autoplay; fullscreen"
title="Diffusion en direct: <?php echo htmlspecialchars($liveStream['title']); ?>"
aria-describedby="live-description">
title="<?php echo htmlspecialchars($video['title']); ?>"
aria-describedby="video-description">
</iframe>
<div id="live-description" class="sr-only">
Lecteur vidéo pour la diffusion en direct de <?php echo htmlspecialchars($liveStream['channel']); ?>
<div id="video-description" class="sr-only">
Lecteur vidéo pour <?php echo htmlspecialchars($video['title']); ?> de <?php echo htmlspecialchars($video['channel']); ?>
</div>
</div>
<div class="hero-video-info">
<h2><?php echo htmlspecialchars($liveStream['title']); ?></h2>
<h2><?php echo htmlspecialchars($video['title']); ?></h2>
<div class="hero-channel-info">
<?php if (strpos($liveStream['channelAvatar'], 'default-avatar.png') !== false || empty($liveStream['channelAvatar'])): ?>
<?php if (strpos($video['channelAvatar'], 'default-avatar.png') !== false || empty($video['channelAvatar'])): ?>
<div class="channel-avatar-placeholder" role="img" aria-label="Avatar par défaut">
<i class="fas fa-user-circle" aria-hidden="true"></i>
</div>
<?php else: ?>
<img src="<?php echo $liveStream['channelAvatar']; ?>" alt="Avatar de la chaîne <?php echo htmlspecialchars($liveStream['channel']); ?>" class="channel-avatar">
<img src="<?php echo $video['channelAvatar']; ?>" alt="Avatar de la chaîne <?php echo htmlspecialchars($video['channel']); ?>" class="channel-avatar">
<?php endif; ?>
<span class="channel-name"><?php echo htmlspecialchars($liveStream['channel']); ?></span>
<span class="channel-name"><?php echo htmlspecialchars($video['channel']); ?></span>
</div>
</div>
<?php