<?php
	header("Content-Type: application/xml; charset=ISO-8859-1");
	putenv("TZ=PST8DST");
	$xml = "";
	$xml .= "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\r\n";
	$xml .= "<rss version=\"2.0\">\r\n";
	$xml .= "\t<channel>\r\n";
	$xml .= "\t\t<title>Terroir...Dirty Talk on Wine with Dirk Hampson</title>\r\n";
	$xml .= "\t\t<link>http://www.farniente.com/</link>\r\n";
	$xml .= "\t\t<description>Official blog of the Far Niente Dolce and Nickel &amp; Nickel wineries. Hosted by Director of Winemaking Dirk Hampson</description>\r\n";
	$xml .= "\t\t<lastBuildDate>" . date("D, d M Y H:i:s") . " -0700</lastBuildDate>\r\n";
	$xml .= "\t\t<language>en-us</language>\r\n";
	open_database("napi.net-flow.com", "farniente", "start123", "farniente");
	select_records("Blog_RSS_Clicks", "Preferences", "ID='1'");
	get_record();
	$clicks = get_field("Blog_RSS_Clicks") + 1;
	update_field("Preferences", "Blog_RSS_Clicks", "$clicks", "ID='1'");
	select_records("*", "Blog", "", "Date_Added DESC");
	$blogs = get_field_array("ID");
	for($x=0; $x<count($blogs); $x++) {
		select_records("*", "Blog", "ID='".$blogs[$x]."'");
		$blog = get_record();
		$xml .= "\t\t<item>\r\n";
		$blog["Title"] = eregi_replace("\x85", "...", $blog["Title"]);
		$blog["Title"] = eregi_replace("&",    "&amp;", $blog["Title"]);
		$blog["Title"] = eregi_replace("\x91", "&#039;", $blog["Title"]);
		$blog["Title"] = eregi_replace("\x92", "&#039;", $blog["Title"]);
		$blog["Title"] = eregi_replace("\x93", "&quot;", $blog["Title"]);
		$blog["Title"] = eregi_replace("\x94", "&quot;", $blog["Title"]);
		$blog["Title"] = eregi_replace("\x96", "-", $blog["Title"]);
		$blog["Title"] = eregi_replace(" +", " ", $blog["Title"]);
		$xml .= "\t\t\t<title>" . $blog["Title"] . "</title>\r\n";
		$xml .= "\t\t\t<link>http://farniente.com/weblog_detail.html?ID=" . $blog["ID"] . "</link>\r\n";
		$xml .= "\t\t\t<guid>http://farniente.com/weblog_detail.html?ID=" . $blog["ID"] . "</guid>\r\n";
		$xml .= "\t\t\t<pubDate>" . date("D, d M Y H:i:s", strtotime($blog["Date_Added"])) . " -0700</pubDate>\r\n";
		$blog["Story"] = htmlspecialchars(get_words(strip_tags($blog["Story"]), 75), ENT_QUOTES);
		$blog["Story"] = eregi_replace("\x85", "...", $blog["Story"]);
		$blog["Story"] = eregi_replace("&",    "&amp;", $blog["Story"]);
		$blog["Story"] = eregi_replace("\x91", "&#039;", $blog["Story"]);
		$blog["Story"] = eregi_replace("\x92", "&#039;", $blog["Story"]);
		$blog["Story"] = eregi_replace("\x93", "&quot;", $blog["Story"]);
		$blog["Story"] = eregi_replace("\x94", "&quot;", $blog["Story"]);
		$blog["Story"] = eregi_replace("\x96", "-", $blog["Story"]);
		$blog["Story"] = eregi_replace("\n", " ", $blog["Story"]);
		$blog["Story"] = eregi_replace("\r", " ", $blog["Story"]);
		$blog["Story"] = eregi_replace(" +", " ", $blog["Story"]);
		$xml .= "\t\t\t<description>" . $blog["Story"] . "</description>\r\n";
		$xml .= "\t\t</item>\r\n";
	}
	close_database();
	$xml .= "\t</channel>\r\n";
	$xml .= "</rss>\r\n";
	
	print $xml;
?>
