<?php
header('Content-Type: application/json');

// Database connection details
$host = 'localhost';
$db = 'digupdog_FEED';
$user = 'digupdog_FEEDadmin';
$pass = 'Raimundinho1';
$charset = 'utf8mb4';

// Set up PDO
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];
$pdo = new PDO($dsn, $user, $pass, $opt);

// Get the feed ID from the query parameters
$feedId = $_GET['id'];
$feedTitle = htmlspecialchars($feed['title'], ENT_QUOTES, 'UTF-8');
$feedDescription = htmlspecialchars($feed['description'], ENT_QUOTES, 'UTF-8');
$feedImage = htmlspecialchars($feed['thumbnail'], ENT_QUOTES, 'UTF-8');
$feedUrl = "https://myhashtag.io/pindetails.php?id=" . $feedId;

// Get the feed from the database
$stmt = $pdo->prepare('SELECT id, title, image, description, pubDate, link, guid, source, updated, thumbnail, favicon FROM pinfeeds WHERE id = ?');
$stmt->execute([$feedId]);
$feed = $stmt->fetch();

if ($feed) {
    echo json_encode($feed);
} else {
    echo json_encode(['error' => 'Feed not found']);
}
?>