require_once 'db.php'; require_once 'includes/functions.php'; if (file_exists('includes/seo_modules.php')) require_once 'includes/seo_modules.php'; $id = get_url_id('id'); $product_res = $conn->query("SELECT p.*, u.shop_name, u.shop_slug, u.shop_image FROM products p LEFT JOIN users u ON p.user_id = u.id WHERE p.id = $id"); $product = ($product_res && $product_res->num_rows > 0) ? $product_res->fetch_assoc() : null; if (!$product) { $raw_slug = $_GET['id'] ?? ''; if (!empty($raw_slug) && !is_numeric($raw_slug)) { $safe_slug = $conn->real_escape_string($raw_slug); $product_res = $conn->query("SELECT p.*, u.shop_name, u.shop_slug, u.shop_image FROM products p LEFT JOIN users u ON p.user_id = u.id WHERE p.slug = '$safe_slug' LIMIT 1"); $product = ($product_res && $product_res->num_rows > 0) ? $product_res->fetch_assoc() : null; if ($product) $id = $product['id']; } } if (!$product) { http_response_code(404); require 'includes/header.php'; // Need header even for 404 if (function_exists('log_404')) { log_404(); } echo "

Ürün bulunamadı.

Aradığınız ürün mevcut değil veya kaldırılmış olabilir.

Anasayfaya Dön
"; require 'includes/footer.php'; exit; } // --- SEO Logic (fiyat odaklı — "en ucuz/toptan" vurgusu) --- $_sell_price = (float)(($product['discount_price'] ?? 0) > 0 ? $product['discount_price'] : ($product['price'] ?? 0)); $_price_str = number_format($_sell_price, 2, ',', '.'); $_koli = (int)($product['koli_adet'] ?? 0); // Başlık: kullanıcı SEO başlığı varsa onu kullan, yoksa fiyat odaklı üret if (!empty($product['seo_title'])) { $page_title = $product['seo_title']; } else { $page_title = $product['name'] . ' – ' . $_price_str . ' TL'; if ($_koli > 1) $page_title .= ' (Toptan)'; } // Açıklama: yoksa fiyat + değer vurgulu üret if (!empty($product['seo_description'])) { $meta_desc = $product['seo_description']; } else { $meta_desc = $product['name'] . ' en uygun fiyatla: adet ' . $_price_str . ' TL.'; if ($_koli > 1) $meta_desc .= ' ' . $_koli . "'li koli toptan fiyatı."; $meta_desc .= ' Hızlı kargo, güvenli alışveriş.'; } $meta_keys = !empty($product['seo_keywords']) ? $product['seo_keywords'] : ''; // Open Graph ürün fiyat etiketleri (header.php kullanır — AI/sosyal medya fiyatı doğrudan çeker) $og_product_price = $_sell_price; $og_product_availability = (($product['stock'] ?? 0) > 0) ? 'instock' : 'oos'; // Link for breadcrumb $cat_id = $product['category_id']; $cat_q = $conn->query("SELECT name, slug FROM categories WHERE id=$cat_id"); $cat_row = ($cat_q && $cat_q->num_rows > 0) ? $cat_q->fetch_assoc() : []; $cat_name = $cat_row['name'] ?? 'Ürünler'; $cat_slug = $cat_row['slug'] ?? ''; // Specifications & FAQ $specifications = $conn->query("SELECT * FROM products_specifications WHERE product_id=$id ORDER BY sort_order"); $faqs = $conn->query("SELECT * FROM products_faq WHERE product_id=$id AND is_active=1 ORDER BY sort_order"); $faq_data = []; if ($faqs) while ($r = $faqs->fetch_assoc()) $faq_data[] = $r; $faq_count = count($faq_data); // FAQ async olarak yükleniyor (faq_ajax.php via JS — sayfa bloklanmaz) // Resimler (Moved up for LCP Preload) $images = $conn->query("SELECT * FROM product_images WHERE product_id=$id ORDER BY is_main DESC, id ASC"); $imgs = []; if ($images) { while ($img = $images->fetch_assoc()) { $path = $img['image_path']; // Geçersiz veya boş resimleri atla if (empty(trim($path)) || $path == 'none' || $path == 'null') continue; // Lokal dosya kontrolü (Opsiyonel ama garanti) if (strpos($path, 'http') !== 0) { $check_path = get_product_image_path($path); if (!file_exists(__DIR__ . '/' . $check_path)) continue; } $imgs[] = $path; } } // Fallback: products.image kolonundan al if (empty($imgs) && !empty(trim($product['image'] ?? ''))) { $img_fallback = trim($product['image']); if ($img_fallback != 'none' && $img_fallback != 'null' && strlen($img_fallback) > 3) { if (strpos($img_fallback, 'http') === 0) { $imgs[] = $img_fallback; } else { $check_path = get_product_image_path($img_fallback); if (file_exists(__DIR__ . '/' . $check_path)) { $imgs[] = $img_fallback; } } } } // placeholder URL schema'ya girmesin — resim yoksa boş bırak, schema'da kontrol edilir // LCP Preload $preload_image = !empty($imgs) ? get_product_image_url($imgs[0], 800) : ''; // Canonical URL (Duplicate content protection) $canonical_tag = ''; if (!empty($product['canonical_url'])) { $canonical_tag = $product['canonical_url']; } else { $_d_proto = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http'; $_d_host = $_SERVER['HTTP_HOST'] ?? ''; $_d_slug = !empty($product['slug']) ? $product['slug'] : slugify($product['name'] ?? ''); $canonical_tag = $_d_proto . '://' . $_d_host . '/urun/' . $_d_slug . '-' . $product['id']; } // Now include header (which uses the above variables) require 'includes/header.php'; // Yorum Ekleme if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['comment'])) { $name = clean($_POST['name']); $msg = clean($_POST['comment']); $rating = (int) $_POST['rating']; if ($rating < 1 || $rating > 5) $rating = 5; if (!empty($name) && !empty($msg)) { $stmt = $conn->prepare("INSERT INTO comments (product_id, user_name, comment, rating) VALUES (?, ?, ?, ?)"); $stmt->bind_param("issi", $id, $name, $msg, $rating); if ($stmt->execute()) { $msg_success = "Yorumunuz alındı, onaylandıktan sonra yayınlanacaktır."; // Admin'e mail bildirimi if (function_exists('send_admin_notif')) { $site_host = $_SERVER['HTTP_HOST'] ?? 'localhost'; $proto = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; $product_name_safe = htmlspecialchars($product['name'] ?? '#'.$id); $product_url = $proto . '://' . $site_host . '/urun/' . ($product['slug'] ?? $id) . '-' . $id; $admin_url = $proto . '://' . $site_host . '/admin/comments_moderation.php'; $subject = "[$site_host] Yeni Yorum: $product_name_safe"; $body = "

Site: $site_host

Ürün: $product_name_safe

Yorumcu: " . htmlspecialchars($name) . "

Puan: $rating / 5

Yorum:

" . nl2br(htmlspecialchars($msg)) . "

Onay için: $admin_url

"; @send_admin_notif($subject, $body); } } } } // Yorumları Çek $comments = $conn->query("SELECT * FROM comments WHERE product_id=$id AND is_approved=1 ORDER BY created_at DESC"); ?>