0 ? $count : count($items); $firstType = $items[0]['type'] ?? ($items[0]['grid']['type'] ?? ''); $shapeClass = in_array($firstType, ['books', 'movies', 'tv']) ? 'vertical' : 'square'; echo '
'; foreach (array_slice($items, 0, $limit) as $item) { $grid = $item['grid'] ?? $item; $alt = htmlspecialchars($grid['alt'] ?? ''); $image = htmlspecialchars($grid['image'] ?? ''); $title = htmlspecialchars($grid['title'] ?? ''); $subtext = htmlspecialchars($grid['subtext'] ?? ''); $url = $grid['url'] ?? null; $type = $item['type'] ?? ''; $isVertical = in_array($type, ['books', 'movies', 'tv']); $imageClass = $isVertical ? 'vertical' : 'square'; $width = $isVertical ? 120 : 150; $height = $isVertical ? 184 : 150; $openLink = $url ? '' : ''; $closeLink = $url ? '' : ''; echo $openLink; echo '
'; if ($title || $subtext) { echo '
'; if ($title) echo '
' . $title . '
'; if ($subtext) echo '
' . $subtext . '
'; echo '
'; } echo '' . $alt . ''; echo '
'; echo $closeLink; } echo '
'; } } if (!function_exists('renderAssociatedMedia')) { function renderAssociatedMedia( array $artists = [], array $books = [], array $genres = [], array $movies = [], array $posts = [], array $shows = [], ) { $sections = [ "artists" => ["icon" => "headphones", "css_class" => "music", "label" => "Related artist(s)", "hasGrid" => true], "books" => ["icon" => "books", "css_class" => "books", "label" => "Related book(s)", "hasGrid" => true], "genres" => ["icon" => "headphones", "css_class" => "music", "label" => "Related genre(s)", "hasGrid" => false], "movies" => ["icon" => "movie", "css_class" => "movies", "label" => "Related movie(s)", "hasGrid" => true], "posts" => ["icon" => "article", "css_class" => "article", "label" => "Related post(s)", "hasGrid" => false], "shows" => ["icon" => "device-tv-old", "css_class" => "tv", "label" => "Related show(s)", "hasGrid" => true] ]; $allMedia = compact('artists', 'books', 'genres', 'movies', 'posts', 'shows'); echo '
'; foreach ($sections as $key => $section) { $items = $allMedia[$key]; if (empty($items)) continue; echo '

'; echo getTablerIcon($section['icon']); echo htmlspecialchars($section['label']); echo '

'; if ($section['hasGrid']) { renderMediaGrid($items); } else { echo ''; } } echo '
'; } } if (!function_exists('renderMediaLinks')) { function renderMediaLinks(array $data, string $type, int $count = 10): string { if (empty($data) || empty($type)) return ""; $slice = array_slice($data, 0, $count); if (count($slice) === 0) return ""; $buildLink = function ($item) use ($type) { switch ($type) { case "genre": return '' . htmlspecialchars($item['genre_name']) . ''; case "artist": return '' . htmlspecialchars($item['name']) . ''; case "book": return '' . htmlspecialchars($item['title']) . ''; default: return ''; } }; if (count($slice) === 1) return $buildLink($slice[0]); $links = array_map($buildLink, $slice); $last = array_pop($links); return implode(', ', $links) . ' and ' . $last; } } ?>