/** * Get descriptive title for box art based on filename */ private function getBoxArtTitle($basename) { // Map common box art types to descriptive titles - more specific patterns first $titleMap = [ 'variant02_back' => 'Variant 2 Back', 'variant02_front' => 'Variant 2 Front', 'variant01_back' => 'Variant 1 Back', 'variant01_front' => 'Variant 1 Front', 'variant02' => 'Variant 2', 'variant01' => 'Variant 1', 'variant03' => 'Variant 3', '_back' => 'Back Box Art', // More specific: must have underscore before "back" '_front' => 'Front Box Art', // More specific: must have underscore before "front" '_main' => 'Main Box Art' // More specific: must have underscore before "main" ]; // Check for matches in order of specificity (most specific first) foreach ($titleMap as $key => $title) { if (strpos($basename, $key) !== false) { return $title; } } // Fallback check for less specific patterns $fallbackMap = [ 'main' => 'Main Box Art', 'front' => 'Front Box Art', 'back' => 'Back Box Art' ]; foreach ($fallbackMap as $key => $title) { // Make sure it's not part of "boxart" word if (preg_match('/\b' . $key . '\b/', $basename)) { return $title; } } // Default: capitalize and replace underscores with spaces return ucwords(str_replace(['_', '-'], ' ', $basename)); } /** * Updated getBoxArtGallery method with correct ordering */ public function getBoxArtGallery($maxCount = 10) { $boxArtDir = $this->softwareFolder . self::FOLDER_BOX_ART . '/'; $allFiles = $this->getFilesInDirectory($boxArtDir); // Filter to get only images $images = array_filter($allFiles, function($file) { return $file['type'] === 'image'; }); if (empty($images)) { return []; } // Get the main display image to exclude it $mainBoxArt = $this->getBoxArt(); $mainImagePath = $mainBoxArt['path']; $boxArtImages = []; // Define priority order for box art display (matches desired order) $priorityOrder = [ '_main' => 1, '_front' => 2, '_back' => 3, 'variant01_front' => 4, 'variant01_back' => 5, 'variant02_front' => 6, 'variant02_back' => 7, 'variant01' => 8, 'variant02' => 9, 'variant03' => 10 ]; // Add priority scores to images foreach ($images as &$image) { $image['priority'] = 999; // Default low priority foreach ($priorityOrder as $key => $priority) { if (strpos($image['basename'], $key) !== false) { $image['priority'] = $priority; break; } } } // Sort by priority order usort($images, function($a, $b) { return $a['priority'] - $b['priority']; }); foreach ($images as $image) { if (count($boxArtImages) >= $maxCount) { break; } // Skip the main display image (don't show it in gallery) if ($image['path'] === $mainImagePath) { continue; } // Determine title based on filename $title = $this->getBoxArtTitle($image['basename']); $supportFiles = $this->findSupportFilesForImage($boxArtDir, $image['basename']); $boxArtImages[] = [ 'path' => $image['path'], 'title' => $title, 'support_files' => $supportFiles ]; } return $boxArtImages; }