/* --------------------------------------- 11) Helper functions - FIXED WITH if (!function_exists()) --------------------------------------- */ if (!function_exists('movie_href')) { function movie_href($movie) { // Use the slug directly (it now includes TMDB ID if needed for uniqueness) $slug = $movie['slug'] ?? slugify($movie['title'] ?? 'movie'); // If slug doesn't exist, generate it with uniqueness check if (empty($slug) || $slug === slugify($movie['title'] ?? 'movie')) { global $pdo; $baseSlug = slugify($movie['title'] ?? 'movie'); try { $stmt = $pdo->prepare("SELECT COUNT(*) FROM movies WHERE title = ? AND tmdb_id != ?"); $stmt->execute([$movie['title'], $movie['tmdb_id']]); $duplicates = $stmt->fetchColumn(); if ($duplicates > 0) { $slug = $baseSlug . '-' . $movie['tmdb_id']; } else { $slug = $baseSlug; } } catch (Throwable $e) { $slug = $baseSlug . '-' . $movie['tmdb_id']; } } return "/movie/" . $slug . "/"; } } if (!function_exists('category_href')) { function category_href($genre) { if (function_exists('slugify')) { $slug = slugify($genre); } else { $slug = strtolower(preg_replace('/[^a-z0-9]+/i', '-', $genre)); $slug = trim($slug, '-'); } return "/category/" . $slug . "/"; } } if (!function_exists('year_href')) { function year_href($year) { return "/year/" . (int)$year . "/"; } } // CRITICAL FIX: Only declare if not already in helpers.php if (!function_exists('format_duration')) { function format_duration($duration) { if (empty($duration) || $duration === 'N/A') return ''; if (preg_match('/\d+h|\d+m/', $duration)) return $duration; $minutes = (int)$duration; if ($minutes > 0) { $hours = floor($minutes / 60); $mins = $minutes % 60; if ($hours > 0 && $mins > 0) return $hours . 'h ' . $mins . 'm'; elseif ($hours > 0) return $hours . 'h'; else return $mins . 'm'; } return $duration; } } if (!function_exists('movies_index_href')) { function movies_index_href() { return '/movies'; } }