<?php

////////////
//SETTINGS//
////////////

//Set the maximum number of updates to list
$updatelistmax = 10;

//Set the filename with list of features
$featurelistfile = "featurelist.php";



/////////////////////////////////////////////
//!!!SHOULD NOT NEED TO EDIT BEYOND HERE!!!// (ONCE FINISHED MAKING THIS WORK, ANYWAY.)
/////////////////////////////////////////////



$now = date("D, d M Y H:i:s T");


$output = "<?xml version=\"1.0\"?>
            <rss version=\"2.0\">
			<channel>
			  <title>Otter Comics</title>
			  <link>http://www.taur.net/~ottercomics</link>
			  <category>Comic Syndicate</category>
			  <language>en-us</language>
			  <description>An Independent Webcomic Community</description>
			  <pubDate>$now</pubDate>
              <lastBuildDate>$now</lastBuildDate>
			  <image>
				<url>http://www.taur.net/~ottercomics/_front/oclogo75.png</url>
				<title>Otter Comics</title>
				<link>http://www.taur.net/~ottercomics</link>
			  </image>
                    <managingEditor>orenotter2@yahoo.com</managingEditor>
                    <webMaster>xyie_fourseasons@yahoo.com</webMaster>
            ";

require ($featurelistfile);  //get the list of features and information thereon




//Build the array listing the update dates
	foreach ($featurelist as $key => $feacheck){
		include($feacheck['folder'] . "/" . $feacheck['updatefile'] );
		//$featurelist[$key]['updateyear'] = substr($last_update,-2);
		//$featurelist[$key]['updatemonth'] = substr($last_update,0,2);
		//$featurelist[$key]['updateday'] = substr($last_update,3,2);
		$updatelister['updateyear'][$key] = (int)substr($last_update,-2);
		$updatelister['updatemonth'][$key] = (int)substr($last_update,0,2);
		$updatelister['updateday'][$key] = (int)substr($last_update,3,2);
	}//end foreach
//}

//Sort the update date list array
array_multisort($updatelister['updateyear'],SORT_NUMERIC,SORT_DESC,	//sort by year, such that the highest number year is first (note: 2 digit year)
		$updatelister['updatemonth'],SORT_NUMERIC,SORT_DESC,	//sort by month, such that the highest number month is first in its year
		$updatelister['updateday'],SORT_NUMERIC,SORT_DESC);	//sort by day, such that the highest number day is first in its month

//build an array that is just the feature ID, ordered as per the update date list
foreach ($updatelister['updateday'] as $key => $sortedupdates){
	$updateorder[] = $key;
}//end foreach$featurelist[$featureID]['name'] . ": " .


/*
$updatelistcatch = 0; //this is used to break out of the foreach loop....sorta.
	foreach ($updateorder as $key => $featureID){
		if($updatelistcatch<$updatelistmax){ //only list the maximum number of items
			// Item to repeat in here
			$headline =$featurelist[$featureID]['name']; 
			$description="Description missing! Please check updates file.";
			include($featurelist[$featureID]['folder'] . "/" . $featurelist[$featureID]['updatefile']); 
// nowdate variable is giving me problems trying to access it...

			//make some sort of check to only display if $headline and $description exist in the file!updatelistmax
			$output .= "<item><title>" . htmlentities($headline) . "</title>
					    <link>" . htmlentities("http://ottercomics.taur.net/" . $featurelist[$featureID]['folder'] . "/archive/?" . $var . "=" .  $[$featureID]_now_date  ) . "</link>

			<description>" . htmlentities( $featurelist[$featureID]['name'] . ": " . strip_tags($description)) . "</description>
					</item>";


		}//end if
		$updatelistcatch++;
	}//end foreach

*/


for($n=0;$n<$updatelistmax;$n++){
	$featureID = $updateorder[$n];
			// Item to repeat in here
			$headline =""; 
			$description="";
			$pubDate ="";
			include($featurelist[$featureID]['folder'] . "/" . $featurelist[$featureID]['updatefile']); 
			$full_headline = $featurelist[$featureID]['name'];
			if(!empty($headline)){
				$full_headline .= ": " . $headline;
			}//endif
			if(empty($description)){
				$description= "#" . ${$featureID.'_now_date'} ;
			}
			//make some sort of check to only display if $headline and $description exist in the file!
			$output .= "<item><title>" . htmlentities($full_headline) . "</title>
					    <link>" . htmlentities("http://ottercomics.taur.net/" . $featurelist[$featureID]['folder'] . "/" . $featurelist[$featureID]['archive'] . "?" . $var . "=" . ${$featureID.'_now_date'} ) . "</link>";
			//displays a publication date if one exists
			if(!empty($pubDate)){
			$output .= "<pubDate>" . $pubDate . "</pubDate>";
			}

			$output .= "<description>" . htmlentities( strip_tags($description)) . "</description>
					</item>";
			
}//end for

/*
//foreach feature....add it to the rss feed (modify this so as to arrange, then trim!)
	foreach ($featurelist as $key => $feacheck){
	
	include($feacheck['folder'] . "/" . $feacheck['updatefile']);

$output .= "<item><title>".htmlentities($headline)."</title>
                    <link>".htmlentities("http://www.taur.net/~ottercomics/" . $feacheck['folder'] . "/archive/?" . $var . $[$key]_now_date)."</link>
                    
<description>".htmlentities(strip_tags($description))."</description>
                </item>";
	
	}
*/	






    /*        
//require("archives/updates.php");

$output .= "<item><title>".htmlentities($headline)."</title>
                    <link>".htmlentities("http://www.taur.net/~ottercomics/rfom/archives/phparchive.php?strip=" . $rfom_now_date)."</link>
                    
<description>".htmlentities(strip_tags($description))."</description>
                </item>";
*/

				
				
				
$output .= "</channel></rss>";
header("Content-Type: application/rss+xml");
echo $output;
?>
