mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
172 lines
5.9 KiB
PHP
172 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
use App\Models\AdultVideo;
|
|
use Slim\Views\Twig;
|
|
|
|
class AdultController extends Controller
|
|
{
|
|
private \PDO $pdo;
|
|
|
|
public function __construct(\PDO $pdo, Twig $view)
|
|
{
|
|
parent::__construct($view);
|
|
$this->pdo = $pdo;
|
|
}
|
|
|
|
public function index(Request $request, Response $response, $args)
|
|
{
|
|
$queryParams = $request->getQueryParams();
|
|
|
|
// Get pagination parameters
|
|
$page = max(1, (int)($queryParams['page'] ?? 1));
|
|
$perPage = max(12, min(100, (int)($queryParams['per_page'] ?? 24)));
|
|
|
|
// Get search parameters
|
|
$search = trim($queryParams['search'] ?? '');
|
|
|
|
// Get filter parameters
|
|
$genres = $queryParams['genres'] ?? [];
|
|
if (!is_array($genres)) {
|
|
$genres = [$genres];
|
|
}
|
|
$genres = array_filter($genres);
|
|
|
|
$directors = $queryParams['directors'] ?? [];
|
|
if (!is_array($directors)) {
|
|
$directors = [$directors];
|
|
}
|
|
$directors = array_filter($directors);
|
|
|
|
// Get view mode
|
|
$viewMode = $queryParams['view'] ?? 'grid'; // grid, list, covers
|
|
|
|
// Get adult videos with pagination and filters
|
|
$adultVideos = AdultVideo::getAllWithPagination($this->pdo, $page, $perPage, $search, $genres, $directors);
|
|
|
|
// Process metadata to extract local image paths for template compatibility
|
|
foreach ($adultVideos as &$video) {
|
|
if (!empty($video['metadata'])) {
|
|
$metadata = json_decode($video['metadata'], true);
|
|
|
|
// Use local cover path if available, otherwise fall back to original URL
|
|
if (!empty($metadata['local_cover_path'])) {
|
|
$video['poster_url'] = $metadata['local_cover_path'];
|
|
} elseif (!empty($metadata['cover_url'])) {
|
|
$video['poster_url'] = $metadata['cover_url'];
|
|
}
|
|
|
|
// Add actors data if available
|
|
if (!empty($metadata['actors'])) {
|
|
$video['actors'] = $metadata['actors'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Get total count for pagination
|
|
$totalCount = AdultVideo::getTotalCount($this->pdo, $search, $genres, $directors);
|
|
|
|
// Get available filter options
|
|
$availableGenres = AdultVideo::getAvailableGenres($this->pdo);
|
|
$availableDirectors = AdultVideo::getAvailableDirectors($this->pdo);
|
|
|
|
// Calculate pagination info
|
|
$totalPages = ceil($totalCount / $perPage);
|
|
$hasNextPage = $page < $totalPages;
|
|
$hasPrevPage = $page > 1;
|
|
|
|
return $this->view->render($response, 'adult/index.twig', [
|
|
'title' => 'Adult Videos',
|
|
'movies' => $adultVideos, // Keep same variable name for template compatibility
|
|
'pagination' => [
|
|
'current_page' => $page,
|
|
'per_page' => $perPage,
|
|
'total_pages' => $totalPages,
|
|
'total_items' => $totalCount,
|
|
'has_next' => $hasNextPage,
|
|
'has_prev' => $hasPrevPage,
|
|
'next_page' => $page + 1,
|
|
'prev_page' => $page - 1
|
|
],
|
|
'search' => $search,
|
|
'view_mode' => $viewMode,
|
|
'view_modes' => ['grid', 'list', 'covers'],
|
|
'filters' => [
|
|
'genres' => $genres,
|
|
'directors' => $directors
|
|
],
|
|
'available_filters' => [
|
|
'genres' => $availableGenres,
|
|
'directors' => $availableDirectors
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function show(Request $request, Response $response, $args)
|
|
{
|
|
$adultVideoId = (int) $args['id'];
|
|
|
|
// Get adult video details
|
|
$stmt = $this->pdo->prepare("
|
|
SELECT av.*, s.display_name as source_name
|
|
FROM adult_videos av
|
|
JOIN sources s ON av.source_id = s.id
|
|
WHERE av.id = :id
|
|
");
|
|
$stmt->execute(['id' => $adultVideoId]);
|
|
$adultVideo = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
|
|
if (!$adultVideo) {
|
|
return $response->withStatus(404);
|
|
}
|
|
|
|
// Decode metadata for display
|
|
$metadata = json_decode($adultVideo['metadata'], true);
|
|
|
|
// Add local image paths and other metadata to the video data for template compatibility
|
|
if (!empty($metadata['local_cover_path'])) {
|
|
$adultVideo['poster_url'] = '/images/'.$metadata['local_cover_path'];
|
|
} elseif (!empty($metadata['cover_url'])) {
|
|
$adultVideo['poster_url'] = $metadata['cover_url'];
|
|
}
|
|
|
|
if (!empty($metadata['local_screenshot_path'])) {
|
|
$adultVideo['screenshot_url'] = '/images/'.$metadata['local_screenshot_path'];
|
|
}
|
|
|
|
// Add actors data if available
|
|
if (!empty($metadata['actors'])) {
|
|
$adultVideo['actors'] = $metadata['actors'];
|
|
}
|
|
|
|
// Get actors for this adult video from the pivot table
|
|
$stmt = $this->pdo->prepare("
|
|
SELECT a.*
|
|
FROM actors a
|
|
JOIN actor_adult_video aav ON a.id = aav.actor_id
|
|
WHERE aav.adult_video_id = :adult_video_id
|
|
ORDER BY a.name ASC
|
|
");
|
|
$stmt->execute(['adult_video_id' => $adultVideoId]);
|
|
$actors = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
return $this->view->render($response, 'adult/show.twig', [
|
|
'title' => $adultVideo['title'],
|
|
'movie' => $adultVideo, // Keep same variable name for template compatibility
|
|
'metadata' => $metadata,
|
|
'actors' => $actors
|
|
]);
|
|
}
|
|
|
|
private function getAdultSourceId(): ?int
|
|
{
|
|
$stmt = $this->pdo->prepare("SELECT id FROM sources WHERE name = 'adult' LIMIT 1");
|
|
$stmt->execute();
|
|
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
return $result ? (int) $result['id'] : null;
|
|
}
|
|
}
|