292 lines
12 KiB
PHP
292 lines
12 KiB
PHP
|
|
<?php
|
||
|
|
// Récupération de la requête de recherche
|
||
|
|
$query = isset($_GET['q']) ? htmlspecialchars($_GET['q']) : '';
|
||
|
|
|
||
|
|
// Dans un vrai projet, ces données viendraient d'une API PeerTube
|
||
|
|
// Pour cet exemple, on utilise des données statiques
|
||
|
|
$videos = [
|
||
|
|
[
|
||
|
|
'id' => 1,
|
||
|
|
'title' => 'Introduction à la culture libre et aux logiciels open source',
|
||
|
|
'thumbnail' => 'img/video-thumbnails/featured-1.jpg',
|
||
|
|
'duration' => 1245,
|
||
|
|
'channel' => 'Tech Libre',
|
||
|
|
'views' => 15420,
|
||
|
|
'date' => '2023-11-15',
|
||
|
|
'description' => 'Une introduction complète au monde de la culture libre et des logiciels open source. Découvrez les principes fondamentaux, les licences, et comment contribuer à des projets open source.',
|
||
|
|
'tags' => ['open source', 'logiciels libres', 'tech', 'formation']
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'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',
|
||
|
|
'description' => 'Partez à la découverte des sentiers cachés de La Réunion. Cette vidéo vous guide à travers des paysages magnifiques et peu connus de l\'île.',
|
||
|
|
'tags' => ['La Réunion', 'voyage', 'randonnée', 'nature']
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'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',
|
||
|
|
'description' => 'Tutoriel détaillé pour installer une distribution Linux légère sur un ancien ordinateur et lui donner une seconde vie.',
|
||
|
|
'tags' => ['linux', 'tutoriel', 'open source', 'recyclage']
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'id' => 4,
|
||
|
|
'title' => 'Festival Sakifo 2023 - Les meilleurs moments',
|
||
|
|
'thumbnail' => 'img/video-thumbnails/recent-1.jpg',
|
||
|
|
'duration' => 1832,
|
||
|
|
'channel' => 'Culture 974',
|
||
|
|
'views' => 3420,
|
||
|
|
'date' => '2023-12-15',
|
||
|
|
'description' => 'Revivez les meilleurs moments du Festival Sakifo 2023 à Saint-Pierre, avec les performances des artistes locaux et internationaux.',
|
||
|
|
'tags' => ['musique', 'festival', 'sakifo', 'La Réunion']
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'id' => 5,
|
||
|
|
'title' => 'Cuisine créole: Recette du rougail saucisse traditionnel',
|
||
|
|
'thumbnail' => 'img/video-thumbnails/recent-2.jpg',
|
||
|
|
'duration' => 685,
|
||
|
|
'channel' => 'Saveurs des Îles',
|
||
|
|
'views' => 7245,
|
||
|
|
'date' => '2023-12-10',
|
||
|
|
'description' => 'Apprenez à préparer un délicieux rougail saucisse traditionnel de La Réunion, avec tous les secrets pour réussir ce plat emblématique.',
|
||
|
|
'tags' => ['cuisine', 'recette', 'La Réunion', 'créole']
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'id' => 6,
|
||
|
|
'title' => 'Tutoriel: Créer votre première application web avec PHP',
|
||
|
|
'thumbnail' => 'img/video-thumbnails/recent-3.jpg',
|
||
|
|
'duration' => 1540,
|
||
|
|
'channel' => 'CodeMastery',
|
||
|
|
'views' => 2180,
|
||
|
|
'date' => '2023-12-08',
|
||
|
|
'description' => 'Un guide pas à pas pour créer votre première application web en PHP, depuis l\'installation de l\'environnement jusqu\'au déploiement.',
|
||
|
|
'tags' => ['php', 'web', 'programmation', 'tutoriel']
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'id' => 7,
|
||
|
|
'title' => 'Les plus belles plages de La Réunion en 2023',
|
||
|
|
'thumbnail' => 'img/video-thumbnails/recent-4.jpg',
|
||
|
|
'duration' => 925,
|
||
|
|
'channel' => 'Île Aventure',
|
||
|
|
'views' => 5690,
|
||
|
|
'date' => '2023-12-05',
|
||
|
|
'description' => 'Découvrez les plus belles plages de La Réunion, des lagons de l\'ouest aux côtes sauvages du sud, avec des conseils pour chaque site.',
|
||
|
|
'tags' => ['plages', 'La Réunion', 'voyage', 'mer']
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'id' => 8,
|
||
|
|
'title' => 'Débat: L\'avenir du numérique à La Réunion',
|
||
|
|
'thumbnail' => 'img/video-thumbnails/recent-5.jpg',
|
||
|
|
'duration' => 3245,
|
||
|
|
'channel' => 'Tech Libre',
|
||
|
|
'views' => 1250,
|
||
|
|
'date' => '2023-12-01',
|
||
|
|
'description' => 'Un débat passionnant sur l\'avenir du numérique à La Réunion, avec des intervenants du secteur public et privé qui discutent des enjeux et opportunités.',
|
||
|
|
'tags' => ['numérique', 'La Réunion', 'débat', 'technologie']
|
||
|
|
],
|
||
|
|
[
|
||
|
|
'id' => 9,
|
||
|
|
'title' => 'Concert live: Groupe Sakili au Téat Plein Air',
|
||
|
|
'thumbnail' => 'img/video-thumbnails/recent-6.jpg',
|
||
|
|
'duration' => 4512,
|
||
|
|
'channel' => 'Culture 974',
|
||
|
|
'views' => 4325,
|
||
|
|
'date' => '2023-11-28',
|
||
|
|
'description' => 'Le concert complet du groupe Sakili au Téat Plein Air de Saint-Gilles, un moment magique de musique traditionnelle réunionnaise revisitée.',
|
||
|
|
'tags' => ['concert', 'musique', 'La Réunion', 'maloya']
|
||
|
|
]
|
||
|
|
];
|
||
|
|
|
||
|
|
// Fonction de recherche simple (dans un vrai projet, ce serait géré par l'API)
|
||
|
|
function searchVideos($videos, $query) {
|
||
|
|
if (empty($query)) return [];
|
||
|
|
|
||
|
|
$results = [];
|
||
|
|
$lowercaseQuery = strtolower($query);
|
||
|
|
|
||
|
|
foreach ($videos as $video) {
|
||
|
|
// Recherche dans le titre
|
||
|
|
if (strpos(strtolower($video['title']), $lowercaseQuery) !== false) {
|
||
|
|
$results[] = $video;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Recherche dans la description
|
||
|
|
if (strpos(strtolower($video['description']), $lowercaseQuery) !== false) {
|
||
|
|
$results[] = $video;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Recherche dans les tags
|
||
|
|
foreach ($video['tags'] as $tag) {
|
||
|
|
if (strpos(strtolower($tag), $lowercaseQuery) !== false) {
|
||
|
|
$results[] = $video;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Recherche dans le nom de la chaîne
|
||
|
|
if (strpos(strtolower($video['channel']), $lowercaseQuery) !== false) {
|
||
|
|
$results[] = $video;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $results;
|
||
|
|
}
|
||
|
|
|
||
|
|
$searchResults = !empty($query) ? searchVideos($videos, $query) : [];
|
||
|
|
|
||
|
|
// Fonctions utilitaires
|
||
|
|
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' : '');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
?>
|
||
|
|
|
||
|
|
<!DOCTYPE html>
|
||
|
|
<html lang="fr">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
<title>Recherche: <?php echo $query; ?> - Kaubuntu.re</title>
|
||
|
|
<link rel="stylesheet" href="css/styles.css">
|
||
|
|
<link rel="stylesheet" href="css/search.css">
|
||
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="container">
|
||
|
|
<?php include 'includes/header.php'; ?>
|
||
|
|
|
||
|
|
<main class="search-page">
|
||
|
|
<div class="search-header">
|
||
|
|
<h1>Résultats de recherche pour "<?php echo $query; ?>"</h1>
|
||
|
|
<div class="search-container">
|
||
|
|
<form action="search.php" method="get">
|
||
|
|
<input type="text" name="q" value="<?php echo $query; ?>" placeholder="Rechercher des vidéos...">
|
||
|
|
<button type="submit"><i class="fas fa-search"></i></button>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<?php if (!empty($query)): ?>
|
||
|
|
<?php if (count($searchResults) > 0): ?>
|
||
|
|
<div class="search-results-count">
|
||
|
|
<p><?php echo count($searchResults); ?> résultat(s) trouvé(s)</p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="search-results">
|
||
|
|
<?php foreach ($searchResults as $video): ?>
|
||
|
|
<div class="search-result-item" data-video-id="<?php echo $video['id']; ?>">
|
||
|
|
<div class="search-result-thumbnail">
|
||
|
|
<img src="<?php echo $video['thumbnail']; ?>" alt="<?php echo $video['title']; ?>">
|
||
|
|
<div class="video-duration"><?php echo formatDuration($video['duration']); ?></div>
|
||
|
|
</div>
|
||
|
|
<div class="search-result-info">
|
||
|
|
<h3 class="search-result-title"><?php echo $video['title']; ?></h3>
|
||
|
|
<div class="search-result-metadata">
|
||
|
|
<span class="search-result-views"><?php echo formatViewCount($video['views']); ?> vues</span>
|
||
|
|
<span class="search-result-date"><?php echo formatDate($video['date']); ?></span>
|
||
|
|
</div>
|
||
|
|
<div class="search-result-channel"><?php echo $video['channel']; ?></div>
|
||
|
|
<div class="search-result-description"><?php echo substr($video['description'], 0, 150); ?>...</div>
|
||
|
|
<div class="search-result-tags">
|
||
|
|
<?php foreach ($video['tags'] as $tag): ?>
|
||
|
|
<a href="search.php?q=<?php echo urlencode($tag); ?>" class="tag">#<?php echo $tag; ?></a>
|
||
|
|
<?php endforeach; ?>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<?php endforeach; ?>
|
||
|
|
</div>
|
||
|
|
<?php else: ?>
|
||
|
|
<div class="no-results">
|
||
|
|
<i class="fas fa-search fa-3x"></i>
|
||
|
|
<h2>Aucun résultat trouvé pour "<?php echo $query; ?>"</h2>
|
||
|
|
<p>Essayez avec d'autres mots-clés ou vérifiez l'orthographe.</p>
|
||
|
|
</div>
|
||
|
|
<?php endif; ?>
|
||
|
|
<?php else: ?>
|
||
|
|
<div class="search-instructions">
|
||
|
|
<i class="fas fa-search fa-3x"></i>
|
||
|
|
<h2>Recherchez du contenu</h2>
|
||
|
|
<p>Utilisez la barre de recherche pour trouver des vidéos, des chaînes ou des mots-clés.</p>
|
||
|
|
</div>
|
||
|
|
<?php endif; ?>
|
||
|
|
</main>
|
||
|
|
|
||
|
|
<?php include 'includes/footer.php'; ?>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="mobile-menu-overlay" id="mobileMenuOverlay">
|
||
|
|
<?php include 'includes/mobile-menu.php'; ?>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
||
|
|
<script src="js/main.js"></script>
|
||
|
|
<script>
|
||
|
|
document.addEventListener('DOMContentLoaded', function() {
|
||
|
|
// Gestion des clics sur les résultats de recherche
|
||
|
|
const searchResultItems = document.querySelectorAll('.search-result-item');
|
||
|
|
|
||
|
|
searchResultItems.forEach(item => {
|
||
|
|
item.addEventListener('click', function() {
|
||
|
|
const videoId = this.dataset.videoId;
|
||
|
|
if (videoId) {
|
||
|
|
window.location.href = 'video.php?id=' + videoId;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|