fix load more and improve vide page

This commit is contained in:
2025-04-08 10:49:46 +04:00
parent a227247f57
commit 133b2e9d5e
6 changed files with 361 additions and 92 deletions
+92
View File
@@ -0,0 +1,92 @@
<?php
// Inclure la configuration
require_once '../includes/config.php';
// Vérifier que la requête est faite par AJAX
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest') {
http_response_code(403); // Accès non autorisé
echo json_encode(['error' => 'Accès non autorisé']);
exit;
}
// Récupérer les paramètres
$type = isset($_GET['type']) ? $_GET['type'] : '';
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Vérifier que le type est valide
if (!in_array($type, ['recent', 'trending', 'independence'])) {
http_response_code(400); // Requête incorrecte
echo json_encode(['error' => 'Type de vidéos non valide']);
exit;
}
// Récupérer les vidéos en fonction du type
$videos = [];
$offset = $page * LOAD_MORE_COUNT;
switch ($type) {
case 'recent':
// Récupérer les vidéos récentes
$data = callPeerTubeApi('videos', [
'sort' => '-publishedAt',
'count' => LOAD_MORE_COUNT,
'start' => $offset,
'isLocal' => true
]);
$videos = formatVideosData($data['data'] ?? []);
break;
case 'trending':
// Récupérer les vidéos tendances
$data = callPeerTubeApi('videos', [
'sort' => '-views',
'count' => LOAD_MORE_COUNT,
'start' => $offset,
'isLocal' => true
]);
$videos = formatVideosData($data['data'] ?? []);
break;
case 'independence':
// Récupérer les vidéos sur l'indépendance
$data = callPeerTubeApi('videos', [
'tagsOneOf' => TAG_INDEPENDENCE,
'count' => LOAD_MORE_COUNT,
'start' => $offset,
'isLocal' => true
]);
$videos = formatVideosData($data['data'] ?? []);
break;
}
// Préparer la réponse HTML
$html = '';
foreach ($videos as $video) {
$html .= '<div class="video-card" data-video-id="' . $video['id'] . '">';
$html .= ' <div class="video-thumbnail">';
$html .= ' <img src="' . $video['thumbnail'] . '" alt="' . htmlspecialchars($video['title']) . '">';
$html .= ' <div class="video-play-icon">';
$html .= ' <i class="fas fa-play-circle"></i>';
$html .= ' </div>';
$html .= ' <div class="video-duration">' . formatDuration($video['duration']) . '</div>';
$html .= ' </div>';
$html .= ' <div class="video-info">';
$html .= ' <h3 class="video-title">' . htmlspecialchars($video['title']) . '</h3>';
$html .= ' <div class="video-channel">' . htmlspecialchars($video['channel']) . '</div>';
$html .= ' <div class="video-metadata">';
$html .= ' <span class="video-views"><i class="fas fa-eye"></i> ' . formatViewCount($video['views']) . ' vues</span>';
$html .= ' <span class="video-date"><i class="far fa-calendar-alt"></i> ' . formatDate($video['date']) . '</span>';
$html .= ' </div>';
$html .= ' </div>';
$html .= '</div>';
}
// Retourner la réponse
echo json_encode([
'success' => true,
'html' => $html,
'page' => $page,
'hasMore' => count($videos) >= LOAD_MORE_COUNT
]);
?>