<? 

// Replace the auto header
header('Content-type: text/xml'); 

// You gotta have this file to connect to the database
// and provide all the default RSS values
@include('init_rss.php');


// FUNCTION FOR GRABBING COUNTRIES
function convertCountry($which) {
	// Query the database for country list
	$country_query = "SELECT name FROM hero_countries WHERE id = '".$which."'";
	$country_result = mysql_query($country_query);
	$country_array = mysql_fetch_array($country_result);
	return $country_array[0];
}// end function: convertCountry()



echo '<?xml version="1.0" encoding="UTF-8"?>';

?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
	<itunes:explicit>no</itunes:explicit>
	<atom:link href="http://www.widespreadpanic.com/rss_feeds/podcasts.xml" rel="self" type="application/rss+xml" />
	<title>WIDESPREAD PANIC - PODCAST</title>
	<link>http://www.widespreadpanic.com/rss_feeds/podcasts.xml</link>
	<description>The official WIDESPREAD PANIC podcast.</description>
	<?
	
	// PRETEND THAT THE FEED IS PUBLISHED DAILY
	$pub_date = date("D, d M Y H:i:s T", (time() - (24 * 60 * 60)));
	echo '<pubDate>'.$pub_date.'</pubDate>';
	
	
	// DISCOVER THE LAST PUBLISH DATE...
	$the_q = "SELECT id,date_posted FROM hero_audio_tracks WHERE status = 2 ORDER BY date_posted DESC LIMIT 2";
	$the_r = mysql_query($the_q);
	$last_build_date = date("D, d M Y H:i:s T",  mysql_result($the_r,0,'date_posted')   );
	
	echo '<lastBuildDate>'.$last_build_date.'</lastBuildDate>';
	
	
	echo '<language>'.$rss_lang.'</language>';
	echo '<copyright>'.$rss_copyright.'</copyright>';
	echo '<managingEditor>'.$rss_managing_editor.'</managingEditor>';
	echo '<webMaster>'.$rss_webmaster.'</webMaster>';
	echo '<generator>'.$rss_generator.'</generator>';
	
	if (isset($rss_category)) {
		echo '<category>'.$rss_category.'</category>';
	}
	if (isset($rss_time_to_live)) {
		echo '<ttl>'.$rss_time_to_live.'</ttl>';
	}
	
	
	//*************************************
	// THE FOLLOWING IS iTunes specific
	?>
	<itunes:author>WIDESPREAD PANIC</itunes:author>
	<itunes:subtitle>The official WIDESPREAD PANIC podcast.</itunes:subtitle>
	<itunes:summary>The WIDESPREAD PANIC: WEEKLY MP3 podcast includes one mp3 chosen from the archive every week.</itunes:summary>
	<itunes:owner>
        <itunes:name>WIDESPREAD PANIC</itunes:name>
	    <itunes:email><? echo $rss_managing_editor; ?></itunes:email>
    </itunes:owner>
		<itunes:category text="Music"></itunes:category>
	<?
	//*************************************
	
	
	
	$the_q = "SELECT * FROM hero_audio_tracks WHERE status = 2 ORDER BY date_posted DESC LIMIT 50";
	$the_r = mysql_query($the_q);
	$the_total = @mysql_num_rows($the_r);
	
	// run loop
	for ($i=0; $i < $the_total; $i++) {
	
		// POPULATE VARIABLES
		$cur = mysql_fetch_array($the_r);
		
		
		// CHECK TO MAKE SURE THAT THE TOUR GROUP IS APPROVED
		$group_q = "SELECT id, name FROM hero_audio WHERE id = '".$cur['group_id']."' AND status = '2'";
		$group_r = mysql_query($group_q);
		
		if (@mysql_num_rows($group_r) > 0) {
			
			
			// id
			$cur_id = $cur['id'];
			
			// date
			$cur_date = date("D, d M Y H:i:s T",$cur["date_posted"]);
			
			// audio group name
			$cur_name = htmlentities(strip_tags(stripslashes(  mysql_result($group_r,0,'name')   )));
			
			
			
			
			// POPULATE TRACK VARIABLES *******************************************
				
				$track_name = htmlentities(stripslashes($cur["name"]));
				
				$track_desc = stripslashes($cur["description"]);
				
				$track_path = $cur["link"];
				
			// END TRACK VARIABLES ************************************************
			
			
			
			echo "<item>";
			
			echo '<title>'. $cur_name . ' - ' .$track_name;
			echo '</title>';
			
			echo '<link>'. htmlentities($track_path) .'</link>';
			
			echo '<guid isPermaLink="false">'. htmlentities($track_path) .'</guid>';
			
			echo '<description>';
			
			$desc_string = '';
			
			$desc_string .= $track_desc;

			echo htmlentities($desc_string);
			
			echo '</description>';
				 
			echo '<pubDate>'.$cur_date.'</pubDate>';
				 
			echo '<source url="http://www.widespreadpanic.com/rss_feeds/podcasts.xml">WIDESPREAD PANIC PODCAST</source>';
			
			// get file size
			$uri = @parse_url($track_path);
			$fs = @filesize($server_dir . $uri['path']);
			
			
			echo '<enclosure url="'.$track_path.'" length="'.$fs.'" type="audio/mpeg" />';
			
			echo "</item>";
			
		} // end if	
	}// end for
	
	?>
</channel>
</rss>