<?php
header("Content-type: text/xml"); 
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

$webbase = "deanbible.org/Media/Audio Files/";

function build_enclosures($startdir, $series_title)
{
  global $series;
  global $weeks;
  $basedir = "/hsphere/local/home/burtcbl/";
  
  if ($series == "All") { $weeksback = $weeks * 345600; }
  else {$weeksback = 302400000;}
  
  if ($dh = opendir($basedir . $startdir))
  {
    while (($file = readdir($dh)) !== false)
    {
	  if ( filetype($basedir . $startdir . $file) == "dir")
	  {
	     if (($file != ".") && ($file != ".."))
		 {
			 if (($series == "All") || ($file == $series)) { build_enclosures($startdir . $file . "/", $file); }
			 else {  continue 1; }
		 }
	  }
	  else	 
	  {
         if ( substr_count($file, ".mp3"))
		 {
         if ((filectime($basedir . $startdir . $file)) > (time() - $weeksback))
			{
			   		
               echo "<item>\n";
			   $descfile = substr_replace($file, ".pod", strpos($file, ".mp3"));
               if (file_exists($basedir . $startdir . $descfile))
			   {
			      echo "<description>" . $series_title . "-";
                  $f = fopen($basedir . $startdir . $descfile, r);
			      $buf = fgets($f, 150);
			      fclose($f);
			      echo trim(strip_tags($buf));
                  echo "</description>\n";
               }
			   else
			   {
			      echo "<description>Description not available at this time</description>";
			   }
               echo "<pubDate>";
			   echo strftime("%a, %d %b %Y %T", filectime($basedir . $startdir . $file));
			   echo " EST</pubDate>\n";
               echo "<enclosure url=\"";
			   echo "http://";

			   $patharray = explode("/", $startdir . $file);
               $size = count($patharray);
			   for ($i=0; $i < count($patharray);$i++)
			   {
				  echo rawurlencode($patharray[$i]);
                  if ($i < (count($patharray)-1)) echo "/";
			   }	
			   echo "\" length=\"";
			   echo filesize($basedir . $startdir . $file);
			   echo "\" type=\"audio/mpeg\"/>\n";
			   echo "<guid isPermaLink=\"false\">";
			   echo $file;
			   echo "</guid>";
 			   echo "</item>\n";
		    }
	    }
      }
    }
    closedir($dh);
  }
}
?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/" version="2.0">
<channel>
<?php
if(isset($_GET["series"])) echo "<title>Doctrinal Bible Studies from Dean Bible Ministries Inc. - " . rawurldecode($_GET["series"]). "</title>";
else echo "<title>Doctrinal Bible Studies from Dean Bible Ministries Inc.</title>"
?>
<link>http://deanbible.org</link>
<itunes:image href="http://deanbible.org/images/drdeanitunes.png" />
<itunes:explicit>no</itunes:explicit>
<itunes:owner>
  <itunes:name>Deanbible</itunes:name>
  <itunes:email>webmaster@deanbible.org</itunes:email>
</itunes:owner>
<itunes:category text="Religion &amp; Spirituality"></itunes:category>
<description>MP3 Bible studies by Dr. Robert L. Dean Jr., Pastor of West Houston Bible Church, Houston, Texas.

This Podcast always provides the last 2 weeks of Bible classes. For previous classes and many more series, visit http://deanbible.org

Dean Bible Ministries is a non-profit organization dedicated to sharing the teaching ministry of Dr. Robert L. Dean Jr. through the distribution of various media such as MP3 downloads, MP3 disks, DVDs and cassette tapes.

Our mission is fourfold:

To introduce true biblical teaching to those who are new to the scripture and who seek the truth

To provide supplemental Bible classes for the edification of fellow believers

To provide a mechanism for listeners in local areas to learn of each other and thus aid in starting a local assembly

To provide video teaching to those local assemblies that are not yet developed enough to support a pastor

Dean Bible Ministries in no way seeks to supplant the local church, the only authorized agency for spiritual growth, 
but rather hopes to assist in forming fully functional local bodies which are shepherded by a local pastor as God intends.

http://deanbible.org
</description>
<language>en-us</language>
<copyright>Copyright 1998-2005 Dr. Robert L. Dean Jr.</copyright>
<lastBuildDate>Fri, 9 Dec 2005 11:00:00 GMT</lastBuildDate>
<managingEditor>brice@deanbible.org (Brice Burtch)</managingEditor>
<webMaster>brice@deanbible.org (Brice Burtch)</webMaster>
<?php
if(!isset($_GET["weeks"])){$weeks = 2;}
else {$weeks = $_GET["weeks"];}
if(!isset($_GET["series"])){$series = "All";}
else {$series = rawurldecode($_GET["series"]);}
build_enclosures($webbase, "MP3 Bible Classes");
?> 
</channel>
</rss>

