<?php
//index.php
$connect = new PDO("mysql:host=localhost;dbname=xxx", "xxx", "xxx");
$query = "SELECT * FROM recipes ORDER BY recipe_id DESC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
header("Content-Type:text/xml; charset=UTF-8");
$base_url = "xxx";
echo "<?xml version='1.0' encoding='utf-8' ?>" . PHP_EOL;
echo "<rss version='2.0'>" . PHP_EOL;
echo "<channel>" . PHP_EOL;
echo "<title>Bidokunus| RSS</title>" . PHP_EOL;
echo "<link>" . $base_url . "index.php</link>" . PHP_EOL;
echo "<description>Cloud RSS</description>" . PHP_EOL;
echo "<language>en-us</language>" . PHP_EOL;
foreach ($result as $row) {
$publish_Date = date("D, d M Y H:i:s T", strtotime($row["datetime"]));
$image_size_array = get_headers($base_url . "cdn/recipes//" . $row["featured_image"], 1);
$image_size = $image_size_array["Content-Length"];
$image_mime_array = getimagesize($base_url . "cdn/recipes/" . $row["featured_image"]);
$image_mime = $image_mime_array["mime"];
echo "<item xmlns:dc='ns:1'>" . PHP_EOL;
echo "<title>" . $row["title"] . "</title>" . PHP_EOL;
echo "<link>" . $base_url . "recipe/" . $row["permalink"] . "/</link>" . PHP_EOL;
echo "<guid>" . md5($row["recipe_id"]) . "</guid>" . PHP_EOL;
echo "<pubDate>" . $row["created"] . "</pubDate>" . PHP_EOL;
echo "<dc:creator>BiDokunus</dc:creator>" . PHP_EOL;
echo "<description><![CDATA[" . substr($row["description"], 0, 300) . "]]></description>" . PHP_EOL;
echo "<enclosure url='cdn/recipes/" . $row["featured_image"] . "' length='" . $image_size . "' type='" . $image_mime . "' />" . PHP_EOL;
echo "<category>yemek</category>" . PHP_EOL;
echo "</item>" . PHP_EOL;
}
echo '</channel>' . PHP_EOL;
echo '</rss>' . PHP_EOL;
?>