getUri()->getPath(); // Map routes to media types $mediaRoutes = [ '/media/games' => 'games', '/media/movies' => 'movies', '/media/tv-shows' => 'tvshows', '/media/music' => 'music', '/media/adult' => 'adult', '/media/actors' => 'actors' ]; foreach ($mediaRoutes as $route => $mediaType) { if (strpos($path, $route) === 0) { // Check if this media type is visible to the current user if (!$this->isMediaTypeVisible($mediaType)) { // Redirect to login or show 404 based on configuration if (!is_logged_in()) { return $handler->handle($request)->withStatus(401)->withHeader('Location', '/login'); } else { return $handler->handle($request)->withStatus(404); } } break; } } return $handler->handle($request); } private function isMediaTypeVisible(string $mediaType): bool { // Get database connection $pdo = \App\Database\Database::getInstance(); // Get media visibility setting $stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = :key LIMIT 1"); $stmt->execute(['key' => "media_visibility_{$mediaType}"]); $visibility = $stmt->fetchColumn() ?: 'authenticated'; // Default to authenticated only // Check user authentication status $isLoggedIn = is_logged_in(); switch ($visibility) { case 'public': return true; // Visible to everyone case 'authenticated': return $isLoggedIn; // Visible only to authenticated users case 'hidden': return false; // Hidden from all users default: return $isLoggedIn; // Default to authenticated only } } }