<?php
include ("adm/dbcall.php"); // the usual

function showrssdatetime($raw) {

	$r = strtotime($raw);
	
	$newdt = date("D, d M Y H:i:s T",$r);
	
	return $newdt;

}

//getLastBuildDate



$bq = "SELECT content.createdate,content.editdate FROM content WHERE type < '3' AND status='1' ORDER BY content.createdate DESC LIMIT 0,1"; 
$br = mysql_query($bq) or die(mysql_error());



while ($bdrow = mysql_fetch_array($br)){ 
	$createdate = $bdrow["createdate"];
	$editdate = $bdrow["editdate"];
	
} // end while

if ($editdate > $createdate)
	$lastbuilddate = showrssdatetime($editdate);
else
	$lastbuilddate = showrssdatetime($createdate);


//we're just rssing blog entries



echo "<?xml version=\"1.0\"?>\n";
echo "<rss version=\"2.0\">\n";
echo "   <channel>\n";
echo "      <title>Synklynk.com</title>\n";
echo "      <link>http://www.synklynk.com/index.php</link>\n";
echo "      <description>Music for your people</description>\n";
echo "      <language>en-us</language>\n";
echo "      <pubDate>$pubdate</pubDate>\n";
//echo "      <pubDate>Fri, 14 Jul 2006 23:00:22 PDT</pubDate>\n";
echo "      <lastBuildDate>$lastbuilddate</lastBuildDate>\n";
echo "      <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
//echo "      <generator>Weblog Editor 2.0</generator>\n";
//echo "      <managingEditor>editor@example.com</managingEditor>\n";
//echo "      <webMaster>webmaster@example.com</webMaster>\n";

//now the items themselves

//set startdate within three months

$thisday = date("d");
$thismonth = date("m");
$thisyear = date("Y");

$threemonthsago = date("Y-m-d", mktime(0,0,0,$thismonth - 6,$thisday,$thisyear));

//createdate >= '$threemonthsago' AND

$q = "SELECT content.id,content.title,content.copy,content.createdate,content.editdate FROM content WHERE type < '3' AND status='1' ORDER BY content.createdate DESC";

//echo $q."\n\n";


$r = mysql_query($q) or die(mysql_error());



while ($row = mysql_fetch_array($r)){ 


	$link = "http://www.synklynk.com/index.php/".$row["id"];
	$title = stripslashes($row["title"]);
	$subtitle = stripslashes($row["subtitle"]);
	$copy = stripslashes($row["copy"]);
	$createdate = stripslashes($row["createdate"]);
	$editdate = stripslashes($row["editdate"]);

	/*
	//grab just the first sentence
	$sent = strpos($copy,". ");
	$sent = $sent + 2;
	$firstsentence = substr($copy, 0, $sent);
	*/

	if ($editdate > $createdate)
		$pubdate = showrssdatetime($editdate);
	else
		$pubdate = showrssdatetime($createdate);

	echo "      <item>\n";
	echo "         <title>$title</title>\n";
	echo "         <link>$link</link>\n";
	echo "         <description>$copy</description>\n";
	echo "         <pubDate>$pubdate</pubDate>\n";
	echo "         <guid>$link</guid>\n";
	echo "      </item>\n";
	
		
} // end while



//close out the channel

echo "   </channel>\n";
echo "</rss>";

?>
