211 lines
11 KiB
PHP
211 lines
11 KiB
PHP
<?php
|
|
// Inclure la configuration
|
|
require_once 'includes/config.php';
|
|
|
|
// Récupération de la requête de recherche et de la page courante
|
|
$query = isset($_GET['q']) ? trim($_GET['q']) : '';
|
|
$currentSearchPage = isset($_GET['page']) ? max(1, intval($_GET['page'])) : 1;
|
|
|
|
// Déterminer si la recherche est par tag
|
|
$isTagSearch = !empty($query) && substr($query, 0, 1) === '#';
|
|
$searchTag = $isTagSearch ? substr($query, 1) : '';
|
|
|
|
// Rechercher les vidéos via l'API PeerTube si une requête est soumise
|
|
$searchResults = !empty($query) ? searchVideos($query, COUNT_VIDEO_SEARCH) : [];
|
|
|
|
// Définir le nombre total de résultats
|
|
$resultsCount = count($searchResults);
|
|
|
|
// Calculer le nombre total de pages
|
|
$totalPages = ceil($resultsCount / VIDEOS_PER_PAGE);
|
|
|
|
// S'assurer que la page actuelle est valide
|
|
$currentSearchPage = min($currentSearchPage, max(1, $totalPages));
|
|
|
|
// Calculer les indices de début et de fin pour la page actuelle
|
|
$startIndex = ($currentSearchPage - 1) * VIDEOS_PER_PAGE;
|
|
$endIndex = min($startIndex + VIDEOS_PER_PAGE, $resultsCount);
|
|
|
|
// Extraire les vidéos pour la page actuelle
|
|
$currentPageVideos = [];
|
|
if ($resultsCount > 0) {
|
|
$currentPageVideos = array_slice($searchResults, $startIndex, VIDEOS_PER_PAGE);
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?php echo !empty($query) ? 'Recherche: ' . htmlspecialchars($query) . ' - ' : 'Recherche - '; ?>kaubuntu.re</title>
|
|
<link rel="stylesheet" href="css/styles.css">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
|
|
|
<!-- Favicons -->
|
|
<link rel="apple-touch-icon" sizes="180x180" href="img/apple-touch-icon.png">
|
|
<link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png">
|
|
<link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png">
|
|
<link rel="manifest" href="site.webmanifest">
|
|
<link rel="icon" type="image/x-icon" href="img/favicon.ico">
|
|
<meta name="theme-color" content="#ffffff">
|
|
</head>
|
|
<body>
|
|
<?php include 'includes/sidebar.php'; ?>
|
|
|
|
<!-- Contenu principal -->
|
|
<div class="main-content">
|
|
<?php include 'includes/header.php'; ?>
|
|
|
|
<!-- Section de recherche -->
|
|
<div class="video-section search-page" data-search-query="<?php echo htmlspecialchars($query); ?>">
|
|
<div class="section-header">
|
|
<div class="section-logo">
|
|
<img src="img/logo.png" alt="kaubuntu.re">
|
|
</div>
|
|
<?php if (!empty($query)): ?>
|
|
<?php if ($isTagSearch): ?>
|
|
<h2 class="section-title">Vidéos avec le hashtag : "<?php echo htmlspecialchars($searchTag); ?>"</h2>
|
|
<?php else: ?>
|
|
<h2 class="section-title">Résultats pour : "<?php echo htmlspecialchars($query); ?>"</h2>
|
|
<?php endif; ?>
|
|
<?php else: ?>
|
|
<h2 class="section-title">Rechercher des vidéos</h2>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if (!empty($query)): ?>
|
|
<?php if ($resultsCount > 0): ?>
|
|
<div class="search-results-count">
|
|
<?php if ($isTagSearch): ?>
|
|
<p><?php echo $resultsCount; ?> vidéo<?php echo $resultsCount > 1 ? 's' : ''; ?> avec le hashtag #<?php echo htmlspecialchars($searchTag); ?></p>
|
|
<?php else: ?>
|
|
<p><?php echo $resultsCount; ?> résultat<?php echo $resultsCount > 1 ? 's' : ''; ?> trouvé<?php echo $resultsCount > 1 ? 's' : ''; ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="video-grid category-videos">
|
|
<?php foreach ($currentPageVideos 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 htmlspecialchars($video['title']); ?>">
|
|
<div class="video-play-icon">
|
|
<i class="fas fa-play-circle"></i>
|
|
</div>
|
|
<span class="video-duration"><?php echo formatDuration($video['duration']); ?></span>
|
|
</div>
|
|
<div class="video-info">
|
|
<h3 class="video-title"><?php echo htmlspecialchars($video['title']); ?></h3>
|
|
<div class="video-channel">
|
|
<?php if (strpos($video['channelAvatar'], 'default-avatar') !== false || empty($video['channelAvatar'])): ?>
|
|
<div class="channel-avatar-placeholder">
|
|
<i class="fas fa-user-circle"></i>
|
|
</div>
|
|
<?php else: ?>
|
|
<img src="<?php echo $video['channelAvatar']; ?>" alt="<?php echo htmlspecialchars($video['channel']); ?>" class="channel-avatar">
|
|
<?php endif; ?>
|
|
<span class="channel-name"><?php echo htmlspecialchars($video['channel']); ?></span>
|
|
</div>
|
|
<div class="video-metadata">
|
|
<span class="video-views"><i class="fas fa-eye"></i> <?php echo formatViewCount($video['views']); ?> vues</span>
|
|
<span class="video-date"><i class="far fa-calendar-alt"></i> <?php echo formatDate($video['date']); ?></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<?php if ($totalPages > 1): ?>
|
|
<div class="pagination">
|
|
<?php if ($currentSearchPage > 1): ?>
|
|
<?php var_dump($currentSearchPage); ?>
|
|
<a href="recherche.php?q=<?php echo urlencode($query); ?>&page=<?php echo $currentSearchPage - 1; ?>" class="page-link prev">
|
|
<i class="fas fa-chevron-left"></i> Précédent
|
|
</a>
|
|
<?php endif; ?>
|
|
|
|
<div class="page-numbers">
|
|
<?php
|
|
// Déterminer la plage de pages à afficher
|
|
$pageRange = 2; // Nombre de pages à afficher de chaque côté
|
|
$startPage = max(1, $currentSearchPage - $pageRange);
|
|
$endPage = min($totalPages, $currentSearchPage + $pageRange);
|
|
|
|
// Afficher le lien vers la première page si nécessaire
|
|
if ($startPage > 1) {
|
|
echo '<a href="recherche.php?q=' . urlencode($query) . '&page=1" class="page-number">1</a>';
|
|
if ($startPage > 2) {
|
|
echo '<span class="page-dots">...</span>';
|
|
}
|
|
}
|
|
|
|
// Afficher les liens de pagination
|
|
for ($i = $startPage; $i <= $endPage; $i++) {
|
|
if ($i == $currentSearchPage) {
|
|
echo '<span class="page-number current">' . $i . '</span>';
|
|
} else {
|
|
echo '<a href="recherche.php?q=' . urlencode($query) . '&page=' . $i . '" class="page-number">' . $i . '</a>';
|
|
}
|
|
}
|
|
|
|
// Afficher le lien vers la dernière page si nécessaire
|
|
if ($endPage < $totalPages) {
|
|
if ($endPage < $totalPages - 1) {
|
|
echo '<span class="page-dots">...</span>';
|
|
}
|
|
echo '<a href="recherche.php?q=' . urlencode($query) . '&page=' . $totalPages . '" class="page-number">' . $totalPages . '</a>';
|
|
}
|
|
?>
|
|
</div>
|
|
|
|
<?php if ($currentSearchPage < $totalPages): ?>
|
|
<a href="recherche.php?q=<?php echo urlencode($query); ?>&page=<?php echo $currentSearchPage + 1; ?>" class="page-link next">
|
|
Suivant <i class="fas fa-chevron-right"></i>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php else: ?>
|
|
<div class="no-videos-message">
|
|
<i class="fas fa-search-minus"></i>
|
|
<h3>Aucun résultat trouvé</h3>
|
|
<?php if ($isTagSearch): ?>
|
|
<p>Aucune vidéo n'a été trouvée avec le hashtag "#<?php echo htmlspecialchars($searchTag); ?>".</p>
|
|
<?php else: ?>
|
|
<p>Aucune vidéo ne correspond à votre recherche "<?php echo htmlspecialchars($query); ?>".</p>
|
|
<?php endif; ?>
|
|
<p>Essayez avec d'autres termes ou consultez les vidéos populaires sur la <a href="index.php">page d'accueil</a>.</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php else: ?>
|
|
<div class="search-instructions">
|
|
<i class="fas fa-search"></i>
|
|
<h3>Effectuez une recherche</h3>
|
|
<p>Utilisez le formulaire ci-dessus pour rechercher des vidéos par titre, description ou tags.</p>
|
|
<p class="mt-2"><strong>Astuce :</strong> Pour rechercher par tag, commencez votre recherche par # (exemple: #réunion)</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|
|
<?php include 'includes/mobile-menu.php'; ?>
|
|
|
|
<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 vidéos
|
|
const videoCards = document.querySelectorAll('.video-card');
|
|
videoCards.forEach(card => {
|
|
card.addEventListener('click', function() {
|
|
const videoId = this.dataset.videoId;
|
|
if (videoId) {
|
|
window.location.href = 'video.php?id=' + videoId;
|
|
}
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|