<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once __DIR__ . '/includes/db.php';

echo "=== VERIFICACIÓN DIRECTA DE LA BASE DE DATOS ===\n\n";

// Check recurrent_messages
echo "--- Tabla: recurrent_messages ---\n";
$stmt = $pdo->query("SELECT id, message_content FROM recurrent_messages WHERE message_content LIKE '%galeria%'");
$count = 0;
while ($row = $stmt->fetch()) {
    if (!$row['message_content']) continue;
    
    // Count img tags
    preg_match_all('/<img/', $row['message_content'], $img_matches);
    $img_count = count($img_matches[0]);
    
    if ($img_count > 0) {
        $count++;
        echo "ID {$row['id']}: $img_count imágenes\n";
        
        // Extract and show ALL src attributes
        preg_match_all('/src="[^"]*"/', $row['message_content'], $src_matches);
        foreach ($src_matches[0] as $src) {
            echo "  -> $src\n";
        }
        if (count($src_matches[0]) === 0) {
            echo "  -> (no src found, raw content preview: " . substr($row['message_content'], 0, 300) . ")\n";
        }
    }
}

echo "\nTotal con imágenes: $count\n\n";

// Also check messages table
echo "--- Tabla: messages ---\n";
$stmt = $pdo->query("SELECT id, content FROM messages WHERE content LIKE '%galeria%' LIMIT 5");
while ($row = $stmt->fetch()) {
    if (!$row['content']) continue;
    
    preg_match_all('/src="[^"]*"/', $row['content'], $src_matches);
    if (count($src_matches[0]) > 0) {
        echo "ID {$row['id']}: " . implode(' | ', array_slice($src_matches[0], 0, 3)) . "\n";
    }
}
