<?php
header("Content-type: application/xml; charset=iso-8859-1");
echo "<?xml version='1.0' encoding='iso-8859-1' ?><rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:sy='http://purl.org/rss/1.0/modules/syndication/' xmlns:admin='http://webns.net/mvcb/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'><channel><title>Wandy Teeth</title><link>http://www.wandyteeth.com/</link><description>only the best literature in the woooorld</description><language>en-us</language><docs>http://www.wandyteeth.com/rss.xml</docs><sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>";
// Now write the header information
 //connection info
 include ("/home/virtual/wandyteeth.com/var/www/html/connect.php");





//for each of the selected blogs (2, 3, 4, 5, 8, 10, and 14) in mt_blog, find and display in descending order the most recent post in mt_entry.




$alldata = array();
 $alldates = array();




$blogcount=0; // keep track of number of blogs




$blogarray = "SELECT blog_id, blog_site_url, blog_name, blog_description FROM mt_blog WHERE (blog_id != 2) and (blog_id != 30) and (blog_id != 55)"; 
 $resultblog = mysql_query($blogarray) or die (mysql_error()); 
 while ($rowblog = mysql_fetch_array($resultblog)) {




$burl = ($rowblog['blog_site_url']);
 $bname = ($rowblog['blog_name']);
 $bdesc = ($rowblog['blog_description']);




$rowarray = "SELECT entry_created_on, entry_id, entry_blog_id FROM mt_entry WHERE (entry_blog_id = (".$rowblog['blog_id'].")) ORDER BY entry_created_on DESC"; 
 $resultid = mysql_query($rowarray) or die (mysql_error());




$count=0;   
 while ($rowid = mysql_fetch_array($resultid)) {
 if ($count>0) { break; }   //to ensure that if there are less than 1 posts the blog will not break the query




$maxarray = "SELECT entry_title, entry_id, entry_created_on, SUBSTRING_INDEX(entry_text, ' ', 75) AS exerpt FROM mt_entry WHERE entry_created_on = '".$rowid['entry_created_on']."' and entry_id = '".$rowid['entry_id']."'"; $resultmax = mysql_query($maxarray) or die (mysql_error());




while ($rowmax = mysql_fetch_array($resultmax)) {




$ids = array($rowmax['entry_id']);
 $date = ($rowmax['entry_created_on']);
 $title = ($rowmax['entry_title']);
 $text = ($rowmax['exerpt']);
 




//saves the data int alldata array for use outside of the while loop 
 $alldates[$blogcount++] = $date;
 $alldata[$blogcount++] = array('bname'=>$bname, 'burl'=>$burl, 'bdesc'=>$bdesc, 'ids'=>$ids, 'title'=>$title, 'text'=>$text); 
 }




$count++;
 }
 }
 array_multisort($alldates, SORT_DESC, $alldata);




for ($i=0; $i<7; $i++) {



 //separate date created on up between year, month, and date 
 $year[$i] = substr($alldates[$i], 0, 4); 
 $month[$i] = substr($alldates[$i], 5, 2); 
 $day[$i] = substr($alldates[$i], 8, 2);
$time[$i] = substr($alldates[$i], 11,8);

$lard = $alldates[$i];

$poopsmcgee = strip_tags($alldata[$i]['text']);
$xmltitle = strip_tags($alldata[$i]['title']);
$xmllink = ($alldata[$i]['burl']);
$xmlname = strip_tags($alldata[$i]['bname']);

$fatty = "$year[$i]-$month[$i]-$day[$i]T$time[$i]-00:00";
$doublepoops = date('r',strtotime($alldates[$i]));
echo "<item>";
echo "<title>$xmlname - $xmltitle</title>";
echo "<description>".htmlentities($poopsmcgee)."</description>";
echo "<link>$xmllink</link>";
echo "<guid>$xmllink</guid>";
echo "<pubDate>$doublepoops</pubDate>";
echo "</item>";
}
echo "</channel></rss>";
?>


