<?php
   if ( strtolower($_SERVER['HTTP_HOST']) == 'fbc.peihomeschool.com' ) {
       $path= $_SERVER['REQUEST_URI'];
       header("Location: http://fbcsummerside.org{$path}");
   }

ob_start( 'ob_gzhandler' );
require('getid3-2.0.0b4/getid3/getid3.php');
$lbd='';
$audiofiles = getaudio('audio/');
print <<<HERE
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"  version="2.0">
<channel>
<title>Bible Preaching - Fundamental Baptist Church, Summerside PEI Canada</title>
<description>KJV Bible Audio Messages</description>
<link>http://fbcsummerside.org</link>
<language>en-us</language>
<copyright>No Copyright</copyright>
<lastBuildDate>$lbd</lastBuildDate>
<itunes:category text="Religion &amp; Spirituality">
    <itunes:category text="Christianity" />
</itunes:category>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<webMaster>fbchurch@fbcsummerside.org</webMaster>
<itunes:author>Pastor Ian C. Kurylyk</itunes:author>
<itunes:subtitle>Preaching from the pulpit of Fundamental Baptist Church, Summerside Prince Edward Island</itunes:subtitle>
<itunes:summary>Fundamental Baptist Church is located on a small Island on the east coast of Canada.  Our address is 200 MacEwen Road Summerside PEI Canada C1N 2P6</itunes:summary>
<itunes:owner>
<itunes:name>Pastor Ian C. Kurylyk</itunes:name>
<itunes:email>fbchurch@fbcsummerside.org</itunes:email>
</itunes:owner>
<itunes:explicit>clean</itunes:explicit>
<ttl>30</ttl>
<itunes:image href="http://www.fbcsummerside.org/podcast/IanKurylyk.jpg"/>
HERE;


foreach ($audiofiles as $key =>$value) {
  print substr($value,7);
}

print "</channel>\n";
print "</rss>\n";







function getaudio ($folder) {
global $series,$lbd;
$basepath = '/home/kendan/public_html/fbc/'.$folder;
$oldestyymmdd ='';
if ($handle = opendir($basepath)) {
    while (false !== ($file = readdir($handle))) {
            if ( $file== '..' || $file== '.'  ) continue;
            if ( !strpos($file, '.mp3',1) ) 	getaudio( $folder . $file . '/' );


            if ( strpos($file,'.mp3',1) ) {

                    // Initialize getID3 engine
                    $getid3 = new getID3;
                    // Tell getID3() to use UTF-8 encoding - must send proper header as well.
                   // $getid3->encoding = 'UTF-8';

          	  try {
	    $getid3->Analyze('/home/kendan/public_html/fbc/'.$folder.$file);
	    // Show audio bitrate and length
	     //$samplerate 	=  @$getid3->info['audio']['bitrate']; 
	    $playtime 	=  @$getid3->info['playtime_string'];
	    //$year 		=  @$getid3->info['year'];
	    $album 		=  @$getid3->info['tags']['id3v2']['album'][0];
	    $artist 		=  @$getid3->info['tags']['id3v2']['artist'][0];
	    $comment 	=  @$getid3->info['tags']['id3v2']['comment'][0];
	    $title 		=  @$getid3->info['tags']['id3v2']['title'][0];
	    //$genre		=  @$getid3->info['genre'];
	   }
	    catch (Exception $e) {    
	    echo 'An error occured: ' .  $e->message;
                    }

	  $filesize = filesize('/home/kendan/public_html/fbc/'.$folder.$file);
                    $fname7 = substr($file,0,7);
                    $yymmdd =  substr($fname7,0,2) . '-' . substr($fname7,2,2) . '-' . substr($fname7,4,2);
	  $dispubdate = date('D, d M Y', strtotime($yymmdd) );
	  $pubdate = $dispubdate .  ' 00:00:00 EST';
                    if ( strtotime($yymmdd) > strtotime($oldestyymmdd) ) {
	         $oldestyymmdd = $yymmdd;
	         $lbd = $pubdate;
	  }


	      switch (strtolower(substr($file,6,1))) {
	         case 'm':
	         $time='Sunday Morning Service';
	         break;
	         case 'n':
	         $time='Sunday Morning Service';
	         break;
	         case 's':
	         $time='Sunday School Service';
	         break;
	         case 'w':
	         $time='Wednesday Night Service';
	         break;
	         default :
	         $time='';
	         break;
                        }

     	    //$file = str_replace('{','&#123;',$file);
	    //$file = str_replace('}','&#125;',$file);
$series[] = $fname7 . <<<HERE

<item>
  <title>$title</title>
  <pubDate>$pubdate</pubDate>
  <link>http://fbcsummerside.org/m?file=$file&amp;folder=$folder</link>
  <guid isPermaLink="false">http://fbcsummerside.org/$folder{$file}</guid>
  <author>fbchurch@fbcsummerside.org (Fundamental Baptist Church Summerside)</author>
  <category>Religion &amp; Spirituality</category>
  <enclosure url="http://fbcsummerside.org/$folder{$file}" length="$filesize" type="audio/mpeg"/>
  <itunes:subtitle>$title</itunes:subtitle>
  <itunes:summary>$comment</itunes:summary>
  <itunes:author>$artist</itunes:author>
  <itunes:duration>$playtime </itunes:duration>
  <itunes:keywords>religion, pastor, priest, bible, kjv, sound doctrine, salvation</itunes:keywords>
  <itunes:explicit>no</itunes:explicit>
  <description>A new MP3 sermon  from &lt;a href=&quot;http://fbcsummerside.org&quot;&gt;Fundamental Baptist Church - Summerside&lt;/a&gt; is now available:&lt;BR&gt;&lt;BR&gt;&lt;b&gt;Series:&lt;/b&gt; $album &lt;BR&gt;&lt;b&gt;Title:&lt;/b&gt; $title &lt;BR&gt;&lt;b&gt;Speaker:&lt;/b&gt; $artist &lt;BR&gt;&lt;b&gt;Service:&lt;/b&gt; $time&lt;BR&gt;&lt;b&gt;Date:&lt;/b&gt; $dispubdate &lt;BR&gt;&lt;b&gt;Bible:&lt;/b&gt; KJV&lt;BR&gt;&lt;b&gt;Length:&lt;/b&gt; $playtime minutes &lt;BR&gt; &lt;BR&gt;</description>
</item>

HERE;




 	 } //end if
    } //end while
    closedir($handle);
} //end if ($handle
asort($series);

return $series;
}






?>
