<?php
// Blog Image Display Test
require_once 'config.php';
require_once 'admin/blog-functions.php';

echo "🖼️ Blog Image Display Test\n";
echo "===========================\n\n";

// Get all blogs to test image display
$blogs = getAllBlogsAdmin($link, 10, 0);

if (empty($blogs)) {
    echo "❌ No blogs found to test\n";
    exit;
}

echo "📊 Testing " . count($blogs) . " blog posts for image display:\n\n";

foreach ($blogs as $index => $blog) {
    $blog_num = $index + 1;
    echo "🔍 Blog #{$blog_num}: {$blog['title']}\n";
    echo "   - Blog ID: {$blog['id']}\n";
    echo "   - Featured Image: " . ($blog['featured_image'] ? $blog['featured_image'] : 'None') . "\n";
    
    if (!empty($blog['featured_image'])) {
        $image_path = "uploads/blog/" . $blog['featured_image'];
        $full_path = __DIR__ . "/" . $image_path;
        
        echo "   - Image Path: $image_path\n";
        echo "   - File Exists: " . (file_exists($full_path) ? "✅ Yes" : "❌ No") . "\n";
        
        if (file_exists($full_path)) {
            $file_size = filesize($full_path);
            $image_info = getimagesize($full_path);
            echo "   - File Size: " . number_format($file_size / 1024, 2) . " KB\n";
            if ($image_info) {
                echo "   - Dimensions: {$image_info[0]} x {$image_info[1]} pixels\n";
                echo "   - MIME Type: {$image_info['mime']}\n";
            }
        } else {
            echo "   - ⚠️  Image file missing at: $full_path\n";
        }
        
        // Test admin dashboard URL
        $admin_url = "admin/../uploads/blog/" . $blog['featured_image'];
        echo "   - Admin Dashboard URL: $admin_url\n";
        
        // Test blog details URL  
        $details_url = "uploads/blog/" . $blog['featured_image'];
        echo "   - Blog Details URL: $details_url\n";
        
    } else {
        echo "   - 📝 No featured image set\n";
    }
    
    echo "\n";
}

echo "📋 Summary:\n";
echo "- Blog Details Image Path: uploads/blog/[filename]\n";
echo "- Admin Dashboard Image Path: ../uploads/blog/[filename]\n";
echo "- Both paths should now display images correctly\n\n";

echo "🧪 Test blog details page: http://localhost/A+/01/blog-details.php?id=15\n";
echo "🧪 Test admin dashboard: http://localhost/A+/01/admin/admin-dashboard.php\n";
?>