basic project skeleton
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
// Dans un vrai projet, ces données viendraient d'une API PeerTube
|
||||
// Pour cet exemple, on utilise des données statiques
|
||||
$featuredVideos = [
|
||||
[
|
||||
'id' => 1,
|
||||
'title' => 'Introduction à la culture libre et aux logiciels open source',
|
||||
'thumbnail' => 'img/video-thumbnails/featured-1.jpg',
|
||||
'duration' => 1245, // en secondes
|
||||
'channel' => 'Tech Libre',
|
||||
'views' => 15420,
|
||||
'date' => '2023-11-15'
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'title' => 'La Réunion: Découverte des sentiers cachés',
|
||||
'thumbnail' => 'img/video-thumbnails/featured-2.jpg',
|
||||
'duration' => 843,
|
||||
'channel' => 'Île Aventure',
|
||||
'views' => 8745,
|
||||
'date' => '2023-12-02'
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'title' => 'Comment installer Linux sur un ancien ordinateur',
|
||||
'thumbnail' => 'img/video-thumbnails/featured-3.jpg',
|
||||
'duration' => 723,
|
||||
'channel' => 'Tech Libre',
|
||||
'views' => 24680,
|
||||
'date' => '2023-10-25'
|
||||
]
|
||||
];
|
||||
|
||||
// Affichage des vidéos
|
||||
foreach ($featuredVideos as $video) :
|
||||
?>
|
||||
<div class="video-card" data-video-id="<?php echo $video['id']; ?>">
|
||||
<div class="video-thumbnail">
|
||||
<img src="<?php echo $video['thumbnail']; ?>" alt="<?php echo $video['title']; ?>" data-src="<?php echo $video['thumbnail']; ?>">
|
||||
<div class="video-duration"><?php echo formatDuration($video['duration']); ?></div>
|
||||
</div>
|
||||
<div class="video-info">
|
||||
<h3 class="video-title"><?php echo $video['title']; ?></h3>
|
||||
<div class="video-channel"><?php echo $video['channel']; ?></div>
|
||||
<div class="video-metadata">
|
||||
<span class="video-views"><?php echo formatViewCount($video['views']); ?> vues</span>
|
||||
<span class="video-date"><?php echo formatDate($video['date']); ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php
|
||||
// Fonctions utilitaires (dans un vrai projet, ces fonctions seraient dans un fichier séparé)
|
||||
function formatDuration($seconds) {
|
||||
$hours = floor($seconds / 3600);
|
||||
$minutes = floor(($seconds % 3600) / 60);
|
||||
$remainingSeconds = $seconds % 60;
|
||||
|
||||
if ($hours > 0) {
|
||||
return sprintf('%d:%02d:%02d', $hours, $minutes, $remainingSeconds);
|
||||
} else {
|
||||
return sprintf('%d:%02d', $minutes, $remainingSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
function formatViewCount($views) {
|
||||
if ($views >= 1000000) {
|
||||
return round($views / 1000000, 1) . 'M';
|
||||
} elseif ($views >= 1000) {
|
||||
return round($views / 1000, 1) . 'K';
|
||||
} else {
|
||||
return $views;
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate($dateString) {
|
||||
$date = new DateTime($dateString);
|
||||
$now = new DateTime();
|
||||
$interval = $now->diff($date);
|
||||
|
||||
if ($interval->days == 0) {
|
||||
return 'Aujourd\'hui';
|
||||
} elseif ($interval->days == 1) {
|
||||
return 'Hier';
|
||||
} elseif ($interval->days < 7) {
|
||||
return 'Il y a ' . $interval->days . ' jours';
|
||||
} elseif ($interval->days < 30) {
|
||||
$weeks = floor($interval->days / 7);
|
||||
return 'Il y a ' . $weeks . ' semaine' . ($weeks > 1 ? 's' : '');
|
||||
} elseif ($interval->days < 365) {
|
||||
$months = floor($interval->days / 30);
|
||||
return 'Il y a ' . $months . ' mois';
|
||||
} else {
|
||||
$years = floor($interval->days / 365);
|
||||
return 'Il y a ' . $years . ' an' . ($years > 1 ? 's' : '');
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user