<? require "prep.php";
$mlink = dbconnect();
   header("Content-Type: text/xml");
   header("Expires: ".gmdate("D, d M Y H:i:s \G\M\T", time()+3600000));


// HTTP/1.0
header("Pragma: no-cache");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd" encoding="iso-8859-1">
  <channel>
  <title>Christian Tape Ministry</title>
    <link>http://<?=$DomainName?>/</link>
	<itunes:category><![CDATA[Religion & Spirituality]]></itunes:category>
	<itunes:explicit>no</itunes:explicit>
    <description>Messages about Christ, His purpose, His word, and His Church from a variety of speakers including Lance Lambert, Stephen Kaung, Ed Miller, Dana Congdon, Christian Chen, and others.</description>
    <language>en-us</language>
    <webMaster>cox.jack@gmail.com</webMaster>
    <managingEditor>comments2@christiantapeministry.com</managingEditor>
    <ttl>60</ttl>
<?


	$query = "select tape.id, tape.title, tape.contentType, speaker.speakerName , ".
        "venue.venueName, tape.deliverDate, UNIX_TIMESTAMP(tape.publishDate) as pub, tape.summary,tape.length  ".
        "from tape, venue, speaker ".
        "where tape.contentType='T' and tape.speakerId=speaker.id and tape.venueId=venue.id AND tape.hidden=0 ".
        "order by publishDate desc limit 100";

	$result = mysql_query($query, $mlink);

	while ($row = mysql_fetch_object($result))
    {
?><item><title><![CDATA[<?=rawurldecode($row->title)?> - <?=$row->speakerName?>]]></title>
<itunes:author><![CDATA[<?=$row->speakerName?>]]></itunes:author>
<itunes:duration><![CDATA[<?=$row->length?>:00]]></itunes:duration>
<link>http://<?=$DomainName?>/tape.php?id=<?=$row->id?></link>
<guid>http://<?=$DomainName?>/tape.php?id=<?=$row->id?></guid>
<description><![CDATA[<?=rawurldecode(strip_tags($row->summary))?>]]></description>
<itunes:summary><![CDATA[<?=substr(rawurldecode($row->summary),0,4000)?>]]></itunes:summary>
<pubDate><?=gmdate("D, d M Y H:i:s \G\M\T",$row->pub)?></pubDate>
<?
	$q2 = "select * from mediaFiles where tapeId=$row->id and mediaType=1 order by tapeId limit 1";
	$result2 = mysql_query($q2, $mlink);
	if (mysql_num_rows($result2) > 0) {
		$row2 = mysql_fetch_object($result2);
		$fname = "$audioDir/$row2->url";
		if (file_exists($fname)) {
		$filesize = filesize($fname);
	?>
		<enclosure url="http://s3.amazonaws.com/CTM/audio/tape<?=$row->id?>.mp3" 
			length="<?=$filesize?>" type="audio/mpeg"/>
	<?	} 
	} ?>
</item>
<?    } ?>
</channel>
</rss>


